mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 10:34:21 +00:00
trombi: fix some 500 errors when accessing page without being in a trombi
This commit is contained in:
parent
b7db969f08
commit
fcb3035b67
@ -40,5 +40,3 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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,6 +59,7 @@ 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")}
|
||||||
)
|
)
|
||||||
|
if hasattr(self.request.user, "trombi_user"):
|
||||||
tab_list.append(
|
tab_list.append(
|
||||||
{
|
{
|
||||||
"url": reverse("trombi:profile"),
|
"url": reverse("trombi:profile"),
|
||||||
@ -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
|
||||||
@ -317,7 +331,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 +344,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 +374,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