From ae0b7699f3ece6285c42a7c87975fcb7a8989d99 Mon Sep 17 00:00:00 2001 From: Skia Date: Sun, 15 Jan 2017 22:56:21 +0100 Subject: [PATCH] Finish weekmail, and fix preferences page --- ...103_1341.py => 0003_auto_20170115_2300.py} | 16 ++--- com/migrations/0004_auto_20170107_1222.py | 24 ------- com/models.py | 1 + .../com/weekmail_renderer_html.jinja | 66 +++++++++++-------- .../0019_preferences_receive_weekmail.py | 2 +- core/views/user.py | 15 +++-- 6 files changed, 59 insertions(+), 65 deletions(-) rename com/migrations/{0003_auto_20170103_1341.py => 0003_auto_20170115_2300.py} (64%) delete mode 100644 com/migrations/0004_auto_20170107_1222.py diff --git a/com/migrations/0003_auto_20170103_1341.py b/com/migrations/0003_auto_20170115_2300.py similarity index 64% rename from com/migrations/0003_auto_20170103_1341.py rename to com/migrations/0003_auto_20170115_2300.py index ebcddb20..660c7635 100644 --- a/com/migrations/0003_auto_20170103_1341.py +++ b/com/migrations/0003_auto_20170115_2300.py @@ -8,8 +8,8 @@ from django.conf import settings class Migration(migrations.Migration): dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('club', '0006_auto_20161229_0040'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('com', '0002_news_newsdate'), ] @@ -17,8 +17,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Weekmail', fields=[ - ('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), - ('title', models.CharField(verbose_name='title', max_length=64)), + ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)), + ('title', models.CharField(max_length=64, verbose_name='title', blank=True)), ('intro', models.TextField(verbose_name='intro', blank=True)), ('joke', models.TextField(verbose_name='joke', blank=True)), ('protip', models.TextField(verbose_name='protip', blank=True)), @@ -32,13 +32,13 @@ class Migration(migrations.Migration): migrations.CreateModel( name='WeekmailArticle', fields=[ - ('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), - ('title', models.CharField(verbose_name='title', max_length=64)), + ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)), + ('title', models.CharField(max_length=64, verbose_name='title')), ('content', models.TextField(verbose_name='content')), ('rank', models.IntegerField(verbose_name='rank', default=-1)), - ('author', models.ForeignKey(related_name='owned_weekmail_articles', to=settings.AUTH_USER_MODEL, verbose_name='author')), - ('club', models.ForeignKey(related_name='weekmail_articles', to='club.Club', verbose_name='club')), - ('weekmail', models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail')), + ('author', models.ForeignKey(to=settings.AUTH_USER_MODEL, verbose_name='author', related_name='owned_weekmail_articles')), + ('club', models.ForeignKey(to='club.Club', verbose_name='club', related_name='weekmail_articles')), + ('weekmail', models.ForeignKey(to='com.Weekmail', verbose_name='weekmail', related_name='articles', null=True)), ], ), migrations.AddField( diff --git a/com/migrations/0004_auto_20170107_1222.py b/com/migrations/0004_auto_20170107_1222.py deleted file mode 100644 index 41d8bcec..00000000 --- a/com/migrations/0004_auto_20170107_1222.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('com', '0003_auto_20170103_1341'), - ] - - operations = [ - migrations.AlterField( - model_name='weekmail', - name='title', - field=models.CharField(verbose_name='title', max_length=64, blank=True), - ), - migrations.AlterField( - model_name='weekmailarticle', - name='weekmail', - field=models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail', null=True), - ), - ] diff --git a/com/models.py b/com/models.py index 34ea514a..3b6ca542 100644 --- a/com/models.py +++ b/com/models.py @@ -84,6 +84,7 @@ class Weekmail(models.Model): def send(self): dest = [i[0] for i in Preferences.objects.filter(receive_weekmail=True).values_list('user__email')] + print(dest) with transaction.atomic(): email = EmailMultiAlternatives( subject=self.title, diff --git a/com/templates/com/weekmail_renderer_html.jinja b/com/templates/com/weekmail_renderer_html.jinja index 1b6c518c..37a9bc50 100644 --- a/com/templates/com/weekmail_renderer_html.jinja +++ b/com/templates/com/weekmail_renderer_html.jinja @@ -1,34 +1,46 @@ -

{{ weekmail.title }}

+ +
+
+

{{ weekmail.title }}

-{% if weekmail.intro %} -

{% trans %}Intro{% endtrans %}

-{{ weekmail.intro|markdown }} -{% endif %} + {% if weekmail.intro %} +

{% trans %}Intro{% endtrans %}

+ {{ weekmail.intro|markdown }} + {% endif %} -

{% trans %}Table of content{% endtrans %}

-
    - {% for a in weekmail.articles.all() %} -
  • [{{ a.club }}] {{ a.title }}
  • - {%- endfor %} -
+

{% trans %}Table of content{% endtrans %}

+
    + {% for a in weekmail.articles.all() %} +
  • [{{ a.club }}] {{ a.title }}
  • + {%- endfor %} +
-{%- for a in weekmail.articles.all() %} -

[{{ a.club }}] {{ a.title }}

-{{ a.content|markdown }} -{%- endfor -%} + {%- for a in weekmail.articles.all() %} +

[{{ a.club }}] {{ a.title }}

+ {{ a.content|markdown }} + {%- endfor -%} -{%- if weekmail.joke %} -

{% trans %}Joke{% endtrans %}

-{{ weekmail.joke|markdown }} -{% endif -%} + {%- if weekmail.joke %} +

{% trans %}Joke{% endtrans %}

+ {{ weekmail.joke|markdown }} + {% endif -%} -{%- if weekmail.protip %} -

{% trans %}Pro tip{% endtrans %}

-{{ weekmail.protip|markdown }} -{% endif -%} + {%- if weekmail.protip %} +

{% trans %}Pro tip{% endtrans %}

+ {{ weekmail.protip|markdown }} + {% endif -%} -{%- if weekmail.conclusion %} -

{% trans %}Final word{% endtrans %}

-{{ weekmail.conclusion|markdown }} -{% endif -%} + {%- if weekmail.conclusion %} +

{% trans %}Final word{% endtrans %}

+ {{ weekmail.conclusion|markdown }} + {% endif -%} + +
+ +
diff --git a/core/migrations/0019_preferences_receive_weekmail.py b/core/migrations/0019_preferences_receive_weekmail.py index b02b1c19..7f7b117a 100644 --- a/core/migrations/0019_preferences_receive_weekmail.py +++ b/core/migrations/0019_preferences_receive_weekmail.py @@ -14,6 +14,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='preferences', name='receive_weekmail', - field=models.BooleanField(verbose_name='define if we want to receive the weekmail', default=False, help_text='Do you want to receive the weekmail'), + field=models.BooleanField(default=False, verbose_name='do you want to receive the weekmail'), ), ] diff --git a/core/views/user.py b/core/views/user.py index 03a31a86..95a67c7e 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -387,21 +387,26 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView): """ Edit a user's preferences """ - model = Preferences + model = User pk_url_kwarg = "user_id" template_name = "core/edit.jinja" - fields = ['receive_weekmail'] + form_class = modelform_factory(Preferences, fields=['receive_weekmail']) context_object_name = "profile" current_tab = "prefs" def get_object(self, queryset=None): user = get_object_or_404(User, pk=self.kwargs['user_id']) + return user + + def get_form_kwargs(self): + kwargs = super(UserPreferencesView, self).get_form_kwargs() try: - return user.preferences + pref = self.object.preferences except: - pref = Preferences(user=user) + pref = Preferences(user=self.object) pref.save() - return pref + kwargs.update({'instance': pref}) + return kwargs class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView): """