mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 22:23:23 +00:00
Merge branch 'trombi' into 'master'
Trombi fixs See merge request ae/Sith!240
This commit is contained in:
commit
fd5cd56f81
@ -40,5 +40,3 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
{{ subscribe_form.as_p() }}
|
{{ subscribe_form.as_p() }}
|
||||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% endif %}
|
||||||
|
{% if trombi %}
|
||||||
<p>{% trans trombi = user.trombi_user.trombi %}You are subscribed to the Trombi {{ trombi }}{% endtrans %}</p>
|
<p>{% trans trombi = user.trombi_user.trombi %}You are subscribed to the Trombi {{ trombi }}{% endtrans %}</p>
|
||||||
<hr>
|
<hr>
|
||||||
{% set can_comment = trombi.subscription_deadline < date.today() and
|
{% set can_comment = trombi.subscription_deadline < date.today() and
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
from django.http import Http404, HttpResponseRedirect
|
from django.http import Http404, HttpResponseRedirect
|
||||||
from django.shortcuts import 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_lazy, reverse
|
||||||
from django.views.generic import DetailView, RedirectView, TemplateView
|
from django.views.generic import DetailView, RedirectView, TemplateView, View
|
||||||
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
from django.views.generic.edit import UpdateView, CreateView, DeleteView
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django import forms
|
from django import forms
|
||||||
@ -59,20 +59,21 @@ class TrombiTabsMixin(TabedViewMixin):
|
|||||||
tab_list.append(
|
tab_list.append(
|
||||||
{"url": reverse("trombi:user_tools"), "slug": "tools", "name": _("Tools")}
|
{"url": reverse("trombi:user_tools"), "slug": "tools", "name": _("Tools")}
|
||||||
)
|
)
|
||||||
tab_list.append(
|
if hasattr(self.request.user, "trombi_user"):
|
||||||
{
|
tab_list.append(
|
||||||
"url": reverse("trombi:profile"),
|
{
|
||||||
"slug": "profile",
|
"url": reverse("trombi:profile"),
|
||||||
"name": _("My profile"),
|
"slug": "profile",
|
||||||
}
|
"name": _("My profile"),
|
||||||
)
|
}
|
||||||
tab_list.append(
|
)
|
||||||
{
|
tab_list.append(
|
||||||
"url": reverse("trombi:pictures"),
|
{
|
||||||
"slug": "pictures",
|
"url": reverse("trombi:pictures"),
|
||||||
"name": _("My pictures"),
|
"slug": "pictures",
|
||||||
}
|
"name": _("My pictures"),
|
||||||
)
|
}
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
trombi = self.request.user.trombi_user.trombi
|
trombi = self.request.user.trombi_user.trombi
|
||||||
if self.request.user.is_owner(trombi):
|
if self.request.user.is_owner(trombi):
|
||||||
@ -90,6 +91,19 @@ class TrombiTabsMixin(TabedViewMixin):
|
|||||||
return tab_list
|
return tab_list
|
||||||
|
|
||||||
|
|
||||||
|
class UserIsInATrombiMixin(View):
|
||||||
|
"""
|
||||||
|
This view check if the requested user has a trombi_user attribute
|
||||||
|
"""
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
if not hasattr(self.request.user, "trombi_user"):
|
||||||
|
raise Http404()
|
||||||
|
|
||||||
|
return super(UserIsInATrombiMixin, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class TrombiForm(forms.ModelForm):
|
class TrombiForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Trombi
|
model = Trombi
|
||||||
@ -299,9 +313,13 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
|||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.form = UserTrombiForm(request.POST)
|
self.form = UserTrombiForm(request.POST)
|
||||||
if self.form.is_valid():
|
if self.form.is_valid():
|
||||||
trombi_user = TrombiUser(
|
if hasattr(request.user, "trombi_user"):
|
||||||
user=request.user, trombi=self.form.cleaned_data["trombi"]
|
trombi_user = request.user.trombi_user
|
||||||
)
|
trombi_user.trombi = self.form.cleaned_data["trombi"]
|
||||||
|
else:
|
||||||
|
trombi_user = TrombiUser(
|
||||||
|
user=request.user, trombi=self.form.cleaned_data["trombi"]
|
||||||
|
)
|
||||||
trombi_user.save()
|
trombi_user.save()
|
||||||
self.quick_notif_list += ["qn_success"]
|
self.quick_notif_list += ["qn_success"]
|
||||||
return super(UserTrombiToolsView, self).get(request, *args, **kwargs)
|
return super(UserTrombiToolsView, self).get(request, *args, **kwargs)
|
||||||
@ -309,7 +327,10 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(UserTrombiToolsView, self).get_context_data(**kwargs)
|
kwargs = super(UserTrombiToolsView, self).get_context_data(**kwargs)
|
||||||
kwargs["user"] = self.request.user
|
kwargs["user"] = self.request.user
|
||||||
if not hasattr(self.request.user, "trombi_user"):
|
if not (
|
||||||
|
hasattr(self.request.user, "trombi_user")
|
||||||
|
and self.request.user.trombi_user.trombi
|
||||||
|
):
|
||||||
kwargs["subscribe_form"] = UserTrombiForm()
|
kwargs["subscribe_form"] = UserTrombiForm()
|
||||||
else:
|
else:
|
||||||
kwargs["trombi"] = self.request.user.trombi_user.trombi
|
kwargs["trombi"] = self.request.user.trombi_user.trombi
|
||||||
@ -317,7 +338,7 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
class UserTrombiEditPicturesView(TrombiTabsMixin, UserIsInATrombiMixin, UpdateView):
|
||||||
model = TrombiUser
|
model = TrombiUser
|
||||||
fields = ["profile_pict", "scrub_pict"]
|
fields = ["profile_pict", "scrub_pict"]
|
||||||
template_name = "core/edit.jinja"
|
template_name = "core/edit.jinja"
|
||||||
@ -330,7 +351,9 @@ class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
|||||||
return reverse("trombi:user_tools") + "?qn_success"
|
return reverse("trombi:user_tools") + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
class UserTrombiEditProfileView(
|
||||||
|
QuickNotifMixin, TrombiTabsMixin, UserIsInATrombiMixin, UpdateView
|
||||||
|
):
|
||||||
model = User
|
model = User
|
||||||
form_class = modelform_factory(
|
form_class = modelform_factory(
|
||||||
User,
|
User,
|
||||||
@ -358,7 +381,7 @@ class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
|||||||
return reverse("trombi:user_tools") + "?qn_success"
|
return reverse("trombi:user_tools") + "?qn_success"
|
||||||
|
|
||||||
|
|
||||||
class UserTrombiResetClubMembershipsView(RedirectView):
|
class UserTrombiResetClubMembershipsView(UserIsInATrombiMixin, RedirectView):
|
||||||
permanent = False
|
permanent = False
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user