Vinyll's blog

( Python, Javascript & Web stuff… )

AMO and Zamboni gotchas

Servers

Dev test: https://addons-dev.allizom.org. It's a copy of the prod to play around.

Change a user's password

A user is a django.contrib.auth.models.User instance. It actually has a password field and a set_password() method. Don't use them.

Instead call the user_instance.get_profile().set_pasword() method then save it. It is actually an instance of users.models.UserProfile that redefines set_password() and other methods.

Gain access as admin

Run some sql command to gain admin access:

./manage.py dbshell
select id from users where email = 'MY_EMAIL_ADDRESS' into @id;
update auth_user set is_superuser = 1, is_staff = 1 where id = @id; insert into groups_users (group_id, user_id) values (1, @id);

(Thanks cvan!)

You can then access the django admin at http://localhost:8000/admin/models/ or an addons admin at http://localhost:8000/admin

Testing

Running tests

Make sure to carefully read the doc at http://zamboni.readthedocs.org/en/latest/topics/hacking/testing.html.

I had test failing and lots of logs. The magical sentence for me was FORCE_DB=1 python manage.py test --logging-clear-handlers --noinput

Avoid using FORCE_DB=1 whenever you can though as it is time consuming.

Skipped tests

Search tests - among others - are based on ElasticSearch which is disabled by default. If you need to run search tests, you should install ES, run it and update your settings_local adding RUN_ES_TESTS = True

Writing tests

assertTrue, assertEqual and some other TestCase methods are not used. eq_() and assert are preferred (don't ask me why).

Dealing with translations

.po and .mo files are auto-generated using Wil's Tower project. That means you are not supposed to edit them at all.

Quick code tips

hidden features

launch ./manage.py. Read all the available commands.

bugzil.la/123456 is a shortcut for https://bugzilla.mozilla.org/show_bug.cgi?id=123456

Best practices (or how to be picky)

Python

HTML

JavaScript

Other projects

FlightDeck gotchas

EDIT: Don't edit this project at all.

I resolved this error: ImportError: Could not import settings 'src.settings_local' (Is it on sys.path?): No module named settings_local

By commenting #import log_settings in the end of manage.py file.

Weirdly the server can now start and if I edit the file again and uncomment it, the server reloads just fine.

Marketplace

The project is called Fireplace and the sources are in an individual project.

You may consider this page to run the Marketplace with Zamboni. Note that both fireplace and AMO should be running when you call the Nginx url or you'll get an Nginx 502 bad gateway error.

Note that Zamboni should run with --settings=settings_local_mkt to run the marketplace through nginx!

Troublesootings

TypeError: _cache_key() takes exactly 2 arguments (3 given)

Some package may have changed and generate a cache key error. Just run pip install -r requirements/local.txt.

Extra resources

Extra TODOs

Register at https://mozillians.org

By vinyll on Sept. 26, 2013


Comments