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 @@ ...@@ -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
......
...@@ -313,9 +313,13 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView): ...@@ -313,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)
...@@ -323,7 +327,10 @@ class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView): ...@@ -323,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
......
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