Verified Commit 35d9c05a authored by Sli's avatar Sli
Browse files

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

parent fcb3035b
Pipeline #2037 passed with stage
in 45 minutes and 12 seconds
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment