Skip to content

Commit

Permalink
Fixing tag issues in conversation card and edit conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiola-m committed Nov 28, 2018
1 parent 90c3dc1 commit e3a9926
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/ej_conversations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def save_all(self, author, board=None, **kwargs):
for k, v in kwargs.items():
setattr(conversation, k, v)
conversation.save()

print(self.cleaned_data['tags'])
# Save tags on the database
tags = conversation.tags.all()
if tags:
conversation.tags = None
for tag in self.cleaned_data['tags']:
conversation.tags.add(tag)

Expand Down
7 changes: 3 additions & 4 deletions src/ej_conversations/jinja2/ej/role/conversation-card.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
<div class="ConversationCard">
<div class="ConversationTags">
<i class="fa fa-tags"></i>
{% 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 %}
Expand Down
3 changes: 0 additions & 3 deletions src/ej_conversations/jinja2/ej_conversations/create.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@

<p>{{ form.text }}</p>

<div class="Conversation-edit">
<b>{{ _('Edit Conversation') }}</b>
</div>
</div>
<div class="ConversationDetail-arrow"></div>
</div>
Expand Down
15 changes: 5 additions & 10 deletions src/ej_conversations/jinja2/ej_conversations/edit.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
</span>
</div>

{% if conversation.tags.count() > 0 %}
{% set tags = (conversation.tags.all()[0]|string).title() %}
{% else %}
{% set tags = 'Tags' %}
{% endif %}

<input type="hidden" name="tags" value="{{ tags }}" />

<div class="ConversationDetail">
<div class="ConversationDetail-banner">
<div class="ConversationTags"><i class="fa fa-tags"></i>
{{ tags }}
</div>
<div class="ConversationTags">
<div class="ConversationField">
<i class="fa fa-tags"></i><input name="tags" value="{{ tags }}" />
</div>
</div>

<p><textarea onfocus="this.style.height = (this.scrollHeight) + 'px'" onkeyup="this.style.height = (this.scrollHeight) + 'px'" class="Conversation-edit-field" name="text" required id="id_text">{{ conversation.text }}</textarea></p>

Expand Down
3 changes: 2 additions & 1 deletion src/ej_conversations/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion src/ej_conversations/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down

0 comments on commit e3a9926

Please sign in to comment.