mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add godfathers
This commit is contained in:
@ -6,6 +6,7 @@ from django.contrib.auth import logout, login, authenticate
|
||||
from django.forms import CheckboxSelectMultiple, Select, DateInput, TextInput, DateTimeInput
|
||||
from django.utils.translation import ugettext as _
|
||||
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
|
||||
from ajax_select.fields import AutoCompleteSelectField
|
||||
|
||||
import logging
|
||||
import re
|
||||
@ -198,6 +199,10 @@ class UserPropForm(forms.ModelForm):
|
||||
'groups': CheckboxSelectMultiple,
|
||||
}
|
||||
|
||||
class UserGodfathersForm(forms.Form):
|
||||
type = forms.ChoiceField(choices=[('godfather', _("Godfather")), ('godchild', _("Godchild"))], label=_("Add"))
|
||||
user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None)
|
||||
|
||||
class PagePropForm(forms.ModelForm):
|
||||
error_css_class = 'error'
|
||||
required_css_class = 'required'
|
||||
|
@ -18,7 +18,7 @@ from datetime import timedelta, datetime, date
|
||||
import logging
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm
|
||||
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm, UserGodfathersForm
|
||||
from core.models import User, SithFile
|
||||
from subscription.models import Subscription
|
||||
|
||||
@ -128,6 +128,11 @@ class UserTabsMixin(TabedViewMixin):
|
||||
'slug': 'infos',
|
||||
'name': _("Infos"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('core:user_godfathers', kwargs={'user_id': self.object.id}),
|
||||
'slug': 'godfather',
|
||||
'name': _("Godfathers"),
|
||||
})
|
||||
if self.request.user == self.object:
|
||||
tab_list.append({
|
||||
'url': reverse('core:user_tools'),
|
||||
@ -174,6 +179,37 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
template_name = "core/user_detail.jinja"
|
||||
current_tab = 'infos'
|
||||
|
||||
class UserGodfathersView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Display a user's godfathers
|
||||
"""
|
||||
model = User
|
||||
pk_url_kwarg = "user_id"
|
||||
context_object_name = "profile"
|
||||
template_name = "core/user_godfathers.jinja"
|
||||
current_tab = 'godfathers'
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.form = UserGodfathersForm(request.POST)
|
||||
if self.form.is_valid() and self.form.cleaned_data['user'] != self.object:
|
||||
if self.form.cleaned_data['type'] == 'godfather':
|
||||
self.object.godfathers.add(self.form.cleaned_data['user'])
|
||||
self.object.save()
|
||||
else:
|
||||
self.object.godchildren.add(self.form.cleaned_data['user'])
|
||||
self.object.save()
|
||||
self.form = UserGodfathersForm()
|
||||
return super(UserGodfathersView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserGodfathersView, self).get_context_data(**kwargs)
|
||||
try:
|
||||
kwargs['form'] = self.form
|
||||
except:
|
||||
kwargs['form'] = UserGodfathersForm()
|
||||
return kwargs
|
||||
|
||||
class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Display a user's stats
|
||||
|
Reference in New Issue
Block a user