Subscribe: Anyway
http://www.laurenwood.org/anyway/feed/atom/
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
book  database  django  error  mathjax  page  party  pythonanywhere  settings  site  system  votes  voting  wagtail  wordpress 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Anyway

Anyway



meandering thoughts from Lauren Wood



Updated: 2017-07-04T02:38:54Z

 



The Wild Robot (book review)

2017-07-04T02:38:54Z

My now 11-year-old daughter loves books and reading so I asked her to write a book review for a couple of her favourites. This one is for The Wild Robot, by Peter Brown. She gave this book ★★★★★ out of 5. “The Wild Robot” is a book about a single robot surviving in the wild [...]

My now 11-year-old daughter loves books and reading so I asked her to write a book review for a couple of her favourites. This one is for The Wild Robot, by Peter Brown. She gave this book (image) (image) (image) (image) (image) out of 5.

“The Wild Robot” is a book about a single robot surviving in the wild with lots of animals. She adopted her own baby animal, learned to speak the animals’ languages, and so much more! I like this book because the author describes everything in a new way. It’s one of those happy but sad books, and I had tears in my eyes at the end. Highly recommended!




Voting systems

2017-07-03T17:42:05Z

In Canada, where I live, the voting system for the parliaments is the easy to understand, but blunt, first past the post (FPTP) system (also called plurality voting). The person who wins the most votes (a plurality) wins the seat, whether they get over 50% or under 30%. I believe that it’s time we had [...]

In Canada, where I live, the voting system for the parliaments is the easy to understand, but blunt, first past the post (FPTP) system (also called plurality voting). The person who wins the most votes (a plurality) wins the seat, whether they get over 50% or under 30%. I believe that it’s time we had a system that gives more people a more nuanced say in the government they get; tactical voting of various forms in a FPTP system only goes so far. For my own benefit I’ve written up the voting systems of 3 other countries in which I’ve lived. I don’t have a firm opinion on which one I prefer (yet).

Germany

At the Federal level in Germany, the voting system is a version of a mixed-member proportional system: voters get two votes. One is for a direct candidate (approximately half the seats), and works by the plurality (FPTP) system. The other is where the voter votes for a party. Each party has a list, and the appropriate number from each party list is deemed elected, depending on the number of votes the party got. There is a threshold for the list votes; parties have to get over 5% of the vote to get any seats via the second (list) vote, unless more than three direct candidates from that party are elected.

This system was set up to balance many aims. Among them are the principle of equal votes (each vote must have equal weight), discourage small parties while allowing them, and encourage balance between various political views. It tends to lead to coalition governments, and is good for finding consensus.

Australia

Australia uses preferential, or ranked, voting systems. The voter ranks the candidates in order of preference. If one candidate gets 50% + 1 (or more) first preference votes, they are elected. If not, the candidate who received the fewest first preference votes is eliminated from the list, and their second preferences are distributed. This process continues until one candidate does have 50% + 1 or more votes. There’s a variation for the Senate that I’m not going into.

Ranked voting gives people a chance to vote for a candidate they know won’t win, and give the second preference to a mainstream candidate, which makes it better than FPTP tactical voting. One downside is that you have to rank all candidates in order, and it is quite possible to miss a number, or make some other mistake. There are some people who number from 1 down the page, so the ballot has to be designed to take that ‘donkey vote’ into account.

New Zealand

New Zealand uses a different version of mixed-member proportional representation to Germany. (No, I’m not going into detail on the precise differences.) Each voter has two votes: one for a direct candidate, and one for a party. The party vote determines the overall number of seats each party is entitled to. There is a threshold, as for Germany, of 5% for the party vote, or one direct candidate elected.

There are also a certain number of seats reserved for the Māori electorate; those use the same voting system.

Personally, I think any of these systems would be better than the current FPTP system we have.




Switching the Mathjax CDN

2017-04-08T18:58:53Z

If you have MathML on your WordPress site, using the Mathjax system to show it, then you need to know that Mathjax is shutting down the CDN as of April 30, 2017. If, like me, you use the MathJax-LaTeX plugin, the solution is easy. Go to the Plugins – Settings – MathJax-LaTeX page. Uncheck the [...]

If you have MathML on your WordPress site, using the Mathjax system to show it, then you need to know that Mathjax is shutting down the CDN as of April 30, 2017. If, like me, you use the MathJax-LaTeX plugin, the solution is easy.

Go to the Plugins – Settings – MathJax-LaTeX page. Uncheck the “Use MathJax CDN Service?” checkbox, and add https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax to the “Custom MathJax location?” text field. You can, of course, also download the MathJax scripts and install locally, but I prefer to use a CDN.

Save the changes, and you’re all set! Unfortunately there isn’t an equivalent of the MathJax ‘latest’ for the scripts, so every now and then you’ll need to update the location, but other than that there should be no differences.




Adding the ‘s’

2017-03-26T18:12:57Z

