diff --git a/club/migrations/0002_auto_20160202_1345.py b/club/migrations/0002_auto_20160202_1345.py
new file mode 100644
index 00000000..0d88c844
--- /dev/null
+++ b/club/migrations/0002_auto_20160202_1345.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('core', '0001_initial'),
+ ('club', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='club',
+ name='edit_group',
+ field=models.ManyToManyField(to='core.Group', blank=True, related_name='editable_club'),
+ ),
+ migrations.AddField(
+ model_name='club',
+ name='view_group',
+ field=models.ManyToManyField(to='core.Group', blank=True, related_name='viewable_club'),
+ ),
+ ]
diff --git a/club/migrations/0003_club_owner_group.py b/club/migrations/0003_club_owner_group.py
new file mode 100644
index 00000000..6425f7cd
--- /dev/null
+++ b/club/migrations/0003_club_owner_group.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('core', '0001_initial'),
+ ('club', '0002_auto_20160202_1345'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='club',
+ name='owner_group',
+ field=models.ForeignKey(default=1, to='core.Group', related_name='owned_club'),
+ ),
+ ]
diff --git a/club/models.py b/club/models.py
index f5774498..00b7287f 100644
--- a/club/models.py
+++ b/club/models.py
@@ -3,8 +3,9 @@ from django.core import validators
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
+from django.core.urlresolvers import reverse
-from core.models import User
+from core.models import User, Group
# Create your models here.
@@ -28,6 +29,10 @@ class Club(models.Model):
)
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",
+ default=settings.AE_GROUPS['root']['id'])
+ edit_group = models.ManyToManyField(Group, related_name="editable_club", blank=True)
+ view_group = models.ManyToManyField(Group, related_name="viewable_club", blank=True)
def check_loop(self):
"""Raise a validation error when a loop is found within the parent list"""
@@ -45,6 +50,9 @@ class Club(models.Model):
def __str__(self):
return self.name
+ def get_absolute_url(self):
+ return reverse('club:club_view', kwargs={'club_id': self.id})
+
class Membership(models.Model):
"""
The Membership class makes the connection between User and Clubs
diff --git a/club/templates/club/club_detail.jinja b/club/templates/club/club_detail.jinja
new file mode 100644
index 00000000..68d78dde
--- /dev/null
+++ b/club/templates/club/club_detail.jinja
@@ -0,0 +1,27 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+
Club
+ Back to list
+ {% if user.can_edit(club) %}
+ Edit
+ Edit members
+ {% endif %}
+ {% if user.is_owner(club) or user.membership.filter(end_date=None).filter(club=club.id).first() is not none %}
+ Prop
+ TODO FIXME: this code sucks and is just a test!
+ We need something really easy to manage the views rights regarding the subscribing status and the membership of
+ someone!
+
+ {% endif %}
+ {{ club.name }}
+ {{ club.address }}
+
+ {% for m in club.members.all() %}
+ - {{ m }}
+ {% endfor %}
+
+{% endblock %}
+
+
+
diff --git a/club/templates/club/club_edit.jinja b/club/templates/club/club_edit.jinja
new file mode 100644
index 00000000..a7dcdf31
--- /dev/null
+++ b/club/templates/club/club_edit.jinja
@@ -0,0 +1,13 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+ Edit club
+
+{% endblock %}
+
+
+
diff --git a/club/templates/club/club_edit_prop.jinja b/club/templates/club/club_edit_prop.jinja
new file mode 100644
index 00000000..23d63d11
--- /dev/null
+++ b/club/templates/club/club_edit_prop.jinja
@@ -0,0 +1,13 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+ Edit club properties
+
+{% endblock %}
+
+
+
diff --git a/club/templates/club/club_list.jinja b/club/templates/club/club_list.jinja
new file mode 100644
index 00000000..4685ebf7
--- /dev/null
+++ b/club/templates/club/club_list.jinja
@@ -0,0 +1,33 @@
+{% extends "core/base.jinja" %}
+
+{% block title %}
+ Club list
+{% endblock %}
+
+{% macro display_club(club) -%}
+ {{ club.name }}
+ {%- if club.children.all()|length != 0 %}
+
+ {%- for c in club.children.all() %}
+ {{ display_club(c) }}
+ {%- endfor %}
+
+ {%- endif -%}
+
+{%- endmacro %}
+
+{% block content %}
+ {% if club_list %}
+ Club list
+
+ {%- for c in club_list if c.parent is none %}
+ {{ display_club(c) }}
+ {%- endfor %}
+
+ {% else %}
+ There is no club in this website.
+ {% endif %}
+{% endblock %}
+
+
+
diff --git a/club/templates/club/club_members.jinja b/club/templates/club/club_members.jinja
new file mode 100644
index 00000000..6d93f1ff
--- /dev/null
+++ b/club/templates/club/club_members.jinja
@@ -0,0 +1,13 @@
+{% extends "core/base.jinja" %}
+
+{% block content %}
+ Edit club
+
+{% endblock %}
+
+
+
diff --git a/club/urls.py b/club/urls.py
new file mode 100644
index 00000000..f6392cdf
--- /dev/null
+++ b/club/urls.py
@@ -0,0 +1,16 @@
+from django.conf.urls import url, include
+
+from club.views import *
+
+urlpatterns = [
+ url(r'^$', ClubListView.as_view(), name='club_list'),
+ url(r'^(?P[0-9]+)/$', ClubView.as_view(), name='club_view'),
+ url(r'^(?P[0-9]+)/edit$', ClubEditView.as_view(), name='club_edit'),
+ url(r'^(?P[0-9]+)/members$', ClubEditMembersView.as_view(), name='club_members'),
+ url(r'^(?P[0-9]+)/prop$', ClubEditPropView.as_view(), name='club_prop'),
+ #url(r'^(?P[0-9]+)/tools$', ClubToolsView.as_view(), name='club_tools'),
+
+ ## API
+ #url(r'^api/markdown$', render_markdown, name='api_markdown'),
+]
+
diff --git a/club/views.py b/club/views.py
index 91ea44a2..b17da97e 100644
--- a/club/views.py
+++ b/club/views.py
@@ -1,3 +1,34 @@
from django.shortcuts import render
+from django.views.generic import ListView, DetailView
+from django.views.generic.edit import UpdateView
+from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
+
+from club.models import Club, Membership
+
+class ClubListView(CanViewMixin, ListView):
+ model = Club
+ template_name = 'club/club_list.jinja'
+
+class ClubView(CanViewMixin, DetailView):
+ model = Club
+ pk_url_kwarg = "club_id"
+ template_name = 'club/club_detail.jinja'
+
+class ClubEditView(CanEditMixin, UpdateView):
+ model = Club
+ pk_url_kwarg = "club_id"
+ fields = ['address']
+ template_name = 'club/club_edit.jinja'
+
+class ClubEditMembersView(CanEditMixin, UpdateView):
+ model = Club
+ pk_url_kwarg = "club_id"
+ fields = ['user']
+ template_name = 'club/club_members.jinja'
+
+class ClubEditPropView(CanEditPropMixin, UpdateView):
+ model = Club
+ pk_url_kwarg = "club_id"
+ fields = ['name', 'address', 'parent']
+ template_name = 'club/club_edit_prop.jinja'
-# Create your views here.
diff --git a/core/management/commands/setup.py b/core/management/commands/setup.py
index f15ab16e..453dff52 100755
--- a/core/management/commands/setup.py
+++ b/core/management/commands/setup.py
@@ -30,8 +30,9 @@ class Command(BaseCommand):
u.save()
for g in settings.AE_GROUPS.values():
Group(id=g['id'], name=g['name']).save()
- Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
- address=settings.AE_MAIN_CLUB['address']).save()
+ ae = Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
+ address=settings.AE_MAIN_CLUB['address'])
+ ae.save()
# 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']:
@@ -67,3 +68,12 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
Subscription(member=Subscriber.objects.filter(pk=s.pk).first(), subscription_type=list(settings.AE_SUBSCRIPTIONS.keys())[0],
payment_method=settings.AE_PAYMENT_METHOD[0]).save()
+ Club(name="Bibo'UT", unix_name="bibout",
+ address="46 de la Boustifaille", parent=ae).save()
+ guyut = Club(name="Guy'UT", unix_name="guyut",
+ address="42 de la Boustifaille", parent=ae)
+ guyut.save()
+ Club(name="Woenzel'UT", unix_name="woenzel",
+ address="Woenzel", parent=guyut).save()
+ Club(name="BdF", unix_name="bdf",
+ address="Guyéuéyuéyuyé").save()
diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja
index 138d1d3b..65ad7173 100644
--- a/core/templates/core/base.jinja
+++ b/core/templates/core/base.jinja
@@ -26,6 +26,7 @@
Profile
Users
Pages
+ Clubs
{% endif %}
{% endblock %}
diff --git a/sith/urls.py b/sith/urls.py
index a7748fb7..42130de9 100644
--- a/sith/urls.py
+++ b/sith/urls.py
@@ -24,5 +24,6 @@ handler404 = "core.views.not_found"
urlpatterns = [
url(r'^', include('core.urls', namespace="core", app_name="core")),
url(r'^subscription/', include('subscription.urls', namespace="subscription", app_name="subscription")),
+ url(r'^club/', include('club.urls', namespace="club", app_name="club")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!