Commit ae0b7699 authored by Skia's avatar Skia 🤘
Browse files

Finish weekmail, and fix preferences page

parent 147809bb
Pipeline #729 passed with stage
in 3 minutes
...@@ -8,8 +8,8 @@ from django.conf import settings ...@@ -8,8 +8,8 @@ from django.conf import settings
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('club', '0006_auto_20161229_0040'), ('club', '0006_auto_20161229_0040'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('com', '0002_news_newsdate'), ('com', '0002_news_newsdate'),
] ]
...@@ -17,8 +17,8 @@ class Migration(migrations.Migration): ...@@ -17,8 +17,8 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Weekmail', name='Weekmail',
fields=[ fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)),
('title', models.CharField(verbose_name='title', max_length=64)), ('title', models.CharField(max_length=64, verbose_name='title', blank=True)),
('intro', models.TextField(verbose_name='intro', blank=True)), ('intro', models.TextField(verbose_name='intro', blank=True)),
('joke', models.TextField(verbose_name='joke', blank=True)), ('joke', models.TextField(verbose_name='joke', blank=True)),
('protip', models.TextField(verbose_name='protip', blank=True)), ('protip', models.TextField(verbose_name='protip', blank=True)),
...@@ -32,13 +32,13 @@ class Migration(migrations.Migration): ...@@ -32,13 +32,13 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='WeekmailArticle', name='WeekmailArticle',
fields=[ fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', serialize=False, auto_created=True)), ('id', models.AutoField(serialize=False, primary_key=True, verbose_name='ID', auto_created=True)),
('title', models.CharField(verbose_name='title', max_length=64)), ('title', models.CharField(max_length=64, verbose_name='title')),
('content', models.TextField(verbose_name='content')), ('content', models.TextField(verbose_name='content')),
('rank', models.IntegerField(verbose_name='rank', default=-1)), ('rank', models.IntegerField(verbose_name='rank', default=-1)),
('author', models.ForeignKey(related_name='owned_weekmail_articles', to=settings.AUTH_USER_MODEL, verbose_name='author')), ('author', models.ForeignKey(to=settings.AUTH_USER_MODEL, verbose_name='author', related_name='owned_weekmail_articles')),
('club', models.ForeignKey(related_name='weekmail_articles', to='club.Club', verbose_name='club')), ('club', models.ForeignKey(to='club.Club', verbose_name='club', related_name='weekmail_articles')),
('weekmail', models.ForeignKey(related_name='articles', to='com.Weekmail', verbose_name='weekmail')), ('weekmail', models.ForeignKey(to='com.Weekmail', verbose_name='weekmail', related_name='articles', null=True)),
], ],
), ),
migrations.AddField( migrations.AddField(
......
# -*- 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),
),
]
...@@ -84,6 +84,7 @@ class Weekmail(models.Model): ...@@ -84,6 +84,7 @@ class Weekmail(models.Model):
def send(self): def send(self):
dest = [i[0] for i in Preferences.objects.filter(receive_weekmail=True).values_list('user__email')] dest = [i[0] for i in Preferences.objects.filter(receive_weekmail=True).values_list('user__email')]
print(dest)
with transaction.atomic(): with transaction.atomic():
email = EmailMultiAlternatives( email = EmailMultiAlternatives(
subject=self.title, subject=self.title,
......
<h2>{{ weekmail.title }}</h2> <style type="text/css" media="all">
h1, h2, h3, h4, h5, h6, p {
{% if weekmail.intro %} padding: 5px;
<h3>{% trans %}Intro{% endtrans %}</h3> margin: 5px;
{{ weekmail.intro|markdown }} }
{% endif %} </style>
<div style="background: black; padding: 0px 5%;">
<h3>{% trans %}Table of content{% endtrans %}</h3> <div style="background: white;">
<ul> <h2 style="background: lightblue;">{{ weekmail.title }}</h2>
{% for a in weekmail.articles.all() %}
<li>[{{ a.club }}] {{ a.title }}</li> {% if weekmail.intro %}
{%- endfor %} <h3 style="background: black; color: white">{% trans %}Intro{% endtrans %}</h3>
</ul> {{ weekmail.intro|markdown }}
{% endif %}
{%- for a in weekmail.articles.all() %}
<h3>[{{ a.club }}] {{ a.title }}</h3> <h3 style="background: black; color: white">{% trans %}Table of content{% endtrans %}</h3>
{{ a.content|markdown }} <ul>
{%- endfor -%} {% for a in weekmail.articles.all() %}
<li>[{{ a.club }}] {{ a.title }}</li>
{%- if weekmail.joke %} {%- endfor %}
<h3>{% trans %}Joke{% endtrans %}</h3> </ul>
{{ weekmail.joke|markdown }}
{% endif -%} {%- for a in weekmail.articles.all() %}
<h3 style="background: lightblue;">[{{ a.club }}] {{ a.title }}</h3>
{%- if weekmail.protip %} {{ a.content|markdown }}
<h3>{% trans %}Pro tip{% endtrans %}</h3> {%- endfor -%}
{{ weekmail.protip|markdown }}
{% endif -%} {%- if weekmail.joke %}
<h3 style="background: black; color: white">{% trans %}Joke{% endtrans %}</h3>
{%- if weekmail.conclusion %} {{ weekmail.joke|markdown }}
<h3>{% trans %}Final word{% endtrans %}</h3> {% endif -%}
{{ weekmail.conclusion|markdown }}
{% endif -%} {%- if weekmail.protip %}
<h3 style="background: black; color: white">{% trans %}Pro tip{% endtrans %}</h3>
{{ weekmail.protip|markdown }}
{% endif -%}
{%- if weekmail.conclusion %}
<h3 style="background: black; color: white">{% trans %}Final word{% endtrans %}</h3>
{{ weekmail.conclusion|markdown }}
{% endif -%}
</div>
</div>
...@@ -14,6 +14,6 @@ class Migration(migrations.Migration): ...@@ -14,6 +14,6 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='preferences', model_name='preferences',
name='receive_weekmail', 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'),
), ),
] ]
...@@ -387,21 +387,26 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView): ...@@ -387,21 +387,26 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
""" """
Edit a user's preferences Edit a user's preferences
""" """
model = Preferences model = User
pk_url_kwarg = "user_id" pk_url_kwarg = "user_id"
template_name = "core/edit.jinja" template_name = "core/edit.jinja"
fields = ['receive_weekmail'] form_class = modelform_factory(Preferences, fields=['receive_weekmail'])
context_object_name = "profile" context_object_name = "profile"
current_tab = "prefs" current_tab = "prefs"
def get_object(self, queryset=None): def get_object(self, queryset=None):
user = get_object_or_404(User, pk=self.kwargs['user_id']) 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: try:
return user.preferences pref = self.object.preferences
except: except:
pref = Preferences(user=user) pref = Preferences(user=self.object)
pref.save() pref.save()
return pref kwargs.update({'instance': pref})
return kwargs
class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView): class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
""" """
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment