Skip to content

Commit

Permalink
#701: add a 'Unassign contract' workflow to Source, available to supe…
Browse files Browse the repository at this point in the history
…rusers
  • Loading branch information
Fasand committed Dec 15, 2024
1 parent 2c02173 commit d48d3e1
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 35 deletions.
1 change: 1 addition & 0 deletions Seeder/contracts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
path('autocomplete', ContractAutocomplete.as_view(), name='autocomplete'),
path('<int:pk>/create', Create.as_view(), name='create'),
path('<int:pk>/assign', Assign.as_view(), name='assign'),
path('<int:pk>/unassign', Unassign.as_view(), name='unassign'),
path('<int:pk>/edit', Edit.as_view(), name='edit'),
path('<int:pk>/history', History.as_view(), name='history'),
path('', ListView.as_view(), name='list'),
Expand Down
40 changes: 39 additions & 1 deletion Seeder/contracts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def get_queryset(self):
return models.Contract.objects.none()
# Annotate as strings so we can use icontains
qs = models.Contract.objects.all().annotate(
contract_number_s=Cast("contract_number", output_field=CharField()),
contract_number_s=Cast(
"contract_number", output_field=CharField()),
year_s=Cast("year", output_field=CharField())
).order_by("contract_number", "year")
# Allow searching by "{contract_number} / {year}"
Expand Down Expand Up @@ -108,6 +109,43 @@ def form_valid(self, form):
return HttpResponseRedirect(contract.get_absolute_url())


class Unassign(LoginMixin, FormView, MessageView, ObjectMixinFixed):
"""
Unassign a contract from source
Defined with Source as the model to stay consistent with Assign
"""
form_class = forms.AssignForm
template_name = "add_form.html"
title = _("Unassign contract")
view_name = "contracts"
model = Source

def get_form(self, form_class=None):
""" Retrieve all of Source's assigned contracts """
form = super().get_form(form_class)
contract = form.fields['contract']
contract.queryset = self.get_object().contract_set.all()
if not contract.queryset.exists():
self.add_message(self.request, messages.ERROR, _(
"The source doesn't have any contracts assigned."))
contract.disabled = True
return form

def form_valid(self, form):
""" Remove selected contract and change Source state if necessary """
contract = form.cleaned_data['contract']
contract.sources.remove(self.object)
# If no assigned contracts remain, update the state
if self.object.contract_set.count() == 0:
self.add_message(_("All contracts have been unassigned so the "
"source state was changed to '%(state)s'") % {
"state": _('Archiving without publisher consent')},
level=messages.WARNING)
self.object.state = source_constants.STATE_WITHOUT_PUBLISHER
self.object.save()
return HttpResponseRedirect(self.object.get_absolute_url())


class Edit(ContractView, EditView):
form_class = forms.ContractForm

Expand Down
51 changes: 34 additions & 17 deletions Seeder/locale/cs/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Seeder\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-15 15:19+0000\n"
"POT-Creation-Date: 2024-12-15 15:59+0000\n"
"PO-Revision-Date: 2018-04-16 13:40+0200\n"
"Last-Translator: mariehaskovcova <[email protected]>, 2017\n"
"Language-Team: Czech (https://www.transifex.com/webarchivecz/teams/43032/"
Expand Down Expand Up @@ -161,7 +161,7 @@ msgstr "Komentář"
#: harvests/templates/harvest.html:110
#: harvests/templates/topic_collection.html:112
#: publishers/templates/publisher.html:39 qa/templates/detail.html:41
#: source/templates/source.html:204 voting/templates/voting_round.html:118
#: source/templates/source.html:207 voting/templates/voting_round.html:118
#: www/templates/news_admin_detail.html:90
msgid "Comments"
msgstr "Komentáře"
Expand Down Expand Up @@ -354,12 +354,12 @@ msgid "Delete"
msgstr "Smazat"

#: contracts/templates/contract.html:131 source/templates/edit_seed.html:16
#: source/templates/source.html:214
#: source/templates/source.html:217
msgid "Proceed with deletion?"
msgstr "Pokračovat se smazáním?"

#: contracts/templates/contract.html:140 harvests/templates/calendar.html:50
#: source/templates/edit_seed.html:28 source/templates/source.html:225
#: source/templates/edit_seed.html:28 source/templates/source.html:228
#: templates/base.html:204
msgid "Close"
msgstr "Zavřít"
Expand Down Expand Up @@ -403,32 +403,53 @@ msgstr ""
msgid "Send"
msgstr "Odeslat"

#: contracts/views.py:64
#: contracts/views.py:65
msgid "Add contract"
msgstr "Přidat smlouvu"

#: contracts/views.py:86
#: contracts/views.py:87
msgid "Assign contract"
msgstr "Přiřadit smlouvu"

#: contracts/views.py:120
#: contracts/views.py:119 source/templates/source.html:202
msgid "Unassign contract"
msgstr "Odpojit smlouvu"

#: contracts/views.py:130
msgid "The source doesn't have any contracts assigned."
msgstr "Zdroj nemá přiřazené žádné smlouvy"

#: contracts/views.py:140
#, python-format
msgid ""
"All contracts have been unassigned so the source state was changed to "
"'%(state)s'"
msgstr ""
"Všechny smlouvy byly odpojeny, stav zdroje byl tedy nastaven na "
"'%(state)s'"

#: contracts/views.py:142 source/constants.py:29
msgid "Archiving without publisher consent"
msgstr "Archivován bez smlouvy"

#: contracts/views.py:158
msgid "Contract number assigned."
msgstr "Smlouvě bylo přiřazeno číslo."

#: contracts/views.py:134 source/templates/source.html:193
#: contracts/views.py:172 source/templates/source.html:193
#: templates/base.html:100
msgid "Contracts"
msgstr "Smlouvy"

#: contracts/views.py:141
#: contracts/views.py:179
msgid "Schedule emails"
msgstr "Naplánování e-mailů"

#: contracts/views.py:207
#: contracts/views.py:245
msgid "Can't delete contract with number"
msgstr "Nelze smazat smlouvu s číslem"

#: contracts/views.py:215
#: contracts/views.py:253
msgid "Contract deleted."
msgstr "Smlouva smazána"

Expand Down Expand Up @@ -1185,10 +1206,6 @@ msgstr "Odmítnuto Webarchivem"
msgid "Archiving accepted"
msgstr "Archivován"

#: source/constants.py:29
msgid "Archiving without publisher consent"
msgstr "Archivován bez smlouvy"

#: source/constants.py:30
msgid "Declined by publisher"
msgstr "Odmítnuto vydavatelem"
Expand Down Expand Up @@ -1427,7 +1444,7 @@ msgstr "WA-KAT"
msgid "QA check"
msgstr "Provedení kontroly kvality"

#: source/templates/source.html:178 source/templates/source.html:221
#: source/templates/source.html:178 source/templates/source.html:224
msgid "Deactivate"
msgstr "Deaktivovat"

Expand All @@ -1451,7 +1468,7 @@ msgstr "Vytvořit"
msgid "Assign"
msgstr "Přiřadit"

#: source/templates/source.html:217
#: source/templates/source.html:220
msgid "If you proceed it will be very hard to reactivate this source."
msgstr "Pokud budete pokračovat, bude velmi těžké zdroj znovu aktivovat."

Expand Down
51 changes: 34 additions & 17 deletions Seeder/locale/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Seeder\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-15 15:19+0000\n"
"POT-Creation-Date: 2024-12-15 15:59+0000\n"
"PO-Revision-Date: 2017-11-07 12:38+0100\n"
"Last-Translator: Visgean Skeloru <[email protected]>, 2017\n"
"Language-Team: English (United States) (https://www.transifex.com/"
Expand Down Expand Up @@ -162,7 +162,7 @@ msgstr "Comment"
#: harvests/templates/harvest.html:110
#: harvests/templates/topic_collection.html:112
#: publishers/templates/publisher.html:39 qa/templates/detail.html:41
#: source/templates/source.html:204 voting/templates/voting_round.html:118
#: source/templates/source.html:207 voting/templates/voting_round.html:118
#: www/templates/news_admin_detail.html:90
msgid "Comments"
msgstr "Comments"
Expand Down Expand Up @@ -355,12 +355,12 @@ msgid "Delete"
msgstr "Delete"

#: contracts/templates/contract.html:131 source/templates/edit_seed.html:16
#: source/templates/source.html:214
#: source/templates/source.html:217
msgid "Proceed with deletion?"
msgstr "Proceed with deletion?"

#: contracts/templates/contract.html:140 harvests/templates/calendar.html:50
#: source/templates/edit_seed.html:28 source/templates/source.html:225
#: source/templates/edit_seed.html:28 source/templates/source.html:228
#: templates/base.html:204
msgid "Close"
msgstr "Close"
Expand Down Expand Up @@ -406,32 +406,53 @@ msgstr ""
msgid "Send"
msgstr "Send"

#: contracts/views.py:64
#: contracts/views.py:65
msgid "Add contract"
msgstr "Add contract"

#: contracts/views.py:86
#: contracts/views.py:87
msgid "Assign contract"
msgstr "Assign contract"

#: contracts/views.py:120
#: contracts/views.py:119 source/templates/source.html:202
msgid "Unassign contract"
msgstr "Unassign contract"

#: contracts/views.py:130
msgid "The source doesn't have any contracts assigned."
msgstr "The source doesn't have any contracts assigned."

#: contracts/views.py:140
#, python-format
msgid ""
"All contracts have been unassigned so the source state was changed to "
"'%(state)s'"
msgstr ""
"All contracts have been unassigned so the source state was changed to "
"'%(state)s'"

#: contracts/views.py:142 source/constants.py:29
msgid "Archiving without publisher consent"
msgstr "Archiving without publisher consent"

#: contracts/views.py:158
msgid "Contract number assigned."
msgstr "Contract number assigned."

#: contracts/views.py:134 source/templates/source.html:193
#: contracts/views.py:172 source/templates/source.html:193
#: templates/base.html:100
msgid "Contracts"
msgstr "Contracts"

#: contracts/views.py:141
#: contracts/views.py:179
msgid "Schedule emails"
msgstr "Schedule e-mails"

#: contracts/views.py:207
#: contracts/views.py:245
msgid "Can't delete contract with number"
msgstr "Can't delete contract with number"

#: contracts/views.py:215
#: contracts/views.py:253
msgid "Contract deleted."
msgstr "Contract deleted."

Expand Down Expand Up @@ -1188,10 +1209,6 @@ msgstr "Declined by staff"
msgid "Archiving accepted"
msgstr "Archiving accepted"

#: source/constants.py:29
msgid "Archiving without publisher consent"
msgstr "Archiving without publisher consent"

#: source/constants.py:30
msgid "Declined by publisher"
msgstr "Declined by publisher"
Expand Down Expand Up @@ -1432,7 +1449,7 @@ msgstr "WA-KAT"
msgid "QA check"
msgstr "QA check"

#: source/templates/source.html:178 source/templates/source.html:221
#: source/templates/source.html:178 source/templates/source.html:224
msgid "Deactivate"
msgstr "Deactivate"

Expand All @@ -1456,7 +1473,7 @@ msgstr "Create"
msgid "Assign"
msgstr "Assign"

#: source/templates/source.html:217
#: source/templates/source.html:220
msgid "If you proceed it will be very hard to reactivate this source."
msgstr "If you proceed it will be very hard to reactivate this source."

Expand Down
3 changes: 3 additions & 0 deletions Seeder/source/templates/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ <h4>{% trans 'Contracts' %}:</h4>
{% endfor %}
<a href="{% url 'contracts:create' pk=source.pk %}" class="btn btn-primary btn-block">{% trans 'Create' %}</a>
<a href="{% url 'contracts:assign' pk=source.pk %}" class="btn btn-primary btn-block">{% trans 'Assign' %}</a>
{% if source.contract_set.exists and request.user.is_superuser %}
<a href="{% url 'contracts:unassign' pk=source.pk %}" class="btn btn-danger btn-block">{% trans 'Unassign contract' %}</a>
{% endif %}
</div>

<div class="col-xs-12 col-md-12">
Expand Down

0 comments on commit d48d3e1

Please sign in to comment.