Finish weekmail, and fix preferences page

This commit is contained in:
Skia 2017-01-15 22:56:21 +01:00
parent 147809bb5d
commit ae0b7699f3
6 changed files with 59 additions and 65 deletions

View File

@ -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(

View File

@ -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),
),
]

View File

@ -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,

View File

@ -1,34 +1,46 @@
<h2>{{ weekmail.title }}</h2>
<style type="text/css" media="all">
h1, h2, h3, h4, h5, h6, p {
padding: 5px;
margin: 5px;
}
</style>
<div style="background: black; padding: 0px 5%;">
<div style="background: white;">
<h2 style="background: lightblue;">{{ weekmail.title }}</h2>
{% if weekmail.intro %}
<h3>{% trans %}Intro{% endtrans %}</h3>
{{ weekmail.intro|markdown }}
{% endif %}
{% if weekmail.intro %}
<h3 style="background: black; color: white">{% trans %}Intro{% endtrans %}</h3>
{{ weekmail.intro|markdown }}
{% endif %}
<h3>{% trans %}Table of content{% endtrans %}</h3>
<ul>
<h3 style="background: black; color: white">{% trans %}Table of content{% endtrans %}</h3>
<ul>
{% for a in weekmail.articles.all() %}
<li>[{{ a.club }}] {{ a.title }}</li>
{%- endfor %}
</ul>
</ul>
{%- for a in weekmail.articles.all() %}
<h3>[{{ a.club }}] {{ a.title }}</h3>
{{ a.content|markdown }}
{%- endfor -%}
{%- for a in weekmail.articles.all() %}
<h3 style="background: lightblue;">[{{ a.club }}] {{ a.title }}</h3>
{{ a.content|markdown }}
{%- endfor -%}
{%- if weekmail.joke %}
<h3>{% trans %}Joke{% endtrans %}</h3>
{{ weekmail.joke|markdown }}
{% endif -%}
{%- if weekmail.joke %}
<h3 style="background: black; color: white">{% trans %}Joke{% endtrans %}</h3>
{{ weekmail.joke|markdown }}
{% endif -%}
{%- if weekmail.protip %}
<h3>{% trans %}Pro tip{% endtrans %}</h3>
{{ weekmail.protip|markdown }}
{% endif -%}
{%- if weekmail.protip %}
<h3 style="background: black; color: white">{% trans %}Pro tip{% endtrans %}</h3>
{{ weekmail.protip|markdown }}
{% endif -%}
{%- if weekmail.conclusion %}
<h3>{% trans %}Final word{% endtrans %}</h3>
{{ weekmail.conclusion|markdown }}
{% endif -%}
{%- if weekmail.conclusion %}
<h3 style="background: black; color: white">{% trans %}Final word{% endtrans %}</h3>
{{ weekmail.conclusion|markdown }}
{% endif -%}
</div>
</div>

View File

@ -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'),
),
]

View File

@ -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):
"""