mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Add page for clubs and inactive clubs
This commit is contained in:
32
club/migrations/0010_auto_20170912_2028.py
Normal file
32
club/migrations/0010_auto_20170912_2028.py
Normal file
@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from club.models import Club
|
||||
|
||||
|
||||
def generate_club_pages(apps, schema_editor):
|
||||
for club in Club.objects.all():
|
||||
club.make_page()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0024_auto_20170906_1317'),
|
||||
('club', '0009_auto_20170822_2232'),
|
||||
]
|
||||
|
||||
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.RunPython(generate_club_pages),
|
||||
]
|
@ -33,11 +33,11 @@ from django.core.urlresolvers import reverse
|
||||
from django.utils import timezone
|
||||
from django.core.validators import RegexValidator, validate_email
|
||||
|
||||
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 +58,7 @@ 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)
|
||||
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,6 +67,7 @@ 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']
|
||||
@ -102,6 +104,24 @@ class Club(models.Model):
|
||||
self.home = home
|
||||
self.save()
|
||||
|
||||
def make_page(self):
|
||||
if not self.page:
|
||||
root = User.objects.filter(username="root").first()
|
||||
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()
|
||||
office = Group.objects.filter(name=self.unix_name + settings.SITH_BOARD_SUFFIX).first()
|
||||
p = Page(name=self.unix_name)
|
||||
p.parent = club_root
|
||||
p.set_lock(root)
|
||||
if public:
|
||||
p.view_groups.add(public)
|
||||
if office:
|
||||
p.edit_groups.add(office)
|
||||
p.save()
|
||||
self.page = p
|
||||
self.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
creation = False
|
||||
@ -122,6 +142,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
|
||||
|
@ -2,7 +2,11 @@
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block content %}
|
||||
{% if club.page and club.page.revisions.exists() %}
|
||||
{{ club.page.revisions.last().content|markdown }}
|
||||
{% else %}
|
||||
<h3>{% trans %}Club{% endtrans %}</h3>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -117,6 +117,12 @@ class ClubTabsMixin(TabedViewMixin):
|
||||
'slug': 'edit',
|
||||
'name': _("Edit"),
|
||||
})
|
||||
if self.object.page:
|
||||
tab_list.append({
|
||||
'url': reverse('core:page_edit', kwargs={'page_name': self.object.page.get_full_name()}),
|
||||
'slug': 'page_edit',
|
||||
'name': _('Edit club page')
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
|
||||
'slug': 'sellings',
|
||||
@ -348,7 +354,7 @@ class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
||||
"""
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
fields = ['name', 'unix_name', 'parent']
|
||||
fields = ['name', 'unix_name', 'parent', 'is_active']
|
||||
template_name = 'core/edit.jinja'
|
||||
current_tab = "props"
|
||||
|
||||
|
Reference in New Issue
Block a user