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

Only show those tags that correspond with filtered posts. #580

Merged
merged 1 commit into from
Aug 29, 2023
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
6 changes: 3 additions & 3 deletions community/templates/_tags_filtering_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</div>
<div class="ma-5" style="margin-top:15px;">
<label>
<input name="active" type="hidden" value="{{ active|yesno:'false,true' }}">
<input id="show-active" type="checkbox" {% if not active %}checked{% endif %} />
<input name="active" type="hidden" value="{{ active|yesno:'true,false' }}">
<input id="show-active" type="checkbox" {% if active %}checked{% endif %} />
{% trans 'Mostrar solo ofertas activas' %}
</label>
</div>
Expand All @@ -25,7 +25,7 @@ <h4 class="list-group-item-heading">{% trans 'Filtrar por etiqueta' %} <button t
</header>
<article class="list-group-item" style="padding:30px;">
<div class="row">
{% for tag in tags %}
{% for tag in usefultags %}
<select name="tag_{{ tag.slug }}" id="tag_{{ tag.slug }}" class="hidden">
<option value=""></option>
<option value="1" {% if tag.slug in included %}selected{% endif %}></option>
Expand Down
28 changes: 28 additions & 0 deletions joboffers/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,34 @@ def test_joboffer_list_view_render_the_joboffer_that_contains_the_given_tag(clie
assert response.context_data['object_list'][0] == first_joboffer


@pytest.mark.django_db
def test_joboffer_list_view_taglist_all_offers(publisher_client):
"""Verify which tags are shown on a mix of active/expired offers when showing all of them."""
client = publisher_client
JobOfferFactory.create(
state=OfferState.ACTIVE, title="First Joboffer", tags=["tag1", "tag2"])
JobOfferFactory.create(
state=OfferState.EXPIRED, title="Second Joboffer", tags=["tag2", "tag3"])

response = client.get(reverse(LIST_URL), {'active': 'false'})

assert sorted(t.slug for t in response.context_data['usefultags']) == ["tag1", "tag2", "tag3"]


@pytest.mark.django_db
def test_joboffer_list_view_taglist_only_active_offers(publisher_client):
"""Verify which tags are shown on a mix of active/expired offers when showing active only."""
client = publisher_client
JobOfferFactory.create(
state=OfferState.ACTIVE, title="First Joboffer", tags=["tag1", "tag2"])
JobOfferFactory.create(
state=OfferState.EXPIRED, title="Second Joboffer", tags=["tag2", "tag3"])

response = client.get(reverse(LIST_URL), {'active': 'true'})

assert sorted(t.slug for t in response.context_data['usefultags']) == ["tag1", "tag2"]


@pytest.mark.django_db
def test_joboffer_list_view_count(client, joboffers_list):
"""
Expand Down
103 changes: 57 additions & 46 deletions joboffers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,32 @@
from django.views.generic import ListView, View, FormView
from django.views.generic.detail import DetailView, SingleObjectMixin
from django.views.generic.edit import CreateView, UpdateView
from taggit.models import Tag

from community.views import FilterableList
from pycompanies.models import UserCompanyProfile
from .constants import (
ACTION_BUTTONS,
APPROVED_MAIL_SUBJECT,
APPROVED_MAIL_BODY,
CODE_ANALYTICS,
CODE_APPROVE,
CODE_CREATE,
CODE_DEACTIVATE,
CODE_EDIT,
CODE_HISTORY,
CODE_REACTIVATE,
CODE_REJECT,
CODE_REQUEST_MODERATION,
PUBLISHER_FAILED_ERROR,
REACTIVATED_MAIL_BODY,
REACTIVATED_MAIL_SUBJECT,
REJECTED_MAIL_SUBJECT,
REJECTED_MAIL_BODY,
STATE_LABEL_CLASSES,
TELEGRAM_APPROVED_MESSAGE,
TELEGRAM_MODERATION_MESSAGE,
TELEGRAM_REJECT_MESSAGE
ACTION_BUTTONS,
APPROVED_MAIL_SUBJECT,
APPROVED_MAIL_BODY,
CODE_ANALYTICS,
CODE_APPROVE,
CODE_CREATE,
CODE_DEACTIVATE,
CODE_EDIT,
CODE_HISTORY,
CODE_REACTIVATE,
CODE_REJECT,
CODE_REQUEST_MODERATION,
PUBLISHER_FAILED_ERROR,
REACTIVATED_MAIL_BODY,
REACTIVATED_MAIL_SUBJECT,
REJECTED_MAIL_SUBJECT,
REJECTED_MAIL_BODY,
STATE_LABEL_CLASSES,
TELEGRAM_APPROVED_MESSAGE,
TELEGRAM_MODERATION_MESSAGE,
TELEGRAM_REJECT_MESSAGE
)
from .forms import JobOfferForm, JobOfferCommentForm
from .joboffer_actions import get_valid_actions
Expand All @@ -48,9 +49,7 @@


class JobOfferObjectMixin(SingleObjectMixin):
"""
Adds permission checking to the matching joboffer
"""
"""Add permission checking to the matching joboffer."""

action_code: str

Expand Down Expand Up @@ -253,16 +252,16 @@ def form_valid(self, form):

subject = REJECTED_MAIL_SUBJECT
body = REJECTED_MAIL_BODY.format(
reason=offer_comment.get_comment_type_display(),
text=offer_comment.text,
title=offer.title
reason=offer_comment.get_comment_type_display(),
text=offer_comment.text,
title=offer.title
)

send_mail_to_publishers(offer, subject, body)

moderators_message = TELEGRAM_REJECT_MESSAGE.format(
offer_url=offer.get_full_url(),
username=user.username
offer_url=offer.get_full_url(),
username=user.username
)

send_notification_to_moderators(moderators_message)
Expand Down Expand Up @@ -300,14 +299,14 @@ def update_object(self, offer):
user = self.request.user

send_mail_to_publishers(
offer,
APPROVED_MAIL_SUBJECT,
APPROVED_MAIL_BODY.format(title=offer.title)
offer,
APPROVED_MAIL_SUBJECT,
APPROVED_MAIL_BODY.format(title=offer.title)
)

moderators_message = TELEGRAM_APPROVED_MESSAGE.format(
offer_url=offer.get_full_url(),
username=user.username
offer_url=offer.get_full_url(),
username=user.username
)

send_notification_to_moderators(moderators_message)
Expand All @@ -316,9 +315,9 @@ def update_object(self, offer):

for publisher_failed in publishers_failed:
messages.add_message(
self.request,
messages.ERROR,
PUBLISHER_FAILED_ERROR.format(publisher=publisher_failed)
self.request,
messages.ERROR,
PUBLISHER_FAILED_ERROR.format(publisher=publisher_failed)
)


Expand All @@ -332,9 +331,9 @@ def update_object(self, offer):
offer.save()

send_mail_to_publishers(
offer,
REACTIVATED_MAIL_SUBJECT,
REACTIVATED_MAIL_BODY.format(title=offer.title)
offer,
REACTIVATED_MAIL_SUBJECT,
REACTIVATED_MAIL_BODY.format(title=offer.title)
)


Expand All @@ -360,9 +359,7 @@ def update_object(self, offer):
offer.state = OfferState.MODERATION
offer.save()

moderators_message = TELEGRAM_MODERATION_MESSAGE.format(
offer_url=offer.get_full_url()
)
moderators_message = TELEGRAM_MODERATION_MESSAGE.format(offer_url=offer.get_full_url())

send_notification_to_moderators(moderators_message)

Expand Down Expand Up @@ -421,7 +418,8 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

if self.request.GET.get('active') == 'false':
user_requested_active = self.request.GET.get('active') == 'true'
if user_requested_active:
context['active'] = True
else:
context['active'] = False
Expand All @@ -431,6 +429,15 @@ def get_context_data(self, **kwargs):

context['user'] = self.request.user

# if only shown active job offers, get the tags considering only those offers (otherwise
# just use all the tags as already calculated by the taggit module)
if user_requested_active:
active_jobffers_ids = {
jo.id for jo in JobOffer.objects.filter(state=OfferState.ACTIVE)}
context["usefultags"] = Tag.objects.filter(joboffer__in=active_jobffers_ids)
else:
context["usefultags"] = context["tags"]

user_company = UserCompanyProfile.objects.for_user(user=self.request.user)
if user_company:
context['own_company'] = user_company.company
Expand Down Expand Up @@ -520,8 +527,12 @@ def get(self, request, **kwargs):
writer = csv.writer(response)

writer.writerow([
_('Fecha'), _('Hora'), _('ID. Oferta'), _('Titulo de la Oferta'), _('Código de Evento'),
_('Evento')
_('Fecha'),
_('Hora'),
_('ID. Oferta'),
_('Titulo de la Oferta'),
_('Código de Evento'),
_('Evento')
])

writer.writerows(data)
Expand Down
2 changes: 2 additions & 0 deletions pyarweb/settings/development/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@

# BASE_URL to use in any notification that might require them
BASE_URL = os.environ.get('BASE_URL', 'http://localhost:8000')

DISCOURSE_HOST = "testdiscourse.com"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esto no parece ser referenciado en ninguna otra parte del código, puede ser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sí, en joboffers/publishers/discourse/__init__.py

Loading