diff --git a/src/ej_conversations/forms.py b/src/ej_conversations/forms.py index 33ac7e8a1..4cf20afad 100644 --- a/src/ej_conversations/forms.py +++ b/src/ej_conversations/forms.py @@ -59,8 +59,7 @@ def save_all(self, author, board=None, **kwargs): conversation.save() # Save tags on the database - for tag in self.cleaned_data['tags']: - conversation.tags.add(tag) + self.save_m2m() # Save board if board: diff --git a/src/ej_conversations/jinja2/ej/role/conversation-card.jinja2 b/src/ej_conversations/jinja2/ej/role/conversation-card.jinja2 index 781fa3fd6..d99f2479e 100644 --- a/src/ej_conversations/jinja2/ej/role/conversation-card.jinja2 +++ b/src/ej_conversations/jinja2/ej/role/conversation-card.jinja2 @@ -2,10 +2,9 @@
- {% if tags %} - {% for tag in tags %} - {{ tag }} - {% endfor %} + {% if tag %} + {# Only conversation first tag is shown in card to prevent overflow #} + {{ tag }} {% else %} {{ _('Conversation') }} {% endif %} diff --git a/src/ej_conversations/jinja2/ej_conversations/create.jinja2 b/src/ej_conversations/jinja2/ej_conversations/create.jinja2 index 98a737fb4..384e23b71 100644 --- a/src/ej_conversations/jinja2/ej_conversations/create.jinja2 +++ b/src/ej_conversations/jinja2/ej_conversations/create.jinja2 @@ -54,9 +54,6 @@

{{ form.text }}

-
- {{ _('Edit Conversation') }} -
diff --git a/src/ej_conversations/jinja2/ej_conversations/edit.jinja2 b/src/ej_conversations/jinja2/ej_conversations/edit.jinja2 index 2413912d2..7842bffb4 100644 --- a/src/ej_conversations/jinja2/ej_conversations/edit.jinja2 +++ b/src/ej_conversations/jinja2/ej_conversations/edit.jinja2 @@ -19,19 +19,14 @@ - {% if conversation.tags.count() > 0 %} - {% set tags = (conversation.tags.all()[0]|string).title() %} - {% else %} - {% set tags = 'Tags' %} - {% endif %} - -
-
- {{ tags }} -
+
+
+ +
+

diff --git a/src/ej_conversations/jinja2/ej_conversations/moderate.jinja2 b/src/ej_conversations/jinja2/ej_conversations/moderate.jinja2 index dfe3aeba0..ac9f929c2 100644 --- a/src/ej_conversations/jinja2/ej_conversations/moderate.jinja2 +++ b/src/ej_conversations/jinja2/ej_conversations/moderate.jinja2 @@ -7,8 +7,8 @@
- {% if conversation.tags.count() > 0 %} - {{ (conversation.tags.all()[0]|string).title() }} + {% if tags %} + {{ ', '.join(tags) }} {% else %} Tags {% endif %} diff --git a/src/ej_conversations/roles.py b/src/ej_conversations/roles.py index 8d59afab9..2e1eedbef 100644 --- a/src/ej_conversations/roles.py +++ b/src/ej_conversations/roles.py @@ -19,10 +19,11 @@ def conversation_card(conversation, request=None, url=None, **kwargs): user = getattr(request, 'user', None) can_moderate = user.has_perm('ej.can_moderate_conversation', conversation) + tag = conversation.tags.first() # only first is shown in card to prevent overflow return { 'conversation': conversation, 'url': url or conversation.get_absolute_url(), - 'tags': conversation.tags.all(), + 'tag': tag, 'n_comments': conversation.approved_comments.count(), 'n_votes': conversation.vote_count(), 'n_followers': conversation.followers.count(), @@ -41,7 +42,8 @@ def conversation_balloon(conversation, request=None, **kwargs): favorites = models.FavoriteConversation.objects is_authenticated = getattr(user, 'is_authenticated', False) is_favorite = is_authenticated and conversation.is_favorite(user) - tags = list(map(str, conversation.tags.all()[:3])) + tags = list(map(str, conversation.tags.all())) + return { 'conversation': conversation, 'tags': tags, diff --git a/src/ej_conversations/routes/admin.py b/src/ej_conversations/routes/admin.py index b899b3d72..c2aa91803 100644 --- a/src/ej_conversations/routes/admin.py +++ b/src/ej_conversations/routes/admin.py @@ -43,14 +43,16 @@ def get_conversation_edit_context(request, conversation): instance=conversation, ) if form.is_valid(): - form.instance.save() + form.save() return redirect(conversation.get_absolute_url() + 'moderate/') else: form = forms.ConversationForm(instance=conversation) + tags = list(map(str, conversation.tags.all())) return { 'form': form, 'conversation': conversation, + 'tags': ",".join(tags), 'can_promote_conversation': request.user.has_perm('can_publish_promoted'), 'comments': list(conversation.comments.filter(status='pending')), 'manage_stereotypes_url': conversation.get_absolute_url() + 'stereotypes/', @@ -80,10 +82,12 @@ def get_conversation_moderate_context(request, conversation): comment.save() status = request.GET.get('status', 'pending') + tags = list(map(str, conversation.tags.all())) return { 'conversation': conversation, 'comment_status': status, 'edit_url': conversation.get_absolute_url() + 'edit/', 'comments': list(conversation.comments.filter(status=status)), + 'tags': tags, } diff --git a/src/ej_conversations/tests/test_forms.py b/src/ej_conversations/tests/test_forms.py index 80bd6cc2f..895a8dbe9 100644 --- a/src/ej_conversations/tests/test_forms.py +++ b/src/ej_conversations/tests/test_forms.py @@ -141,6 +141,22 @@ def test_conversation_form_save_without_author(self, db): is_promoted=True, ) + def test_edit_conversation_form(self, db, conversation): + conversation.tags.add('oldtag') + form = ConversationForm( + data={'title': 'tiaatle', + 'tags': 'newtag', + 'text': 'description', + 'comments_count': 0, }, + instance=conversation, + ) + + assert form.is_valid() + form.save() + conversation.refresh_from_db() + assert str(conversation.tags.first()) == 'newtag' + assert conversation.tags.count() == 1 + class TestCommentForm: def test_init(self, conversation): diff --git a/src/ej_users/socialbuttons.py b/src/ej_users/socialbuttons.py index 1d2f9348b..93043f1de 100644 --- a/src/ej_users/socialbuttons.py +++ b/src/ej_users/socialbuttons.py @@ -49,7 +49,7 @@ def social_buttons(request): def facebook_button(request): provider = providers.registry.by_id('facebook', request) query = { - 'next': '/conversations/', + 'next': request.GET.get('next', '/conversations/'), 'method': 'oauth2', } url = provider.get_login_url(request, **query) @@ -61,7 +61,7 @@ def facebook_button(request): def twitter_button(request): provider = providers.registry.by_id('twitter', request) query = { - 'next': '/conversations/', + 'next': request.GET.get('next', '/conversations/'), } url = provider.get_login_url(request, **query) return fa_icon('twitter', href=url, id='twitter-button', aria_label="Twitter Icon", @@ -72,7 +72,7 @@ def twitter_button(request): def github_button(request): provider = providers.registry.by_id('github', request) query = { - 'next': '/conversations/', + 'next': request.GET.get('next', '/conversations/'), } url = provider.get_login_url(request, **query) return fa_icon('github', href=url, id='github-button') @@ -82,7 +82,7 @@ def github_button(request): def google_button(request): provider = providers.registry.by_id('google', request) query = { - 'next': '/conversations/', + 'next': request.GET.get('next', '/conversations/'), } url = provider.get_login_url(request, **query) return fa_icon('google', href=url, id='google-button', aria_label="Google Icon",