mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Add page for clubs and inactive clubs
This commit is contained in:
parent
13620de754
commit
fe69cbcee1
@ -58,6 +58,6 @@ def FetchMailingLists(request):
|
|||||||
if key != settings.SITH_MAILING_FETCH_KEY:
|
if key != settings.SITH_MAILING_FETCH_KEY:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
data = ''
|
data = ''
|
||||||
for mailing in Mailing.objects.filter(is_moderated=True).all():
|
for mailing in Mailing.objects.filter(is_moderated=True, club__is_active=False).all():
|
||||||
data += mailing.fetch_format() + "\n"
|
data += mailing.fetch_format() + "\n"
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
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.utils import timezone
|
||||||
from django.core.validators import RegexValidator, validate_email
|
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.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class Club(models.Model):
|
class Club(models.Model):
|
||||||
"""
|
"""
|
||||||
The Club class, made as a tree to allow nice tidy organization
|
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)
|
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)
|
address = models.CharField(_('address'), max_length=254)
|
||||||
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
|
# email = models.EmailField(_('email address'), unique=True) # This should, and will be generated automatically
|
||||||
owner_group = models.ForeignKey(Group, related_name="owned_club",
|
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)
|
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,
|
home = models.OneToOneField(SithFile, related_name='home_of_club', verbose_name=_("home"), null=True, blank=True,
|
||||||
on_delete=models.SET_NULL)
|
on_delete=models.SET_NULL)
|
||||||
|
page = models.OneToOneField(Page, related_name="club", blank=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['name', 'unix_name']
|
ordering = ['name', 'unix_name']
|
||||||
@ -102,6 +104,24 @@ class Club(models.Model):
|
|||||||
self.home = home
|
self.home = home
|
||||||
self.save()
|
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):
|
def save(self, *args, **kwargs):
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
creation = False
|
creation = False
|
||||||
@ -122,6 +142,7 @@ class Club(models.Model):
|
|||||||
self.home.edit_groups = [board]
|
self.home.edit_groups = [board]
|
||||||
self.home.view_groups = [member, subscribers]
|
self.home.view_groups = [member, subscribers]
|
||||||
self.home.save()
|
self.home.save()
|
||||||
|
self.make_page()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
{% from 'core/macros.jinja' import user_profile_link %}
|
{% from 'core/macros.jinja' import user_profile_link %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if club.page and club.page.revisions.exists() %}
|
||||||
|
{{ club.page.revisions.last().content|markdown }}
|
||||||
|
{% else %}
|
||||||
<h3>{% trans %}Club{% endtrans %}</h3>
|
<h3>{% trans %}Club{% endtrans %}</h3>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,6 +117,12 @@ class ClubTabsMixin(TabedViewMixin):
|
|||||||
'slug': 'edit',
|
'slug': 'edit',
|
||||||
'name': _("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({
|
tab_list.append({
|
||||||
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
|
'url': reverse('club:club_sellings', kwargs={'club_id': self.object.id}),
|
||||||
'slug': 'sellings',
|
'slug': 'sellings',
|
||||||
@ -348,7 +354,7 @@ class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
|||||||
"""
|
"""
|
||||||
model = Club
|
model = Club
|
||||||
pk_url_kwarg = "club_id"
|
pk_url_kwarg = "club_id"
|
||||||
fields = ['name', 'unix_name', 'parent']
|
fields = ['name', 'unix_name', 'parent', 'is_active']
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
current_tab = "props"
|
current_tab = "props"
|
||||||
|
|
||||||
|
@ -147,6 +147,10 @@ Welcome to the wiki page!
|
|||||||
p.set_lock(root)
|
p.set_lock(root)
|
||||||
PageRev(page=p, title="Laverie", author=root, content="Fonctionnement de la laverie").save()
|
PageRev(page=p, title="Laverie", author=root, content="Fonctionnement de la laverie").save()
|
||||||
|
|
||||||
|
p = Page(name=settings.SITH_CLUB_ROOT_PAGE)
|
||||||
|
p.set_lock(root)
|
||||||
|
p.save()
|
||||||
|
|
||||||
# Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment
|
# Here we add a lot of test datas, that are not necessary for the Sith, but that provide a basic development environment
|
||||||
if not options['prod']:
|
if not options['prod']:
|
||||||
# Adding user Skia
|
# Adding user Skia
|
||||||
|
@ -999,6 +999,11 @@ class Page(models.Model):
|
|||||||
except:
|
except:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_club_page(self):
|
||||||
|
unauthorized_parent = Page.objects.filter(name=settings.SITH_CLUB_ROOT_PAGE).first()
|
||||||
|
return unauthorized_parent is not None and (self == unauthorized_parent or unauthorized_parent in self.get_parent_list())
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self.unset_lock_recursive()
|
self.unset_lock_recursive()
|
||||||
self.set_lock_recursive(User.objects.get(id=0))
|
self.set_lock_recursive(User.objects.get(id=0))
|
||||||
|
@ -25,12 +25,16 @@
|
|||||||
<div class="tool_bar">
|
<div class="tool_bar">
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
{% if page %}
|
{% if page %}
|
||||||
|
{% if page.club %}
|
||||||
|
<a href="{{ url('club:club_view', club_id=page.club.id) }}">{% trans %}View{% endtrans %}</a>
|
||||||
|
{% else %}
|
||||||
<a href="{{ url('core:page', page.get_full_name()) }}">{% trans %}View{% endtrans %}</a>
|
<a href="{{ url('core:page', page.get_full_name()) }}">{% trans %}View{% endtrans %}</a>
|
||||||
|
{% endif %}
|
||||||
<a href="{{ url('core:page_hist', page_name=page.get_full_name()) }}">{% trans %}History{% endtrans %}</a>
|
<a href="{{ url('core:page_hist', page_name=page.get_full_name()) }}">{% trans %}History{% endtrans %}</a>
|
||||||
{% if can_edit(page, user) %}
|
{% if can_edit(page, user) %}
|
||||||
<a href="{{ url('core:page_edit', page_name=page.get_full_name()) }}">{% trans %}Edit{% endtrans %}</a>
|
<a href="{{ url('core:page_edit', page_name=page.get_full_name()) }}">{% trans %}Edit{% endtrans %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if can_edit_prop(page, user) %}
|
{% if can_edit_prop(page, user) and not page.is_club_page %}
|
||||||
<a href="{{ url('core:page_prop', page_name=page.get_full_name()) }}">{% trans %}Prop{% endtrans %}</a>
|
<a href="{{ url('core:page_prop', page_name=page.get_full_name()) }}">{% trans %}Prop{% endtrans %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
{% extends "core/page.jinja" %}
|
{% extends "core/page.jinja" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% if page %}
|
||||||
|
{{ super() }}
|
||||||
|
{% endif %}
|
||||||
<h2>{% trans %}Page properties{% endtrans %}</h2>
|
<h2>{% trans %}Page properties{% endtrans %}</h2>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p() }}
|
{{ form.as_p() }}
|
||||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
{% if page %}
|
||||||
|
<a href="{{ url('core:page_delete', page_id=page.id)}}">{% trans %}Delete{% endtrans %}</a>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ function make_preview() {
|
|||||||
<p><input type="button" value="{% trans %}Preview{% endtrans %}" onclick="javascript:make_preview();" /></p>
|
<p><input type="button" value="{% trans %}Preview{% endtrans %}" onclick="javascript:make_preview();" /></p>
|
||||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||||
</form>
|
</form>
|
||||||
<a href="{{ url('core:page_delete', page_id=page.id)}}">{% trans %}Delete{% endtrans %}</a>
|
|
||||||
<div id="preview" class="page_content">
|
<div id="preview" class="page_content">
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -269,3 +269,17 @@ class PagePropForm(forms.ModelForm):
|
|||||||
super(PagePropForm, self).__init__(*arg, **kwargs)
|
super(PagePropForm, self).__init__(*arg, **kwargs)
|
||||||
self.fields['edit_groups'].required = False
|
self.fields['edit_groups'].required = False
|
||||||
self.fields['view_groups'].required = False
|
self.fields['view_groups'].required = False
|
||||||
|
|
||||||
|
|
||||||
|
class PageForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Page
|
||||||
|
fields = ['parent', 'name', 'owner_group', 'edit_groups', 'view_groups']
|
||||||
|
widgets = {
|
||||||
|
'edit_groups': CheckboxSelectMultiple,
|
||||||
|
'view_groups': CheckboxSelectMultiple,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(PageForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['parent'].queryset = self.fields['parent'].queryset.exclude(name=settings.SITH_CLUB_ROOT_PAGE).filter(club=None)
|
||||||
|
@ -27,13 +27,22 @@ from django.core.urlresolvers import reverse_lazy
|
|||||||
from django.views.generic import ListView, DetailView
|
from django.views.generic import ListView, DetailView
|
||||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory
|
||||||
from django.forms import CheckboxSelectMultiple
|
from django.http import Http404
|
||||||
|
|
||||||
from core.models import Page, PageRev, LockError
|
from core.models import Page, PageRev, LockError
|
||||||
from core.views.forms import MarkdownInput
|
from core.views.forms import MarkdownInput, PageForm, PagePropForm
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
|
||||||
|
|
||||||
|
|
||||||
|
class CanEditPagePropMixin(CanEditPropMixin):
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
res = super(CanEditPagePropMixin, self).dispatch(request, *args, **kwargs)
|
||||||
|
if self.object.is_club_page:
|
||||||
|
raise Http404
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class PageListView(CanViewMixin, ListView):
|
class PageListView(CanViewMixin, ListView):
|
||||||
model = Page
|
model = Page
|
||||||
template_name = 'core/page_list.jinja'
|
template_name = 'core/page_list.jinja'
|
||||||
@ -88,12 +97,7 @@ class PageRevView(CanViewMixin, DetailView):
|
|||||||
|
|
||||||
class PageCreateView(CanCreateMixin, CreateView):
|
class PageCreateView(CanCreateMixin, CreateView):
|
||||||
model = Page
|
model = Page
|
||||||
form_class = modelform_factory(Page,
|
form_class = PageForm
|
||||||
fields=['parent', 'name', 'owner_group', 'edit_groups', 'view_groups', ],
|
|
||||||
widgets={
|
|
||||||
'edit_groups': CheckboxSelectMultiple,
|
|
||||||
'view_groups': CheckboxSelectMultiple,
|
|
||||||
})
|
|
||||||
template_name = 'core/page_prop.jinja'
|
template_name = 'core/page_prop.jinja'
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
@ -118,14 +122,9 @@ class PageCreateView(CanCreateMixin, CreateView):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class PagePropView(CanEditPropMixin, UpdateView):
|
class PagePropView(CanEditPagePropMixin, UpdateView):
|
||||||
model = Page
|
model = Page
|
||||||
form_class = modelform_factory(Page,
|
form_class = PagePropForm
|
||||||
fields=['parent', 'name', 'owner_group', 'edit_groups', 'view_groups', ],
|
|
||||||
widgets={
|
|
||||||
'edit_groups': CheckboxSelectMultiple,
|
|
||||||
'view_groups': CheckboxSelectMultiple,
|
|
||||||
})
|
|
||||||
template_name = 'core/page_prop.jinja'
|
template_name = 'core/page_prop.jinja'
|
||||||
slug_field = '_full_name'
|
slug_field = '_full_name'
|
||||||
slug_url_kwarg = 'page_name'
|
slug_url_kwarg = 'page_name'
|
||||||
@ -189,7 +188,7 @@ class PageEditView(CanEditMixin, UpdateView):
|
|||||||
return super(PageEditView, self).form_valid(form)
|
return super(PageEditView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class PageDeleteView(CanEditPropMixin, DeleteView):
|
class PageDeleteView(CanEditPagePropMixin, DeleteView):
|
||||||
model = Page
|
model = Page
|
||||||
template_name = 'core/delete_confirm.jinja'
|
template_name = 'core/delete_confirm.jinja'
|
||||||
pk_url_kwarg = 'page_id'
|
pk_url_kwarg = 'page_id'
|
||||||
|
14
migrate.py
14
migrate.py
@ -1375,6 +1375,17 @@ def migrate_mailings():
|
|||||||
MailingSubscription(mailing=mailing, email=to_unicode(mailing_sub['email'])).save()
|
MailingSubscription(mailing=mailing, email=to_unicode(mailing_sub['email'])).save()
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_club_again():
|
||||||
|
cur = db.cursor(MySQLdb.cursors.SSDictCursor)
|
||||||
|
cur.execute("SELECT * FROM asso")
|
||||||
|
|
||||||
|
for club in cur:
|
||||||
|
try:
|
||||||
|
c = Club.objects.get(id=club['id_asso'])
|
||||||
|
c.is_disabled = club['hidden'] == 1
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("Start at %s" % start)
|
print("Start at %s" % start)
|
||||||
# Core
|
# Core
|
||||||
@ -1396,7 +1407,8 @@ def main():
|
|||||||
# reset_sas_moderators()
|
# reset_sas_moderators()
|
||||||
# migrate_forum()
|
# migrate_forum()
|
||||||
# reset_index('forum')
|
# reset_index('forum')
|
||||||
migrate_mailings()
|
# migrate_mailings()
|
||||||
|
migrate_club_again()
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
print("End at %s" % end)
|
print("End at %s" % end)
|
||||||
print("Running time: %s" % (end - start))
|
print("Running time: %s" % (end - start))
|
||||||
|
@ -296,6 +296,9 @@ SITH_LAUNDERETTE_MANAGER = {
|
|||||||
'address': "6 Boulevard Anatole France, 90000 Belfort"
|
'address': "6 Boulevard Anatole France, 90000 Belfort"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Main root for club pages
|
||||||
|
SITH_CLUB_ROOT_PAGE = "clubs"
|
||||||
|
|
||||||
# Define the date in the year serving as reference for the subscriptions calendar
|
# Define the date in the year serving as reference for the subscriptions calendar
|
||||||
# (month, day)
|
# (month, day)
|
||||||
SITH_START_DATE = (8, 15) # 15th August
|
SITH_START_DATE = (8, 15) # 15th August
|
||||||
|
Loading…
Reference in New Issue
Block a user