mirror of
https://github.com/ae-utbm/sith.git
synced 2024-10-31 19:38:04 +00:00
trombi: fix trombi tools if user has a trombi profile but no trombi linked
This commit is contained in:
parent
fcb3035b67
commit
35d9c05abf
@ -12,7 +12,8 @@
|
||||
{{ subscribe_form.as_p() }}
|
||||
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
{% if trombi %}
|
||||
<p>{% trans trombi = user.trombi_user.trombi %}You are subscribed to the Trombi {{ trombi }}{% endtrans %}</p>
|
||||
<hr>
|
||||
{% set can_comment = trombi.subscription_deadline < date.today() and
|
||||
|
@ -313,6 +313,10 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.form = UserTrombiForm(request.POST)
|
||||
if self.form.is_valid():
|
||||
if hasattr(request.user, "trombi_user"):
|
||||
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"]
|
||||
)
|
||||
@ -323,7 +327,10 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserTrombiToolsView, self).get_context_data(**kwargs)
|
||||
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()
|
||||
else:
|
||||
kwargs["trombi"] = self.request.user.trombi_user.trombi
|
||||
|
Loading…
Reference in New Issue
Block a user