- {% for tag in tags %} + {% for tag in usefultags %} diff --git a/joboffers/tests/test_views.py b/joboffers/tests/test_views.py index bcc61bc..330085c 100644 --- a/joboffers/tests/test_views.py +++ b/joboffers/tests/test_views.py @@ -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): """ diff --git a/joboffers/views.py b/joboffers/views.py index 32a41e4..6c7772d 100644 --- a/joboffers/views.py +++ b/joboffers/views.py @@ -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 @@ -48,9 +49,7 @@ class JobOfferObjectMixin(SingleObjectMixin): - """ - Adds permission checking to the matching joboffer - """ + """Add permission checking to the matching joboffer.""" action_code: str @@ -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) @@ -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) @@ -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) ) @@ -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) ) @@ -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) @@ -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 @@ -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 @@ -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) diff --git a/pyarweb/settings/development/__init__.py b/pyarweb/settings/development/__init__.py index f20d8c1..b2f7b20 100644 --- a/pyarweb/settings/development/__init__.py +++ b/pyarweb/settings/development/__init__.py @@ -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"