Let’s Encrypt has made it much easier for web sites to use https instead of http, even those on shared hosting. In my case, all I needed to do was ask my ISP, Canadian Web Hosting, to move my accounts to a server that supports a cPanel extension (I assume this one). Installing the certs [...]

Let’s Encrypt has made it much easier for web sites to use https instead of http, even those on shared hosting. In my case, all I needed to do was ask my ISP, Canadian Web Hosting, to move my accounts to a server that supports a cPanel extension (I assume this one). Installing the certs is trivial.

Changing the basic WordPress setting was easy – update the WordPress Address (URL) and Site Address (URL) settings in General. This did break a lot of image links, mostly because I’ve had my blog on WordPress for so long that I still had all my images in a custom image directory and the gallery couldn’t find them any more. That took a certain amount of fiddling, and I haven’t yet got all the images in the old posts back to the way they were.

Another thing that broke was my spam detection. I used Spam Karma for many years, and even after it was no longer updated it was suitable for my needs. But it doesn’t work with https for some reason. I’ve now switched to Antispam Bee and find it does what I need. I haven’t noticed any spam slipping through, nor real comments being marked as spam. Most of the competitors had some feature I didn’t like, such as by default deleting comments without my having a chance to check them. That would be useful on sites with lots of spam, but not necessary for mine. It has a well-deserved high rating on the WordPress plugin site.

Overall, switching my sites to https cost me a couple of hours work and the time waiting for the new server DNS to propagate. Well worth it.




Submitting news on XML.com

2017-02-01T18:31:27Z

I coded XML.com in Wagtail, a CMS based on Django. It works well for my needs and I like Python as a programming language. One of the big reasons I like Wagtail is that it includes a powerful enough but not overly complicated workflow with roles and a built-in moderation and preview system. But, I [...]

I coded XML.com in Wagtail, a CMS based on Django. It works well for my needs and I like Python as a programming language. One of the big reasons I like Wagtail is that it includes a powerful enough but not overly complicated workflow with roles and a built-in moderation and preview system.

But, I wanted a system where people could submit news items that would go into the moderation queue without needing to sign up for a login first. Fortunately, Wagtail makes that possible, and there’s a nice article by Erin Mullaney at Wagtail: 2 Steps for Adding Pages Outside of the CMS that details all the steps you need. It all worked nicely in more recent versions of Wagtail (thanks, Erin!) except for one part, the notification that the news item is in the moderation queue. That wasn’t a stop-ship item, so XML.com launched without those emails working.

I’ve now found the source of the problem. It turns out that when you submit a news item in this way, it doesn’t have a login identity attached to it (obviously, since there isn’t one). The send_notification function that sends the email uses templates, and these templates use the login identity of the author in the body of the email. Since that doesn’t exist, the whole function fails.

That means the solution is easy. The affected templates are wagtailadmin/notifications/submitted.txt and wagtailadmin/notifications/submitted.html, and Wagtail lets you customize the admin templates. I put my customized admin templates into a utils application, which contains all my utilities for the site. My utils/templates/wagtailadmin/notifications/submitted.txt file now has the content

{% extends 'wagtailadmin/notifications/submitted.txt' %}
{% load i18n %}

{% block content %}
{% blocktrans with page=revision.page|safe %}The page "{{ page }}" has been submitted for moderation.{% endblocktrans %}

