Add first club views, this still sucks, particularly on the right managment

This commit is contained in:
Skia 2016-02-02 16:34:36 +01:00
parent afc87888a6
commit d51ab088d8
13 changed files with 215 additions and 4 deletions

View File

@ -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'),
),
]

View File

@ -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'),
),
]

View File

@ -3,8 +3,9 @@ from django.core import validators
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError 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. # Create your models here.
@ -28,6 +29,10 @@ class Club(models.Model):
) )
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",
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): def check_loop(self):
"""Raise a validation error when a loop is found within the parent list""" """Raise a validation error when a loop is found within the parent list"""
@ -45,6 +50,9 @@ class Club(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def get_absolute_url(self):
return reverse('club:club_view', kwargs={'club_id': self.id})
class Membership(models.Model): class Membership(models.Model):
""" """
The Membership class makes the connection between User and Clubs The Membership class makes the connection between User and Clubs

View File

@ -0,0 +1,27 @@
{% extends "core/base.jinja" %}
{% block content %}
<h3>Club</h3>
<p><a href="{{ url('club:club_list') }}">Back to list</a></p>
{% if user.can_edit(club) %}
<p><a href="{{ url('club:club_edit', club_id=club.pk) }}">Edit</a></p>
<p><a href="{{ url('club:club_members', club_id=club.pk) }}">Edit members</a></p>
{% endif %}
{% if user.is_owner(club) or user.membership.filter(end_date=None).filter(club=club.id).first() is not none %}
<p><a href="{{ url('club:club_prop', club_id=club.pk) }}">Prop</a>
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!
</p>
{% endif %}
<h3>{{ club.name }}</h3>
<p>{{ club.address }}</p>
<ul>
{% for m in club.members.all() %}
<li>{{ m }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>Edit club</h2>
<form action="{{ url('club:club_edit', club_id=club.id) }}" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="Save!" /></p>
</form>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>Edit club properties</h2>
<form action="{{ url('club:club_prop', club_id=club.id) }}" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="Save!" /></p>
</form>
{% endblock %}

View File

@ -0,0 +1,33 @@
{% extends "core/base.jinja" %}
{% block title %}
Club list
{% endblock %}
{% macro display_club(club) -%}
<li><a href="{{ url('club:club_view', club_id=club.id) }}">{{ club.name }}</a>
{%- if club.children.all()|length != 0 %}
<ul>
{%- for c in club.children.all() %}
{{ display_club(c) }}
{%- endfor %}
</ul>
{%- endif -%}
</li>
{%- endmacro %}
{% block content %}
{% if club_list %}
<h3>Club list</h3>
<ul>
{%- for c in club_list if c.parent is none %}
{{ display_club(c) }}
{%- endfor %}
</ul>
{% else %}
There is no club in this website.
{% endif %}
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>Edit club</h2>
<form action="{{ url('club:club_members', club_id=club.id) }}" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="Save!" /></p>
</form>
{% endblock %}

16
club/urls.py Normal file
View File

@ -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<club_id>[0-9]+)/$', ClubView.as_view(), name='club_view'),
url(r'^(?P<club_id>[0-9]+)/edit$', ClubEditView.as_view(), name='club_edit'),
url(r'^(?P<club_id>[0-9]+)/members$', ClubEditMembersView.as_view(), name='club_members'),
url(r'^(?P<club_id>[0-9]+)/prop$', ClubEditPropView.as_view(), name='club_prop'),
#url(r'^(?P<club_id>[0-9]+)/tools$', ClubToolsView.as_view(), name='club_tools'),
## API
#url(r'^api/markdown$', render_markdown, name='api_markdown'),
]

View File

@ -1,3 +1,34 @@
from django.shortcuts import render 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.

View File

@ -30,8 +30,9 @@ class Command(BaseCommand):
u.save() u.save()
for g in settings.AE_GROUPS.values(): for g in settings.AE_GROUPS.values():
Group(id=g['id'], name=g['name']).save() Group(id=g['id'], name=g['name']).save()
Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'], ae = Club(name=settings.AE_MAIN_CLUB['name'], unix_name=settings.AE_MAIN_CLUB['unix_name'],
address=settings.AE_MAIN_CLUB['address']).save() 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 # 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']:
@ -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], 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() 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()

View File

@ -26,6 +26,7 @@
<li><a href="{{ url('core:user_profile', user_id=user.id) }}">Profile</a></li> <li><a href="{{ url('core:user_profile', user_id=user.id) }}">Profile</a></li>
<li><a href="{{ url('core:user_list') }}">Users</a></li> <li><a href="{{ url('core:user_list') }}">Users</a></li>
<li><a href="{{ url('core:page_list') }}">Pages</a></li> <li><a href="{{ url('core:page_list') }}">Pages</a></li>
<li><a href="{{ url('club:club_list') }}">Clubs</a></li>
</ul> </ul>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -24,5 +24,6 @@ handler404 = "core.views.not_found"
urlpatterns = [ urlpatterns = [
url(r'^', include('core.urls', namespace="core", app_name="core")), url(r'^', include('core.urls', namespace="core", app_name="core")),
url(r'^subscription/', include('subscription.urls', namespace="subscription", app_name="subscription")), 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)), url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!! ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!