Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6536] Kl 2022 10 label filter #4572

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% has_or_would_have_perm 'meinberlin_budgeting.add_proposal' request.user module as propose_allowed %}
{% if propose_allowed %}
<a href="{% url 'meinberlin_budgeting:proposal-create' module_slug=module.slug %}" class="btn btn--primary btn--full u-spacer-bottom btn--huge">
{% trans 'Submit proposal' %}
{% translate 'Submit proposal' %}
</a>
{% endif %}
{% if module.blueprint_type == 'PB3' %}
Expand All @@ -26,9 +26,9 @@
<form action="{{ request.path }}" method="post">
{% csrf_token %}
<div class="input-group input-group-lg">
<label for="id_token" class="visually-hidden-focusable">{% trans 'Voting token form fields' %}</label>
<label for="id_token" class="visually-hidden-focusable">{% translate 'Voting token form fields' %}</label>
{{ token_form.token }}
<button type="submit" class="btn btn--primary">{% trans 'Enter code' %}</button>
<button type="submit" class="btn btn--primary">{% translate 'Enter code' %}</button>
</div>
{% if token_form.token.errors %}
<div role="alert">{{ token_form.token.errors }}</div>
Expand All @@ -50,8 +50,8 @@
<div class="map-list__controls">
<div class="container">
<div class="leaflet-control-zoom leaflet-bar leaflet-control">
<a class="leaflet-control-zoom-in" id="zoom-in" href="#" title="{% trans 'Zoom in' %}">+</a>
<a class="leaflet-control-zoom-out leaflet-disabled" id="zoom-out" href="#" title="{% trans 'Zoom out' %}">-</a>
<a class="leaflet-control-zoom-in" id="zoom-in" href="#" title="{% translate 'Zoom in' %}">+</a>
<a class="leaflet-control-zoom-out leaflet-disabled" id="zoom-out" href="#" title="{% translate 'Zoom out' %}">-</a>
</div>
</div>
</div>
Expand All @@ -72,11 +72,11 @@
{% if object_list.count > 0 %}
<ul class="u-list-reset">
{% for object in object_list %}
{% include "meinberlin_contrib/includes/proposal_list_item.html" with object=object %}
{% include "meinberlin_ideas/includes/idea_list_item.html" with object=object %}
{% endfor %}
</ul>
{% else %}
{% trans "Nothing to show" %}
{% translate "Nothing to show" %}
{% endif %}

{% include "meinberlin_contrib/includes/pagination.html" %}
Expand Down
4 changes: 3 additions & 1 deletion meinberlin/apps/budgeting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from adhocracy4.categories import filters as category_filters
from adhocracy4.exports.views import DashboardExportView
from adhocracy4.filters import filters as a4_filters
from adhocracy4.labels import filters as label_filters
from adhocracy4.projects.mixins import DisplayProjectOrModuleMixin
from meinberlin.apps.ideas import views as idea_views
from meinberlin.apps.projects.views import ArchivedWidget
Expand All @@ -29,6 +30,7 @@ class ProposalFilterSet(a4_filters.DefaultsFilterSet):
'is_archived': 'false'
}
category = category_filters.CategoryFilter()
labels = label_filters.LabelFilter()
ordering = a4_filters.DynamicChoicesOrderingFilter(
choices=get_ordering_choices
)
Expand All @@ -38,7 +40,7 @@ class ProposalFilterSet(a4_filters.DefaultsFilterSet):

class Meta:
model = models.Proposal
fields = ['category', 'is_archived']
fields = ['category', 'labels', 'is_archived']


