Thursday, July 26, 2018

My first steps with Ajapaik

To get into the ajapaik project, I tried to run a development server locally on my machine. Here are my steps.

  • Clone the project.

  • create and activate a virtualenv

  • pip install -r requirements.txt

    NB I changed “Django==1.8.18” to simply Django

  • Here is a first problem:

    $ cd project
    $ python help
    ValueError: Unable to configure handler 'time_rotating_handler':
    [Errno 2] No such file or directory:

    Okay, the default settings has a hard-coded filename for the log file. You may not run it directly from within the repository. So I did my own file:

    import sys
    sys.path.insert(0, "/home/luc/repositories/ajapaik-web/project")
    from ajapaik.settings.default import *
    fn = "ajapaik.log"
    LOGGING['handlers']['time_rotating_handler']['filename'] = fn
  • Next problem:

    django.core.exceptions.ImproperlyConfigured: GEOS is required and has not been detected. Are you sure it is installed? See also

    I read the 1.11 version and consultd with Kimmo. Solution:

    $ sudo apt install postgis
  • Next problem:

    Traceback (most recent call last):
      File "", line 8, in <module>
      File "/site-packages/django/core/management/", line 354, in execute_from_command_line
      File "/site-packages/django/core/management/", line 328, in execute
      File "/site-packages/django/", line 18, in setup
      File "/site-packages/django/apps/", line 108, in populate
      File "/site-packages/django/apps/", line 198, in import_models
        self.models_module = import_module(models_module_name)
      File "/usr/lib/python2.7/importlib/", line 37, in import_module
      File "/ajapaik-web/project/ajapaik/", line 46, in <module>
        from project.ajapaik.settings import GOOGLE_API_KEY, DEBUG, STATIC_ROOT, MEDIA_ROOT
    ImportError: cannot import name GOOGLE_API_KEY

To be continued.

Kimmo discovered that most GET requests by anonymous users cause creation of a new users.User row with a random username. The guilty code was in project/ajapaik/ where AuthBackend.authenticate() method created a new user for each authentication attempt without password:

random_username = u'_%s_%s' % (username[:25], User.objects.make_random_password(length=3))
user = User.objects.create_user(username=random_username)
Action.log('user_middleware.create', related_object=user)
return user

I don’t know why this behaviour is there, but it clearly wrong since the Django documentation says that the authenticate() of a backend “returns a User object if the password is valid for the given username. If the password is invalid, authenticate() returns None.”

Vadim obviously also saw this problem and removed this backend in the current develop branch.