Some com templates improvments and reordering some models

This commit is contained in:
Skia 2017-03-24 09:19:15 +01:00
parent d2da5716ba
commit 39b32d456c
10 changed files with 94 additions and 6 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounting', '0004_auto_20161005_1505'),
]
operations = [
migrations.AlterField(
model_name='operation',
name='remark',
field=models.CharField(null=True, max_length=128, blank=True, verbose_name='comment'),
),
]

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('club', '0006_auto_20161229_0040'),
]
operations = [
migrations.AlterModelOptions(
name='club',
options={'ordering': ['name', 'unix_name']},
),
]

View File

@ -38,6 +38,9 @@ class Club(models.Model):
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,
on_delete=models.SET_NULL)
class Meta:
ordering = ['name', 'unix_name']
def check_loop(self):
"""Raise a validation error when a loop is found within the parent list"""
objs = []

View File

@ -125,3 +125,5 @@ class WeekmailArticle(models.Model):
def is_owned_by(self, user):
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
def __str__(self):
return "%s - %s (%s)" % (self.title, self.author, self.club)

View File

@ -9,6 +9,7 @@
<h3>{% trans %}Weekmail{% endtrans %} {{ object.id }}</h3>
<p><a href="{{ url('com:weekmail_preview') }}">{% trans %}Preview{% endtrans %}</a></p>
<p><a href="{{ url('com:weekmail_preview') }}?send=true">{% trans %}Send{% endtrans %}</a></p>
<p><a href="{{ url('com:weekmail_article') }}">{% trans %}New article{% endtrans %}</a></p>
<h4>{% trans %}Articles in no weekmail yet{% endtrans %}</h4>
<table>
<thead>
@ -27,7 +28,13 @@
<td><a href="{{ a.club.get_absolute_url() }}">{{ a.club }}</a></td>
<td>{{ a.title }}</td>
<td>{{ a.content|markdown }}</td>
<td><a href="?add_article={{ a.id }}">{% trans %}Add to weekmail{% endtrans %}</a></td>
<td>
<a href="{{ url('com:weekmail_article_edit', article_id=a.id) }}">{% trans %}Edit{% endtrans %}</a> |
<a href="{{ url('com:weekmail_article_delete', article_id=a.id) }}">{% trans %}Delete{% endtrans %}</a> |
<a href="?add_article={{ a.id }}">{% trans %}Add to weekmail{% endtrans %}</a> |
<a href="?up_article={{ a.id }}">{% trans %}Up{% endtrans %}</a> |
<a href="?down_article={{ a.id }}">{% trans %}Down{% endtrans %}</a>
</td>
</tr>
{% endfor %}
</tbody>
@ -52,6 +59,7 @@
<td>{{ a.content|markdown }}</td>
<td>
<a href="{{ url('com:weekmail_article_edit', article_id=a.id) }}">{% trans %}Edit{% endtrans %}</a> |
<a href="{{ url('com:weekmail_article_delete', article_id=a.id) }}">{% trans %}Delete{% endtrans %}</a> |
<a href="?del_article={{ a.id }}">{% trans %}Delete from weekmail{% endtrans %}</a> |
<a href="?up_article={{ a.id }}">{% trans %}Up{% endtrans %}</a> |
<a href="?down_article={{ a.id }}">{% trans %}Down{% endtrans %}</a>

View File

@ -9,7 +9,7 @@ urlpatterns = [
url(r'^sith/edit/weekmail_destinations$', WeekmailDestinationEditView.as_view(), name='weekmail_destinations'),
url(r'^weekmail$', WeekmailEditView.as_view(), name='weekmail'),
url(r'^weekmail/preview$', WeekmailPreviewView.as_view(), name='weekmail_preview'),
url(r'^weekmail/club/(?P<club_id>[0-9]+)/new_article$', WeekmailArticleCreateView.as_view(), name='weekmail_article'),
url(r'^weekmail/club/((?P<club_id>[0-9]+)/)?new_article$', WeekmailArticleCreateView.as_view(), name='weekmail_article'),
url(r'^weekmail/article/(?P<article_id>[0-9]+)/delete$', WeekmailArticleDeleteView.as_view(), name='weekmail_article_delete'),
url(r'^weekmail/article/(?P<article_id>[0-9]+)/edit$', WeekmailArticleEditView.as_view(), name='weekmail_article_edit'),
url(r'^news$', NewsListView.as_view(), name='news_list'),

View File

@ -315,7 +315,7 @@ class WeekmailEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateVi
class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView):
"""Edit an article"""
model = WeekmailArticle
fields = ['title', 'content']
fields = ['title', 'club', 'content']
pk_url_kwarg = "article_id"
template_name = 'core/edit.jinja'
success_url = reverse_lazy('com:weekmail')
@ -325,14 +325,21 @@ class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, U
class WeekmailArticleCreateView(QuickNotifMixin, CreateView): #XXX need to protect this view
"""Post an article"""
model = WeekmailArticle
fields = ['title', 'content']
fields = ['title', 'club', 'content']
template_name = 'core/create.jinja'
success_url = reverse_lazy('core:user_tools')
quick_notif_url_arg = "qn_weekmail_new_article"
def get_initial(self):
init = {}
try:
init['club'] = Club.objects.filter(id=self.kwargs['club_id']).first()
except: pass
return init
def form_valid(self, form):
club = get_object_or_404(Club, id=self.kwargs['club_id'])
form.instance.club = club
# club = get_object_or_404(Club, id=self.kwargs['club_id'])
# form.instance.club = club
form.instance.author = self.request.user
return super(WeekmailArticleCreateView, self).form_valid(form)
@ -340,6 +347,7 @@ class WeekmailArticleDeleteView(CanEditPropMixin, DeleteView):
"""Delete an article"""
model = WeekmailArticle
template_name = 'core/delete_confirm.jinja'
pk_url_kwarg = "article_id"

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.core.validators
class Migration(migrations.Migration):
dependencies = [
('core', '0019_preferences_receive_weekmail'),
]
operations = [
migrations.AlterModelOptions(
name='group',
options={'ordering': ['name']},
),
migrations.AlterField(
model_name='page',
name='name',
field=models.CharField(validators=[django.core.validators.RegexValidator('^[A-z.+-]+$', 'Enter a valid page name. This value may contain only unaccented letters, numbers and ./+/-/_ characters.')], max_length=30, verbose_name='page unix name'),
),
]

View File

@ -33,6 +33,10 @@ class Group(AuthGroup):
help_text=_('Whether a group is a meta group or not'),
)
description = models.CharField(_('description'), max_length=60)
class Meta:
ordering = ['name']
def get_absolute_url(self):
"""
This is needed for black magic powered UpdateView's children

View File

@ -66,8 +66,10 @@
<h4>{% trans %}Communication{% endtrans %}</h4>
<ul>
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
<li><a href="{{ url('com:weekmail_article') }}">{% trans %}Create weekmail article{% endtrans %}</a></li>
<li><a href="{{ url('com:weekmail') }}">{% trans %}Weekmail{% endtrans %}</a></li>
<li><a href="{{ url('com:weekmail_destinations') }}">{% trans %}Weekmail destinations{% endtrans %}</a></li>
<li><a href="{{ url('com:news_new') }}">{% trans %}Create news{% endtrans %}</a></li>
<li><a href="{{ url('com:news_admin_list') }}">{% trans %}Moderate news{% endtrans %}</a></li>
<li><a href="{{ url('com:index_edit') }}">{% trans %}Edit index page{% endtrans %}</a></li>
<li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li>