class ProposalListView(idea_views.AbstractIdeaListView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,9 @@ <h2 id="cl-list_item">List Item</h2>
</div>

<h3 class="list-item__title"><a href="#cl-list_item">My Idea</a></h3>
<div class="list-item__labels">Label</div>
<div class="list-item__labels">
<span class="label label--big">This is a category</span>
</div>
<span class="list-item__author">Author</span>
<time class="list-item__date">Date 2018</time>
</li>
Expand All @@ -1495,7 +1497,12 @@ <h3 class="list-item__title"><a href="#cl-list_item">My Idea</a></h3>
</div>

<h3 class="list-item__title"><a href="#cl-list_item">My Idea 2</a></h3>
<div class="list-item__labels">Label</div>
<div class="list-item__labels">
<span class="label label--big">
<i class="fas fa-map-marker-alt" aria-hidden="true"></i>
This is a point string
</span>
</div>
<span class="list-item__author">Author</span>
<time class="list-item__date">Date 2018</time>
</li>
Expand Down Expand Up @@ -1523,7 +1530,12 @@ <h3 class="list-item__title">
</a>
</h3>
<div class="list-item__labels">
<span class="label label--big">This is a category</span>
<span class="label label--big">Only 3</span>
<span class="label label--big">labels</span>
<span class="label label--big">displayed</span>
<span class="u-spacer-left-half">
<a href="" class="list-item__link">3 More</a>
</span>
</div>
<span class="list-item__author">
admin
Expand Down

This file was deleted.

47 changes: 47 additions & 0 deletions meinberlin/apps/ideas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ckeditor.fields import RichTextField
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import intcomma
from django.db import models
from django.db.models.functions import Concat
from django.db.models.functions import ExtractYear
Expand All @@ -19,6 +20,8 @@
from meinberlin.apps.moderatorfeedback.models import Moderateable
from meinberlin.apps.moderatorremark import models as remark_models

BADGES_LIMIT = 3


class IdeaQuerySet(query.RateableQuerySet, query.CommentableQuerySet):

Expand Down Expand Up @@ -104,6 +107,50 @@ def remark(self):
item_object_id=self.id
).first()

@property
khamui marked this conversation as resolved.
Show resolved Hide resolved
def item_badges(self):
"""List all badges an idea item can have."""
labels = []
if hasattr(self, 'moderator_feedback') and self.moderator_feedback:
labels.append(
['moderator_feedback',
self.get_moderator_feedback_display(),
self.moderator_feedback]
)
if hasattr(self, 'budget') and self.budget > 0:
labels.append(
['budget',
intcomma(self.budget) + '€']
)
if hasattr(self, 'point_label') and self.point_label:
labels.append(
['point_label',
self.point_label]
)
if hasattr(self, 'category') and self.category:
labels.append(
['category',
self.category]
)
if hasattr(self, 'labels') and self.labels:
for label in self.labels.all():
labels.append(
['label',
label.name]
)
return labels

@property
def item_badges_for_list(self):
return self.item_badges[:BADGES_LIMIT]

@property
def additional_item_badges_for_list_count(self):
count = 0
if len(self.item_badges) > BADGES_LIMIT:
count = len(self.item_badges) - BADGES_LIMIT
return count

class Meta:
abstract = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% has_or_would_have_perm 'meinberlin_ideas.add_idea' request.user module as propose_allowed %}
{% if propose_allowed %}
<a href="{% url 'meinberlin_ideas:idea-create' module_slug=module.slug %}" class="btn btn--primary btn--full u-spacer-bottom btn--huge">
{% trans 'Submit idea' %}
{% translate 'Submit idea' %}
</a>
{% endif %}
{% endblock %}
Expand All @@ -26,7 +26,7 @@
{% endfor %}
</ul>
{% else %}
{% trans "Nothing to show" %}
{% translate "Nothing to show" %}
{% endif %}

