Commit 6779b9da authored by Pierre-antoine Comby's avatar Pierre-antoine Comby

Merge branch 'app_member' into 'master'

App member

See merge request !5
parents b7059766 cc41409f
Pipeline #1453 passed with stage
in 2 minutes and 49 seconds
......@@ -6,7 +6,15 @@ from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth.models import User
from django import forms
from .models import Profile, Club
from .models import Profile, Club, Membership
from django.utils.translation import gettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms import layout, bootstrap
from crispy_forms.bootstrap import InlineField, FormActions, StrictButton, Div, Field
from crispy_forms.layout import Layout
class ProfileForm(forms.ModelForm):
......@@ -21,3 +29,33 @@ class ClubForm(forms.ModelForm):
class Meta:
model = Club
fields ='__all__'
class AddMembersForm(forms.Form):
class Meta:
fields = ('',)
class MembershipForm(forms.ModelForm):
class Meta:
model = Membership
fields = ('user','roles','date_start')
MemberFormSet = forms.modelformset_factory(Membership,
class FormSetHelper(FormHelper):
def __init__(self,*args,**kwargs):
self.form_tag = False
self.form_method = 'POST'
# self.template = 'bootstrap/table_inline_formset.html'
self.layout = Layout(
css_class="row formset-row",
......@@ -7,7 +7,7 @@ from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _
from django.urls import reverse
from django.urls import reverse, reverse_lazy
class Profile(models.Model):
......@@ -96,7 +96,7 @@ class Club(models.Model):
def get_absolute_url(self):
return reverse('member:club_detail', args=(,))
return reverse_lazy('member:club_detail', args=(,))
class Role(models.Model):
#!/usr/bin/env python
import django_tables2 as tables
from .models import Club
class ClubTable(tables.Table):
class Meta:
attrs = {'class':'table table-bordered table-condensed table-striped table-hover'}
model = Club
template_name = 'django_tables2/bootstrap.html'
fields= ('id','name','email')
row_attrs = {'class':'table-row',
'data-href': lambda record: }
......@@ -13,6 +13,7 @@ urlpatterns = [
......@@ -11,8 +11,12 @@ from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from django.db.models import Q
from .models import Profile, Club
from .forms import ProfileForm, ClubForm
from django_tables2.views import SingleTableView
from .models import Profile, Club, Membership
from .forms import ProfileForm, ClubForm,MembershipForm, MemberFormSet,FormSetHelper
from .tables import ClubTable
from note.models.transactions import Transaction
class UserCreateView(CreateView):
......@@ -26,7 +30,7 @@ class UserCreateView(CreateView):
second_form = UserCreationForm
def get_context_data(self,**kwargs):
context = super(SignUp,self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context["user_form"] = self.second_form
return context
......@@ -63,14 +67,46 @@ class ClubCreateView(LoginRequiredMixin,CreateView):
def form_valid(self,form):
return super().form_valid(form)
class ClubListView(LoginRequiredMixin,ListView):
class ClubListView(LoginRequiredMixin,SingleTableView):
List TransactionsTemplates
List existing tables
model = Club
form_class = ClubForm
table_class = ClubTable
class ClubDetailView(LoginRequiredMixin,DetailView):
model = Club
def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
club = context["club"]
club_transactions = \
Transaction.objects.all().filter(Q(source=club.note) | Q(destination=club.note))
context['history_list'] = club_transactions
club_member = \
#TODO: consider only valid Membership
context['member_list'] = club_member
return context
class ClubAddMemberView(LoginRequiredMixin,CreateView):
model = Membership
form_class = MembershipForm
template_name = 'member/add_members.html'
def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
context['formset'] = MemberFormSet()
context['helper'] = FormSetHelper()
return context
def post(self,request,*args,**kwargs):
formset = MembershipFormset(request.POST)
if formset.is_valid():
return self.form_valid(formset)
return self.form_invalid(formset)
def form_valid(self,formset):
return super().form_valid(formset)
This diff is collapsed.
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% load static %}
{% block content %}
<form method="post" action="">
{% csrf_token %}
{% crispy formset helper %}
<div class="form-actions">
<input type="submit" name="submit" value="Add Members" class="btn btn-primary" id="submit-save">
<!-- Include formset plugin - including jQuery dependency -->
<script src="//"></script>
<script src="{% static 'js/dynamic-formset.js' %}"></script>
addText: 'add another', // Text for the add link
deleteText: 'remove', // Text for the delete link
addCssClass: 'btn btn-primary', // CSS class applied to the add link
deleteCssClass: 'btn btn-danger h-50 my-auto',
{% endblock %}
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% block content %}
<p><a class="btn btn-default" href="{% url 'member:club_list' %}">Clubs</a></p>
<h5>{{ }}</h5>
{% endblock %}
<p><a class="btn btn-primary" href="{% url 'member:club_list' %}">Clubs</a></p>
<h3 class="text-center"> Club {{ }}</h3>
<dt>{% trans 'Membership starts on' %}</dt>
<dd>{{ club.membership_start }}</dd>
<dt>{% trans 'Membership ends on' %}</dt>
<dd>{{ club.membership_end }}</dd>
<dt>{% trans 'Membership duration' %}</dt>
<dd>{{ club.membership_duration }}</dd>
<dt> Aliases </dt>
<dd>{{ club.note.aliases_set.all }}</dd>
<dt>{% trans 'balance' %}</dt>
<dd>{{ club.note.balance }}</dd>
<div class="btn-group" role="group">
<a class="btn btn-primary" href="{% url 'member:club_add_member' %}"> Ajouter des membres </a>
<a class="btn btn-primary" href="{% url 'member:club_add_member' %}"> Modifier les informations </a>
<a class="btn btn-primary" href="{% url 'member:club_add_member' %}"> Ajouter des roles </a>
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="fa fa-users"></i> Membres du club
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
{% render_table member_list %}
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="fa fa-euro"></i> Historique des transactions
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
<div class="card-body">
{% render_table history_list %}
{% endblock %}
......@@ -2,7 +2,20 @@
{% load render_table from django_tables2 %}
{% block content %}
{% render_table object_list %}
{% render_table table %}
<a class="btn btn-primary" href="{% url 'member:club_create' %}">New Club</a>
{% endblock %}
{% block javascript %}
{{ block.super }}
<script type="text/javascript">
$(document).ready(function($) {
$(".table-row").click(function() {
window.document.location = $(this).data("href");
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment