diff --git a/api/views/club.py b/api/views/club.py index ca2a8c1b..e4d4b30a 100644 --- a/api/views/club.py +++ b/api/views/club.py @@ -58,6 +58,6 @@ def FetchMailingLists(request): if key != settings.SITH_MAILING_FETCH_KEY: raise PermissionDenied data = '' - for mailing in Mailing.objects.filter(is_moderated=True).all(): + for mailing in Mailing.objects.filter(is_moderated=True, club__is_active=True).all(): data += mailing.fetch_format() + "\n" return Response(data) diff --git a/club/migrations/0010_auto_20170912_2028.py b/club/migrations/0010_auto_20170912_2028.py new file mode 100644 index 00000000..af3e2bdf --- /dev/null +++ b/club/migrations/0010_auto_20170912_2028.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + +from club.models import Club +from core.operations import PsqlRunOnly + + +def generate_club_pages(apps, schema_editor): + def recursive_generate_club_page(club): + club.make_page() + for child in Club.objects.filter(parent=club).all(): + recursive_generate_club_page(child) + for club in Club.objects.filter(parent=None).all(): + recursive_generate_club_page(club) + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0024_auto_20170906_1317'), + ('club', '0010_club_logo'), + ] + + operations = [ + migrations.AddField( + model_name='club', + name='is_active', + field=models.BooleanField(default=True, verbose_name='is active'), + ), + migrations.AddField( + model_name='club', + name='page', + field=models.OneToOneField(related_name='club', blank=True, null=True, to='core.Page'), + ), + migrations.AddField( + model_name='club', + name='short_description', + field=models.CharField(verbose_name='short description', max_length=1000, default='', blank=True, null=True), + ), + PsqlRunOnly('SET CONSTRAINTS ALL IMMEDIATE', reverse_sql=migrations.RunSQL.noop), + migrations.RunPython(generate_club_pages), + PsqlRunOnly(migrations.RunSQL.noop, reverse_sql='SET CONSTRAINTS ALL IMMEDIATE'), + ] diff --git a/club/models.py b/club/models.py index d2901505..81c92ef2 100644 --- a/club/models.py +++ b/club/models.py @@ -32,12 +32,13 @@ from django.db import transaction from django.core.urlresolvers import reverse from django.utils import timezone from django.core.validators import RegexValidator, validate_email +from django.utils.functional import cached_property -from core.models import User, MetaGroup, Group, SithFile, RealGroup, Notification - +from core.models import User, MetaGroup, Group, SithFile, RealGroup, Notification, Page # Create your models here. + class Club(models.Model): """ The Club class, made as a tree to allow nice tidy organization @@ -58,6 +59,8 @@ class Club(models.Model): }, ) logo = models.ImageField(upload_to='club_logos', verbose_name=_('logo'), null=True, blank=True) + is_active = models.BooleanField(_('is active'), default=True) + short_description = models.CharField(_('short description'), max_length=1000, default='', blank=True, null=True) address = models.CharField(_('address'), max_length=254) # email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically owner_group = models.ForeignKey(Group, related_name="owned_club", @@ -66,10 +69,15 @@ class Club(models.Model): view_groups = models.ManyToManyField(Group, related_name="viewable_club", blank=True) home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True, on_delete=models.SET_NULL) + page = models.OneToOneField(Page, related_name="club", blank=True, null=True) class Meta: ordering = ['name', 'unix_name'] + @cached_property + def president(self): + return self.members.filter(role=settings.SITH_CLUB_ROLES_ID['President'], end_date=None).first() + def check_loop(self): """Raise a validation error when a loop is found within the parent list""" objs = [] @@ -102,6 +110,31 @@ class Club(models.Model): self.home = home self.save() + def make_page(self): + root = User.objects.filter(username="root").first() + if not self.page: + club_root = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first() + if root and club_root: + public = Group.objects.filter(id=settings.SITH_GROUP_PUBLIC_ID).first() + p = Page(name=self.unix_name) + p.parent = club_root + p.save(force_lock=True) + if public: + p.view_groups.add(public) + p.save(force_lock=True) + if self.parent and self.parent.page: + p.parent = self.parent.page + self.page = p + self.save() + elif self.page and self.page.name != self.unix_name: + self.page.unset_lock() + self.page.name = self.unix_name + self.page.save(force_lock=True) + elif self.page and self.parent and self.parent.page and self.page.parent != self.parent.page: + self.page.unset_lock() + self.page.parent = self.parent.page + self.page.save(force_lock=True) + def save(self, *args, **kwargs): with transaction.atomic(): creation = False @@ -122,6 +155,7 @@ class Club(models.Model): self.home.edit_groups = [board] self.home.view_groups = [member, subscribers] self.home.save() + self.make_page() def __str__(self): return self.name @@ -313,8 +347,14 @@ class MailingSubscription(models.Model): def can_be_edited_by(self, user): return (self.user is not None and user.id == self.user.id) + @property + def get_email(self): + if self.user and not self.email: + return self.user.email + return self.email + def fetch_format(self): - return self.email + ' ' + return self.get_email + ' ' def __str__(self): if self.user: diff --git a/club/templates/club/club_detail.jinja b/club/templates/club/club_detail.jinja index daedbfcb..6dbb62b2 100644 --- a/club/templates/club/club_detail.jinja +++ b/club/templates/club/club_detail.jinja @@ -2,7 +2,16 @@ {% from 'core/macros.jinja' import user_profile_link %} {% block content %} -

{% trans %}Club{% endtrans %}

+
+ {% if club.logo %} + + {% endif %} + {% if page_revision %} + {{ page_revision|markdown }} + {% else %} +

{% trans %}Club{% endtrans %}

+ {% endif %} +
{% endblock %} diff --git a/club/templates/club/club_list.jinja b/club/templates/club/club_list.jinja index 059ad85a..ba875c89 100644 --- a/club/templates/club/club_list.jinja +++ b/club/templates/club/club_list.jinja @@ -5,7 +5,20 @@ {% endblock %} {% macro display_club(club) -%} -
  • {{ club.name }} + + {% if club.is_active or user.is_root %} + +
  • {{ club.name }} + + {% if not club.is_active %} + ({% trans %}inactive{% endtrans %}) + {% endif %} + + {% if club.president %} - {{ club.president.user }}{% endif %} + {% if club.short_description %}

    {{ club.short_description|markdown }}

    {% endif %} + + {% endif %} + {%- if club.children.all()|length != 0 %}