diff --git a/inventory/locale/en/LC_MESSAGES/django.po b/inventory/locale/en/LC_MESSAGES/django.po index 20b01934..5d9459d6 100644 --- a/inventory/locale/en/LC_MESSAGES/django.po +++ b/inventory/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-03 19:21+0200\n" +"POT-Creation-Date: 2024-04-11 00:10+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -141,3 +141,11 @@ msgstr "Loan applications" #: inventory/templates/inventory/loan_applications.html:8 msgid "Oversikt over lånesøknader" msgstr "Overview of loan applications" + +#: inventory/views/item_loan.py:107 +msgid "Lånesøknaden er avslått" +msgstr "Loan applications is denied" + +#: inventory/views/item_loan.py:124 +msgid "Lånesøknaden er lukket" +msgstr "Loan application is closed" diff --git a/inventory/locale/nb/LC_MESSAGES/django.po b/inventory/locale/nb/LC_MESSAGES/django.po index 071e077c..0ff2a267 100644 --- a/inventory/locale/nb/LC_MESSAGES/django.po +++ b/inventory/locale/nb/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-03 19:21+0200\n" +"POT-Creation-Date: 2024-04-11 00:09+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -136,3 +136,11 @@ msgstr "" #: inventory/templates/inventory/loan_applications.html:8 msgid "Oversikt over lånesøknader" msgstr "" + +#: inventory/views/item_loan.py:107 +msgid "Lånesøknaden er avslått" +msgstr "" + +#: inventory/views/item_loan.py:124 +msgid "Lånesøknaden er lukket" +msgstr "" diff --git a/inventory/views/item_loan.py b/inventory/views/item_loan.py index a61f1357..864cbdf9 100644 --- a/inventory/views/item_loan.py +++ b/inventory/views/item_loan.py @@ -7,13 +7,10 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse, reverse_lazy from django.utils import timezone -from django.views.generic import ( - CreateView, - DeleteView, - DetailView, - ListView, - TemplateView, -) +from django.utils.translation import gettext as _ +from django.views.generic import CreateView, DetailView, ListView, TemplateView +from django.views.generic.dates import BaseDetailView +from django.views.generic.edit import DeletionMixin from inventory.models.item import Item from inventory.models.item_loan import ItemLoan @@ -97,12 +94,12 @@ def get(self, request, pk=None, **kwargs): ) -class ItemLoanDeclineView(PermissionRequiredMixin, DeleteView): +class ItemLoanDeclineView(BaseDetailView, PermissionRequiredMixin, DeletionMixin): """Endpoint for deleting/rejecting loans""" model = ItemLoan permission_required = "inventory.delete_itemloan" - success_message = "Lånesøknaden er avslått" + success_message = _("Lånesøknaden er avslått") success_url = reverse_lazy("inventory:loans") def get_success_url(self): @@ -114,12 +111,12 @@ def get(self, request, *args, **kwargs): return self.post(request, *args, **kwargs) -class ItemLoanReturnedView(PermissionRequiredMixin, DeleteView): +class ItemLoanReturnedView(BaseDetailView, PermissionRequiredMixin, DeletionMixin): """Endpoint for returning loans (deletes them)""" model = ItemLoan permission_required = "inventory.delete_itemloan" - success_message = "Lånesøknaden er lukket" + success_message = _("Lånesøknaden er lukket") success_url = reverse_lazy("inventory:loans") def get_success_url(self): diff --git a/news/forms.py b/news/forms.py index 6b59f11a..d1aa4609 100644 --- a/news/forms.py +++ b/news/forms.py @@ -1,5 +1,6 @@ from django import forms from django.contrib.auth.models import User +from django.db.models import Count from django.db.utils import OperationalError, ProgrammingError from django.forms import inlineformset_factory from django.forms.widgets import ClearableFileInput @@ -111,16 +112,6 @@ def __init__(self, *args, **kwargs): ) -class UserFullnameChoiceField(forms.ModelMultipleChoiceField): - """ - Denne klassen overrider ModelChoiceField for å vise vanlige - fulle navn istedenfor brukernavn - """ - - def label_from_instance(self, obj): - return obj.get_full_name() - - class MaterialFileWidget(ClearableFileInput): template_name = "files/_file_widget.html" @@ -175,16 +166,21 @@ class EventForm(UpdatePubDateOnDraftPublishMixin, forms.ModelForm): registration_end = SplitDateTimeFieldCustom(label="Påmeldingsfrist") deregistration_end = SplitDateTimeFieldCustom(label="Avmeldingsfrist") - responsibles = UserFullnameChoiceField( + responsibles = forms.Field( label=_("Arrangementansvarlig"), - queryset=User.objects.all() - .filter(groups__name__in=get_committees()) - .order_by("first_name"), ) def clean_responsibles(self): - data = self.cleaned_data["responsibles"] - return User.objects.filter(pk__in=data) + """Get users from responsibles data, filter and check if they exist.""" + data = self.data.getlist("responsibles") + users = User.objects.annotate(group_count=Count("groups")).filter( + pk__in=data, group_count__gt=0 + ) + if type(data) is list and users.count() != len(data): + raise forms.ValidationError( + _("Bruker er ikke i en registert gruppe."), code="invalid" + ) + return users class Meta: model = Event diff --git a/news/locale/en/LC_MESSAGES/django.po b/news/locale/en/LC_MESSAGES/django.po index 2b306b8f..c206c967 100644 --- a/news/locale/en/LC_MESSAGES/django.po +++ b/news/locale/en/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-03 19:21+0200\n" +"POT-Creation-Date: 2024-04-11 00:10+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -259,31 +259,31 @@ msgstr "Done" msgid "Lagre og publiser arrangement" msgstr "Save and publish event" -#: news/templates/news/edit_event.html:269 +#: news/templates/news/edit_event.html:270 msgid "Kunne ikke hente flere resultater" msgstr "The results could not be loaded" -#: news/templates/news/edit_event.html:270 +#: news/templates/news/edit_event.html:271 msgid "Vennligst skriv inn flere tegn" msgstr "Please add more characters" -#: news/templates/news/edit_event.html:271 +#: news/templates/news/edit_event.html:272 msgid "Vennligst skriv inn færre tegn" msgstr "Please remove characters" -#: news/templates/news/edit_event.html:272 +#: news/templates/news/edit_event.html:273 msgid "Laster flere resultater" msgstr "Loading more results" -#: news/templates/news/edit_event.html:273 +#: news/templates/news/edit_event.html:274 msgid "Du kan ikke velge flere" msgstr "You cannot choose more" -#: news/templates/news/edit_event.html:274 +#: news/templates/news/edit_event.html:275 msgid "Ingen resultater" msgstr "No results found" -#: news/templates/news/edit_event.html:275 +#: news/templates/news/edit_event.html:276 msgid "Fjern alle" msgstr "Remove all" @@ -302,7 +302,6 @@ msgid "" msgstr "" "This event is open to all students regardless of Hackerspace membership" -#: news/templates/news/event.html:49 #: news/templates/news/event.html:49 msgid "Fra" msgstr "From" @@ -529,6 +528,3 @@ msgstr "Attendance Not Registered" #: news/templates/news/skills_form.html:87 msgid "Save" msgstr "Save" - -#~ msgid "Arrangementansvarlig" -#~ msgstr "Event organizer" diff --git a/news/locale/nb/LC_MESSAGES/django.po b/news/locale/nb/LC_MESSAGES/django.po index 0fd02f57..ccf69132 100644 --- a/news/locale/nb/LC_MESSAGES/django.po +++ b/news/locale/nb/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-04-03 19:21+0200\n" +"POT-Creation-Date: 2024-04-11 00:09+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -261,31 +261,31 @@ msgstr "" msgid "Lagre og publiser arrangement" msgstr "" -#: news/templates/news/edit_event.html:269 +#: news/templates/news/edit_event.html:270 msgid "Kunne ikke hente flere resultater" msgstr "" -#: news/templates/news/edit_event.html:270 +#: news/templates/news/edit_event.html:271 msgid "Vennligst skriv inn flere tegn" msgstr "" -#: news/templates/news/edit_event.html:271 +#: news/templates/news/edit_event.html:272 msgid "Vennligst skriv inn færre tegn" msgstr "" -#: news/templates/news/edit_event.html:272 +#: news/templates/news/edit_event.html:273 msgid "Laster flere resultater" msgstr "" -#: news/templates/news/edit_event.html:273 +#: news/templates/news/edit_event.html:274 msgid "Du kan ikke velge flere" msgstr "" -#: news/templates/news/edit_event.html:274 +#: news/templates/news/edit_event.html:275 msgid "Ingen resultater" msgstr "" -#: news/templates/news/edit_event.html:275 +#: news/templates/news/edit_event.html:276 msgid "Fjern alle" msgstr "" diff --git a/news/templates/news/edit_event.html b/news/templates/news/edit_event.html index c6d9b680..45f71dac 100644 --- a/news/templates/news/edit_event.html +++ b/news/templates/news/edit_event.html @@ -6,7 +6,7 @@