{% trans "You can preview the page here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:preview_for_moderation' revision.id %}
{% trans "You can edit the page here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:edit' revision.page.id %}
{% endblock %}

Similar changes are necessary for the wagtailadmin/notifications/submitted.html file if you want to send HTML emails instead.




Django migrate tips

2016-05-10T16:22:26Z

If you read the documentation closely enough, of course all the information is there. Getting the order of operations right, however, can cause the odd issue. Developing Django apps means applying migrations, and those don’t always do what’s expected. In that case, you can roll back to the n-1 migration by using ./manage.py migrate [app_label] [...]

If you read the documentation closely enough, of course all the information is there. Getting the order of operations right, however, can cause the odd issue.

Developing Django apps means applying migrations, and those don’t always do what’s expected. In that case, you can roll back to the n-1 migration by using ./manage.py migrate [app_label] {n-1_migration_label}, then delete the nth migration, then edit the models.py to try again.

To clean up the database from some third-party app you decide you don’t want after all, you use ./manage.py migrate [app_label] zero to get rid of the migrations from that app. You have to run this before deleting the app from your settings.py file.




WordPress error

2016-04-25T21:40:11Z

One of my client websites suddenly started giving an error: Error establishing a database connection. When I went to the /wp-admin URL, the error was still there. This particular website is on shared hosting, so I logged into the CPanel and checked the database was still there. Then I checked the database and found some [...]

One of my client websites suddenly started giving an error: Error establishing a database connection. When I went to the /wp-admin URL, the error was still there.

This particular website is on shared hosting, so I logged into the CPanel and checked the database was still there. Then I checked the database and found some issues with some of the tables.

[site.wp_links] error: Table upgrade required. Please do "REPAIR TABLE `wp_links`" or dump/reload to fix it!
[site.wp_options] error: Table upgrade required. Please do "REPAIR TABLE `wp_options`" or dump/reload to fix it!
[site.wp_postmeta] status: OK
[site.wp_posts] status: OK
[site.wp_term_relationships] status: OK
[site.wp_term_taxonomy] error: Table upgrade required. Please do "REPAIR TABLE `wp_term_taxonomy`" or dump/reload to fix it!
[site.wp_terms] status: OK
[site.wp_usermeta] error: Table upgrade required. Please do "REPAIR TABLE `wp_usermeta`" or dump/reload to fix it!
[site.wp_users] error: Table upgrade required. Please do "REPAIR TABLE `wp_users`" or dump/reload to fix it!

Running those SQL queries on the appropriate database in phpMyAdmin fixed the problem. I don’t know whether the hosting company upgraded the database, or something happened with the automatic WordPress upgrade system, or if something else caused the problem.

[Update] There were a bunch of other errors that cropped up afterwards with the White Screen of Death; I had to call the hosting company to sort out the server-side errors causing those. It’s possible those errors were the original cause of the database problems, whatever they were.




ImportError

2016-04-22T23:04:33Z

I discovered another issue while deploying to PythonAnywhere (maybe it’s applicable to other PAAS providers as well). There was an odd ImportError when running manage.py. In the specific case I had, it showed up when running the tests with coverage: from Unipath import Path ImportError: No module named ‘Unipath’. It turned out I hadn’t installed [...]

I discovered another issue while deploying to PythonAnywhere (maybe it’s applicable to other PAAS providers as well).

There was an odd ImportError when running manage.py. In the specific case I had, it showed up when running the tests with coverage: from Unipath import Path ImportError: No module named ‘Unipath’. It turned out I hadn’t installed coverage in the virtual environment, which meant the system was using the default one. Installing coverage in the virtual environment as well fixed the problem.




Setting up on PythonAnywhere

2016-04-21T22:09:06Z

A checklist for moving a Django-Wagtail project to PythonAnywhere. There is documentation on the PythonAnywhere site; mine includes things I forget. Setup: development and testing on my laptop, staging and production on PythonAnywhere. The help files are pretty good, but I need my own checklist. Right now I’m in the staging mode, but at some [...]

A checklist for moving a Django-Wagtail project to PythonAnywhere. There is documentation on the PythonAnywhere site; mine includes things I forget.

Setup: development and testing on my laptop, staging and production on PythonAnywhere.

The help files are pretty good, but I need my own checklist. Right now I’m in the staging mode, but at some stage I’ll be moving to production. No point figuring out the same things twice!

  1. Develop on laptop in a virtualenv. Push commits regularly to bitbucket account. At some stage squash the migrations and clean those up. Four sets of settings: dev, testing, staging, production.
  2. Set up account on PythonAnywhere that allows the use of Postgres (it’s an add-on to a custom plan).
  3. Create virtualenv and set up staging web app. Delete virtualenv when you realise you didn’t use the right version of Python and the default is 2.7, not 3.5. Recreate the virtualenv with python 3.5.
  4. Clone the repository (using the ssh-keygen instructions). Redirect the public key to a file so you can copy it without line-breaks getting in the way.
  5. pip install -r requirements/production.txt (including psycopg2, which I didn’t need for development).
  6. Create the Postgres server, user, and database Don’t forget a strong password for the user (owner of the project database).
  7. Update the settings file with the database settings.
  8. Set the environment variables for the settings and the secret key (generator).
  9. Attempt to apply the migrations. This will show where you made mistakes on all the preceding steps.
  10. Fix the mistakes. Reload the web app to see if anything shows up.
  11. Set up the static file server. Check the static files are being served correctly.
  12. Create the Django superuser and log in.

The next step is data, of course.




Sun-dried tomato and olive tapenade

2016-01-02T20:46:12Z

Over the Christmas break I made a couple of dips, one of which got better reviews than the others. This is not a recipe for purists, since a real tapenade should have anchovies in it, but I didn’t have any and my family doesn’t like them anyway. None of the quantities are exact. The sun-dried [...]

Over the Christmas break I made a couple of dips, one of which got better reviews than the others. This is not a recipe for purists, since a real tapenade should have anchovies in it, but I didn’t have any and my family doesn’t like them anyway.

None of the quantities are exact. The sun-dried tomatoes were loosely packed in the measuring cup and I didn’t measure the olives, just drained the can and tossed them in the food processor. I didn’t chop anything before putting it in the food processor.

  • Approx 2 cups black olives (contents of one can, 398ml size). I used Californian black olives since those were in the cupboard, next time I’ll probably use Kalamata olives.
  • Approx 3/4 cup oil-packed sun-dried tomatoes; let most of the oil drip off but not all of it.
  • 5 cloves of garlic.
  • 2 tbsp capers

Process in a food processor until finely chopped. If it’s too dry, add a few drops of olive oil (or oil from the sun-dried tomatoes).