mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 11:04:20 +00:00
Finish weekmail, and fix preferences page
This commit is contained in:
parent
147809bb5d
commit
ae0b7699f3
@ -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):
|
|||||||
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):
|
|||||||
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(
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
@ -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,
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
<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 %}
|
{% if weekmail.intro %}
|
||||||
<h3>{% trans %}Intro{% endtrans %}</h3>
|
<h3 style="background: black; color: white">{% trans %}Intro{% endtrans %}</h3>
|
||||||
{{ weekmail.intro|markdown }}
|
{{ weekmail.intro|markdown }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h3>{% trans %}Table of content{% endtrans %}</h3>
|
<h3 style="background: black; color: white">{% trans %}Table of content{% endtrans %}</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for a in weekmail.articles.all() %}
|
{% for a in weekmail.articles.all() %}
|
||||||
<li>[{{ a.club }}] {{ a.title }}</li>
|
<li>[{{ a.club }}] {{ a.title }}</li>
|
||||||
@ -13,22 +21,26 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{%- for a in weekmail.articles.all() %}
|
{%- for a in weekmail.articles.all() %}
|
||||||
<h3>[{{ a.club }}] {{ a.title }}</h3>
|
<h3 style="background: lightblue;">[{{ a.club }}] {{ a.title }}</h3>
|
||||||
{{ a.content|markdown }}
|
{{ a.content|markdown }}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
|
||||||
{%- if weekmail.joke %}
|
{%- if weekmail.joke %}
|
||||||
<h3>{% trans %}Joke{% endtrans %}</h3>
|
<h3 style="background: black; color: white">{% trans %}Joke{% endtrans %}</h3>
|
||||||
{{ weekmail.joke|markdown }}
|
{{ weekmail.joke|markdown }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
{%- if weekmail.protip %}
|
{%- if weekmail.protip %}
|
||||||
<h3>{% trans %}Pro tip{% endtrans %}</h3>
|
<h3 style="background: black; color: white">{% trans %}Pro tip{% endtrans %}</h3>
|
||||||
{{ weekmail.protip|markdown }}
|
{{ weekmail.protip|markdown }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
{%- if weekmail.conclusion %}
|
{%- if weekmail.conclusion %}
|
||||||
<h3>{% trans %}Final word{% endtrans %}</h3>
|
<h3 style="background: black; color: white">{% trans %}Final word{% endtrans %}</h3>
|
||||||
{{ weekmail.conclusion|markdown }}
|
{{ weekmail.conclusion|markdown }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@ -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):
|
|||||||
"""
|
"""
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user