{% include "meinberlin_contrib/includes/pagination.html" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
{% spaceless %}
{% if object|has_feature:"rate" %}
<span class="rating">
<span class="rating-button rating-up is-read-only" title="{% trans 'Positive Ratings' %}">
<i class="fa fa-chevron-up" aria-label="{% trans 'Positive Ratings' %}"></i>
<span class="rating-button rating-up is-read-only" title="{% translate 'Positive Ratings' %}">
<i class="fa fa-chevron-up" aria-label="{% translate 'Positive Ratings' %}"></i>
{{ object.positive_rating_count }}
</span>
<span class="rating-button rating-down is-read-only" title="{% trans 'Negative Ratings' %}">
<i class="fa fa-chevron-down" aria-label="{% trans 'Negative Ratings' %}"></i>
<span class="rating-button rating-down is-read-only" title="{% translate 'Negative Ratings' %}">
<i class="fa fa-chevron-down" aria-label="{% translate 'Negative Ratings' %}"></i>
{{ object.negative_rating_count }}
</span>
</span>
{% endif %}
<span title="{% trans 'Comments' %}" class="list-item__comments">
<i class="far fa-comment" aria-label="{% trans 'Comments' %}"></i>
<span title="{% translate 'Comments' %}" class="list-item__comments">
<i class="far fa-comment" aria-label="{% translate 'Comments' %}"></i>
{{ object.comment_count }}
</span>
{% endspaceless %}
Expand All @@ -27,22 +27,31 @@ <h3 class="list-item__title">
</a>
</h3>
<div class="list-item__labels">
{% if object.category %}
<span class="label label--big">{{ object.category }}</span>
{% endif %}
{% if object.moderator_feedback %}
<span class="label label--big label--{{ object.moderator_feedback|classify|lower }} list-item__label--moderator-feedback">
{{ object.get_moderator_feedback_display }}
{% for badge in object.item_badges_for_list %}
<span class="label label--big {% if badge.0 == 'moderator_feedback' %}label--{{badge.2|classify|lower }}{% endif %}">
{% if badge.0 == 'point_label' %}
<i class="fas fa-map-marker-alt" aria-hidden="true"></i>
{% endif %}
{{ badge.1 }}
</span>
{% endfor %}
{% if object.additional_item_badges_for_list_count > 0 %}
<span class="u-spacer-left-half">
<a href="{{ object.get_absolute_url }}" class="list-item__link">
{% blocktranslate with counter=object.additional_item_badges_for_list_count %}{{ counter }} More{% endblocktranslate %}
fuzzylogic2000 marked this conversation as resolved.
Show resolved Hide resolved
</a>
</span>
{% endif %}
</div>

<span class="list-item__author">
{{ object.creator.username }}
</span>
{% if object.modified %}
{% trans 'updated on ' %}{% html_date object.modified class='list-item__date' %}
{% else %}
{% trans 'created on ' %}{% html_date object.created class='list-item__date' %}
{% endif %}
{% block creator_info %}
<span class="list-item__author">
{{ object.creator.username }}
</span>
{% if object.modified %}
{% translate 'updated on ' %}{% html_date object.modified class='list-item__date' %}
{% else %}
{% translate 'created on ' %}{% html_date object.created class='list-item__date' %}
{% endif %}
{% endblock %}
</li>
4 changes: 3 additions & 1 deletion meinberlin/apps/ideas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from adhocracy4.filters import views as filter_views
from adhocracy4.filters import widgets as filters_widgets
from adhocracy4.filters.filters import FreeTextFilter
from adhocracy4.labels import filters as label_filters
from adhocracy4.projects.mixins import DisplayProjectOrModuleMixin
from adhocracy4.projects.mixins import ProjectMixin
from adhocracy4.rules import mixins as rules_mixins
Expand Down Expand Up @@ -43,6 +44,7 @@ class IdeaFilterSet(a4_filters.DefaultsFilterSet):
'ordering': '-created'
}
category = category_filters.CategoryFilter()
labels = label_filters.LabelFilter()
ordering = a4_filters.DynamicChoicesOrderingFilter(
choices=get_ordering_choices
)
Expand All @@ -53,7 +55,7 @@ class IdeaFilterSet(a4_filters.DefaultsFilterSet):

class Meta:
model = models.Idea
fields = ['search', 'category']
fields = ['search', 'labels', 'category']


class AbstractIdeaListView(ProjectMixin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% has_or_would_have_perm 'meinberlin_kiezkasse.add_proposal' request.user module as propose_allowed %}
{% if propose_allowed %}
<a href="{% url 'meinberlin_kiezkasse:proposal-create' module_slug=module.slug %}" class="btn btn--primary btn--full u-spacer-bottom btn--huge">
{% trans 'Submit proposal' %}
{% translate 'Submit proposal' %}
</a>
{% endif %}
{% endblock %}
Expand All @@ -31,8 +31,8 @@
<div class="map-list__controls">
<div class="container">
<div class="leaflet-control-zoom leaflet-bar leaflet-control">
<a class="leaflet-control-zoom-in" id="zoom-in" href="#" title="{% trans 'Zoom in' %}">+</a>
<a class="leaflet-control-zoom-out leaflet-disabled" id="zoom-out" href="#" title="{% trans 'Zoom out' %}">-</a>
<a class="leaflet-control-zoom-in" id="zoom-in" href="#" title="{% translate 'Zoom in' %}">+</a>
<a class="leaflet-control-zoom-out leaflet-disabled" id="zoom-out" href="#" title="{% translate 'Zoom out' %}">-</a>
</div>
</div>
</div>
Expand All @@ -45,11 +45,11 @@
{% if object_list.count > 0 %}
<ul class="u-list-reset">
{% for object in object_list %}
{% include "meinberlin_contrib/includes/proposal_list_item.html" with object=object %}
{% include "meinberlin_ideas/includes/idea_list_item.html" with object=object %}
{% endfor %}
</ul>
{% else %}
{% trans "Nothing to show" %}
{% translate "Nothing to show" %}
{% endif %}

{% include "meinberlin_contrib/includes/pagination.html" %}
Expand Down
Loading