mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
Format trombi
This commit is contained in:
parent
113c9e696b
commit
69c95cfd37
@ -34,15 +34,18 @@ from core.models import User
|
|||||||
from core.utils import get_start_of_semester, get_semester
|
from core.utils import get_start_of_semester, get_semester
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
|
|
||||||
|
|
||||||
class TrombiManager(models.Manager):
|
class TrombiManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(TrombiManager, self).get_queryset()
|
return super(TrombiManager, self).get_queryset()
|
||||||
|
|
||||||
|
|
||||||
class AvailableTrombiManager(models.Manager):
|
class AvailableTrombiManager(models.Manager):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return super(AvailableTrombiManager,
|
return super(AvailableTrombiManager,
|
||||||
self).get_queryset().filter(subscription_deadline__gte=date.today())
|
self).get_queryset().filter(subscription_deadline__gte=date.today())
|
||||||
|
|
||||||
|
|
||||||
class Trombi(models.Model):
|
class Trombi(models.Model):
|
||||||
"""
|
"""
|
||||||
This is the main class, the Trombi itself.
|
This is the main class, the Trombi itself.
|
||||||
@ -81,6 +84,7 @@ class Trombi(models.Model):
|
|||||||
def can_be_viewed_by(self, user):
|
def can_be_viewed_by(self, user):
|
||||||
return user.id in [u.user.id for u in self.users.all()]
|
return user.id in [u.user.id for u in self.users.all()]
|
||||||
|
|
||||||
|
|
||||||
class TrombiUser(models.Model):
|
class TrombiUser(models.Model):
|
||||||
"""
|
"""
|
||||||
This class is only here to avoid cross references between the core, club,
|
This class is only here to avoid cross references between the core, club,
|
||||||
@ -120,6 +124,7 @@ class TrombiUser(models.Model):
|
|||||||
end=end_date,
|
end=end_date,
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
|
|
||||||
class TrombiComment(models.Model):
|
class TrombiComment(models.Model):
|
||||||
"""
|
"""
|
||||||
This represent a comment given by someone to someone else in the same Trombi
|
This represent a comment given by someone to someone else in the same Trombi
|
||||||
@ -156,4 +161,3 @@ class TrombiClubMembership(models.Model):
|
|||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('trombi:profile')
|
return reverse('trombi:profile')
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.conf.urls import url, include
|
from django.conf.urls import url
|
||||||
|
|
||||||
from trombi.views import *
|
from trombi.views import *
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.views.generic import ListView, DetailView, RedirectView, TemplateView
|
from django.views.generic import DetailView, RedirectView, TemplateView
|
||||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView, FormView, SingleObjectMixin
|
from django.views.generic.edit import UpdateView, CreateView
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -35,11 +35,12 @@ from django.forms.models import modelform_factory
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from trombi.models import Trombi, TrombiUser, TrombiComment, TrombiClubMembership
|
from trombi.models import Trombi, TrombiUser, TrombiComment, TrombiClubMembership
|
||||||
from core.views.forms import SelectFile, SelectDate
|
from core.views.forms import SelectDate
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, QuickNotifMixin
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from club.models import Club
|
from club.models import Club
|
||||||
|
|
||||||
|
|
||||||
class TrombiTabsMixin(TabedViewMixin):
|
class TrombiTabsMixin(TabedViewMixin):
|
||||||
def get_tabs_title(self):
|
def get_tabs_title(self):
|
||||||
return _("Trombi")
|
return _("Trombi")
|
||||||
@ -69,9 +70,11 @@ class TrombiTabsMixin(TabedViewMixin):
|
|||||||
'slug': 'admin_tools',
|
'slug': 'admin_tools',
|
||||||
'name': _("Admin tools"),
|
'name': _("Admin tools"),
|
||||||
})
|
})
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
return tab_list
|
return tab_list
|
||||||
|
|
||||||
|
|
||||||
class TrombiForm(forms.ModelForm):
|
class TrombiForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Trombi
|
model = Trombi
|
||||||
@ -81,6 +84,7 @@ class TrombiForm(forms.ModelForm):
|
|||||||
'comments_deadline': SelectDate,
|
'comments_deadline': SelectDate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TrombiCreateView(CanEditPropMixin, CreateView):
|
class TrombiCreateView(CanEditPropMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
Create a trombi for a club
|
Create a trombi for a club
|
||||||
@ -102,6 +106,7 @@ class TrombiCreateView(CanEditPropMixin, CreateView):
|
|||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
|
||||||
class TrombiEditView(CanEditPropMixin, TrombiTabsMixin, UpdateView):
|
class TrombiEditView(CanEditPropMixin, TrombiTabsMixin, UpdateView):
|
||||||
model = Trombi
|
model = Trombi
|
||||||
form_class = TrombiForm
|
form_class = TrombiForm
|
||||||
@ -112,12 +117,14 @@ class TrombiEditView(CanEditPropMixin, TrombiTabsMixin, UpdateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return super(TrombiEditView, self).get_success_url() + "?qn_success"
|
return super(TrombiEditView, self).get_success_url() + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
||||||
model = Trombi
|
model = Trombi
|
||||||
template_name = 'trombi/detail.jinja'
|
template_name = 'trombi/detail.jinja'
|
||||||
pk_url_kwarg = 'trombi_id'
|
pk_url_kwarg = 'trombi_id'
|
||||||
current_tab = "admin_tools"
|
current_tab = "admin_tools"
|
||||||
|
|
||||||
|
|
||||||
class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
|
class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
|
||||||
model = TrombiUser
|
model = TrombiUser
|
||||||
pk_url_kwarg = 'user_id'
|
pk_url_kwarg = 'user_id'
|
||||||
@ -127,6 +134,7 @@ class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('trombi:detail', kwargs={'trombi_id': self.object.trombi.id}) + "?qn_success"
|
return reverse('trombi:detail', kwargs={'trombi_id': self.object.trombi.id}) + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
||||||
model = Trombi
|
model = Trombi
|
||||||
template_name = 'trombi/comment_moderation.jinja'
|
template_name = 'trombi/comment_moderation.jinja'
|
||||||
@ -139,10 +147,12 @@ class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMi
|
|||||||
author__trombi__id=self.object.id).exclude(target__user__id=self.request.user.id)
|
author__trombi__id=self.object.id).exclude(target__user__id=self.request.user.id)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class TrombiModerateForm(forms.Form):
|
class TrombiModerateForm(forms.Form):
|
||||||
reason = forms.CharField(help_text=_("Explain why you rejected the comment"))
|
reason = forms.CharField(help_text=_("Explain why you rejected the comment"))
|
||||||
action = forms.CharField(initial="delete", widget=forms.widgets.HiddenInput)
|
action = forms.CharField(initial="delete", widget=forms.widgets.HiddenInput)
|
||||||
|
|
||||||
|
|
||||||
class TrombiModerateCommentView(DetailView):
|
class TrombiModerateCommentView(DetailView):
|
||||||
model = TrombiComment
|
model = TrombiComment
|
||||||
template_name = 'core/edit.jinja'
|
template_name = 'core/edit.jinja'
|
||||||
@ -179,23 +189,26 @@ class TrombiModerateCommentView(DetailView):
|
|||||||
return redirect(reverse('trombi:moderate_comments', kwargs={'trombi_id': self.object.author.trombi.id}) + "?qn_success")
|
return redirect(reverse('trombi:moderate_comments', kwargs={'trombi_id': self.object.author.trombi.id}) + "?qn_success")
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(TrombiModerateCommentView, self).get_context_data(**kwargs)
|
kwargs = super(TrombiModerateCommentView, self).get_context_data(**kwargs)
|
||||||
kwargs['form'] = TrombiModerateForm()
|
kwargs['form'] = TrombiModerateForm()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
# User side
|
# User side
|
||||||
|
|
||||||
|
|
||||||
class TrombiModelChoiceField(forms.ModelChoiceField):
|
class TrombiModelChoiceField(forms.ModelChoiceField):
|
||||||
def label_from_instance(self, obj):
|
def label_from_instance(self, obj):
|
||||||
return _("%(name)s (deadline: %(date)s)") % {'name': str(obj), 'date': str(obj.subscription_deadline)}
|
return _("%(name)s (deadline: %(date)s)") % {'name': str(obj), 'date': str(obj.subscription_deadline)}
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiForm(forms.Form):
|
class UserTrombiForm(forms.Form):
|
||||||
trombi = TrombiModelChoiceField(Trombi.availables.all(), required=False, label=_("Select trombi"),
|
trombi = TrombiModelChoiceField(Trombi.availables.all(), required=False, label=_("Select trombi"),
|
||||||
help_text=_("This allows you to subscribe to a Trombi. "
|
help_text=_("This allows you to subscribe to a Trombi. "
|
||||||
"Be aware that you can subscribe only once, so don't play with that, "
|
"Be aware that you can subscribe only once, so don't play with that, "
|
||||||
"or you will expose yourself to the admins' wrath!"))
|
"or you will expose yourself to the admins' wrath!"))
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
||||||
"""
|
"""
|
||||||
Display a user's trombi tools
|
Display a user's trombi tools
|
||||||
@ -222,6 +235,7 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
|||||||
kwargs['date'] = date
|
kwargs['date'] = date
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
||||||
model = TrombiUser
|
model = TrombiUser
|
||||||
fields = ['profile_pict', 'scrub_pict']
|
fields = ['profile_pict', 'scrub_pict']
|
||||||
@ -234,13 +248,13 @@ class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('trombi:user_tools') + "?qn_success"
|
return reverse('trombi:user_tools') + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
||||||
model = User
|
model = User
|
||||||
form_class = modelform_factory(User,
|
form_class = modelform_factory(User,
|
||||||
fields=['second_email', 'phone', 'department', 'dpt_option',
|
fields=['second_email', 'phone', 'department', 'dpt_option',
|
||||||
'quote', 'parent_address'],
|
'quote', 'parent_address'],
|
||||||
labels={
|
labels={'second_email': _("Personal email (not UTBM)"),
|
||||||
'second_email': _("Personal email (not UTBM)"),
|
|
||||||
'phone': _("Phone"),
|
'phone': _("Phone"),
|
||||||
'parent_address': _("Native town"),
|
'parent_address': _("Native town"),
|
||||||
})
|
})
|
||||||
@ -253,6 +267,7 @@ class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('trombi:user_tools') + "?qn_success"
|
return reverse('trombi:user_tools') + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiResetClubMembershipsView(RedirectView):
|
class UserTrombiResetClubMembershipsView(RedirectView):
|
||||||
permanent = False
|
permanent = False
|
||||||
|
|
||||||
@ -264,6 +279,7 @@ class UserTrombiResetClubMembershipsView(RedirectView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('trombi:profile') + "?qn_success"
|
return reverse('trombi:profile') + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiDeleteMembershipView(TrombiTabsMixin, CanEditMixin, DeleteView):
|
class UserTrombiDeleteMembershipView(TrombiTabsMixin, CanEditMixin, DeleteView):
|
||||||
model = TrombiClubMembership
|
model = TrombiClubMembership
|
||||||
pk_url_kwarg = "membership_id"
|
pk_url_kwarg = "membership_id"
|
||||||
@ -274,6 +290,7 @@ class UserTrombiDeleteMembershipView(TrombiTabsMixin, CanEditMixin, DeleteView):
|
|||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return super(UserTrombiDeleteMembershipView, self).get_success_url() + "?qn_success"
|
return super(UserTrombiDeleteMembershipView, self).get_success_url() + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiEditMembershipView(CanEditMixin, TrombiTabsMixin, UpdateView):
|
class UserTrombiEditMembershipView(CanEditMixin, TrombiTabsMixin, UpdateView):
|
||||||
model = TrombiClubMembership
|
model = TrombiClubMembership
|
||||||
pk_url_kwarg = "membership_id"
|
pk_url_kwarg = "membership_id"
|
||||||
@ -300,6 +317,7 @@ class UserTrombiProfileView(TrombiTabsMixin, DetailView):
|
|||||||
raise Http404()
|
raise Http404()
|
||||||
return super(UserTrombiProfileView, self).get(request, *args, **kwargs)
|
return super(UserTrombiProfileView, self).get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TrombiCommentFormView():
|
class TrombiCommentFormView():
|
||||||
"""
|
"""
|
||||||
Create/edit a trombi comment
|
Create/edit a trombi comment
|
||||||
@ -335,6 +353,7 @@ class TrombiCommentFormView():
|
|||||||
kwargs['target'] = self.object.target
|
kwargs['target'] = self.object.target
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class TrombiCommentCreateView(TrombiCommentFormView, CreateView):
|
class TrombiCommentCreateView(TrombiCommentFormView, CreateView):
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
target = get_object_or_404(TrombiUser, id=self.kwargs['user_id'])
|
target = get_object_or_404(TrombiUser, id=self.kwargs['user_id'])
|
||||||
@ -342,11 +361,10 @@ class TrombiCommentCreateView(TrombiCommentFormView, CreateView):
|
|||||||
form.instance.target = target
|
form.instance.target = target
|
||||||
return super(TrombiCommentCreateView, self).form_valid(form)
|
return super(TrombiCommentCreateView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class TrombiCommentEditView(TrombiCommentFormView, CanViewMixin, UpdateView):
|
class TrombiCommentEditView(TrombiCommentFormView, CanViewMixin, UpdateView):
|
||||||
pk_url_kwarg = "comment_id"
|
pk_url_kwarg = "comment_id"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.is_moderated = False
|
form.instance.is_moderated = False
|
||||||
return super(TrombiCommentEditView, self).form_valid(form)
|
return super(TrombiCommentEditView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user