Mercurial > public > sg101
annotate accounts/__init__.py @ 943:cf9918328c64
Haystack tweaks for Django 1.7.7.
I had to upgrade to Haystack 2.3.1 to get it to work with Django
1.7.7. I also had to update the Xapian backend. But I ran into
problems.
On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms
are greater than 245 chars (or something) when indexing. So I created
a custom field that would simply omit terms greater than 64 chars and
used this field everywhere I previously used a CharField.
Secondly, the custom search form was broken now. Something changed in
the Xapian backend and exact searches stopped working. Fortunately the
auto_query (which I was using originally and broke during an upgrade)
started working again. So I cut the search form back over to doing an
auto_query. I kept the form the same (3 fields) because I didn't want
to change the form and I think it's better that way.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 13 May 2015 20:25:07 -0500 |
parents | 988782c6ce6c |
children |
rev | line source |
---|---|
bgneal@347 | 1 import datetime |
bgneal@347 | 2 import logging |
bgneal@347 | 3 |
bgneal@347 | 4 from django.contrib.auth.models import User |
bgneal@347 | 5 |
bgneal@347 | 6 |
bgneal@690 | 7 logger = logging.getLogger('auth') |
bgneal@690 | 8 |
bgneal@690 | 9 |
bgneal@347 | 10 def create_new_user(pending_user, ip=None, admin_activation=False): |
bgneal@347 | 11 """ |
bgneal@347 | 12 This function contains the code to create a new user from a |
bgneal@347 | 13 pending user. The pending user is deleted and the new user |
bgneal@347 | 14 is saved. A log message is produced. If admin_activation is false, |
bgneal@347 | 15 then ip should be the user's IP they confirmed from, if available. |
bgneal@347 | 16 |
bgneal@347 | 17 """ |
bgneal@347 | 18 new_user = User() |
bgneal@347 | 19 |
bgneal@347 | 20 new_user.username = pending_user.username |
bgneal@347 | 21 new_user.first_name = '' |
bgneal@347 | 22 new_user.last_name = '' |
bgneal@347 | 23 new_user.email = pending_user.email |
bgneal@347 | 24 new_user.password = pending_user.password # already been hashed |
bgneal@347 | 25 new_user.is_staff = False |
bgneal@347 | 26 new_user.is_active = True |
bgneal@347 | 27 new_user.is_superuser = False |
bgneal@347 | 28 new_user.last_login = datetime.datetime.now() |
bgneal@347 | 29 new_user.date_joined = new_user.last_login |
bgneal@347 | 30 |
bgneal@347 | 31 new_user.save() |
bgneal@347 | 32 pending_user.delete() |
bgneal@347 | 33 |
bgneal@347 | 34 if admin_activation: |
bgneal@347 | 35 msg = 'Accounts registration confirmed by ADMIN for %s' % new_user.username |
bgneal@347 | 36 else: |
bgneal@347 | 37 msg = 'Accounts registration confirmed by USER for %s from %s' % ( |
bgneal@347 | 38 new_user.username, ip) |
bgneal@347 | 39 |
bgneal@690 | 40 logger.info(msg) |