trombi: fix trombi tools if user has a trombi profile but no trombi linked

This commit is contained in:
Antoine Bartuccio 2019-09-29 11:52:48 +02:00
parent fcb3035b67
commit 35d9c05abf
Signed by: klmp200
GPG Key ID: E7245548C53F904B
2 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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