0001-local-user-profile-storing-welcome-message-view-stat.patch
combo/data/migrations/0010_profile.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import models, migrations |
|
5 |
from django.conf import settings |
|
6 | ||
7 |
def add_missing_profiles(apps, schema_editor): |
|
8 |
User = apps.get_model(settings.AUTH_USER_MODEL) |
|
9 |
Profile = apps.get_model('data', 'Profile') |
|
10 |
for user in User.objects.filter(profile__isnull=True): |
|
11 |
profile, created = Profile.objects.get_or_create(user=user) |
|
12 |
profile.welcome_message_viewed=True |
|
13 |
profile.save() |
|
14 | ||
15 |
def backward(apps, schema_editor): |
|
16 |
pass |
|
17 | ||
18 | ||
19 |
class Migration(migrations.Migration): |
|
20 | ||
21 |
dependencies = [ |
|
22 |
migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
|
23 |
('data', '0009_auto_20150529_2247'), |
|
24 |
] |
|
25 | ||
26 |
operations = [ |
|
27 |
migrations.CreateModel( |
|
28 |
name='Profile', |
|
29 |
fields=[ |
|
30 |
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), |
|
31 |
('welcome_message_viewed', models.BooleanField(default=False)), |
|
32 |
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), |
|
33 |
], |
|
34 |
options={ |
|
35 |
}, |
|
36 |
bases=(models.Model,), |
|
37 |
), |
|
38 |
migrations.RunPython(add_missing_profiles, backward) |
|
39 |
] |
combo/data/models.py | ||
---|---|---|
27 | 27 |
from django import template |
28 | 28 |
from django.utils.safestring import mark_safe |
29 | 29 |
from django.utils.translation import ugettext_lazy as _ |
30 |
from django.db.models.signals import post_save |
|
30 | 31 | |
31 | 32 |
from ckeditor.fields import RichTextField |
32 | 33 |
import cmsplugin_blurp.utils |
... | ... | |
49 | 50 |
return True |
50 | 51 |
return len(set(page_groups).intersection(user.groups.all())) > 0 |
51 | 52 | |
53 |
def create_profile(sender, instance, created, **kwargs): |
|
54 |
if created: |
|
55 |
Profile.objects.create(user=instance) |
|
56 |
post_save.connect(create_profile, sender=settings.AUTH_USER_MODEL) |
|
57 | ||
58 | ||
59 |
class Profile(models.Model): |
|
60 |
user = models.OneToOneField(settings.AUTH_USER_MODEL) |
|
61 |
welcome_message_viewed = models.BooleanField(default=False) |
|
62 | ||
52 | 63 | |
53 | 64 |
class Page(models.Model): |
54 | 65 |
title = models.CharField(_('Title'), max_length=50) |
55 |
- |