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

691 usersearchbar #794

Merged
merged 11 commits into from
Apr 10, 2024
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ venv/
*.html.py
*.txt.py
pyenv/
.python-version
.python-version
2 changes: 1 addition & 1 deletion applications/locale/en/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: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-13 20:22+0100\n"
"POT-Creation-Date: 2024-03-13 23:06+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion applications/locale/nb/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: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-13 20:22+0100\n"
"POT-Creation-Date: 2024-03-13 23:06+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
17 changes: 17 additions & 0 deletions authentication/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.auth.models import Group, User
from rest_framework import serializers


class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = ("name",)


class UserSerializer(serializers.ModelSerializer):

groups = GroupSerializer(many=True)

class Meta:
model = User
fields = ("id", "username", "first_name", "last_name", "email", "groups")
7 changes: 6 additions & 1 deletion news/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.forms import inlineformset_factory
from django.forms.widgets import ClearableFileInput
from django.utils import timezone
from django.utils.translation import gettext as _
from markdownx.fields import MarkdownxFormField

from committees.models import Committee
Expand Down Expand Up @@ -175,12 +176,16 @@ class EventForm(UpdatePubDateOnDraftPublishMixin, forms.ModelForm):
deregistration_end = SplitDateTimeFieldCustom(label="Avmeldingsfrist")

responsibles = UserFullnameChoiceField(
label="Arrangementansvarlig",
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)

class Meta:
model = Event
fields = [
Expand Down
59 changes: 46 additions & 13 deletions news/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: news/forms.py:179
msgid "Arrangementansvarlig"
msgstr "Event organizer"

#: news/templates/news/_event-list-element.html:13
msgid "Skjer nå!"
msgstr "Happening now!"
Expand All @@ -31,7 +35,7 @@ msgid "Administrator-meny"
msgstr "Administrator Menu"

#: news/templates/news/_event_admin_menu.html:14
#: news/templates/news/edit_event.html:12
#: news/templates/news/edit_event.html:21
msgid "Rediger arrangement"
msgstr "Edit event"

Expand Down Expand Up @@ -194,12 +198,12 @@ msgid "Lagre"
msgstr "Save"

#: news/templates/news/edit_article.html:21
#: news/templates/news/edit_event.html:25
#: news/templates/news/edit_event.html:34
msgid "Innhold"
msgstr "Content"

#: news/templates/news/edit_article.html:42
#: news/templates/news/edit_event.html:47
#: news/templates/news/edit_event.html:56
msgid ""
"Bare markdown støttes i dette feltet, html blir returnert som plaintext. "
"Bilder kan legges til ved drag-and-drop."
Expand All @@ -213,31 +217,31 @@ msgid "Lagre og publiser artikkel"
msgstr "Save and publish article"

#: news/templates/news/edit_article.html:76
#: news/templates/news/edit_event.html:239
#: news/templates/news/edit_event.html:248
msgid "Lagre som utkast"
msgstr "Save as draft"

#: news/templates/news/edit_event.html:57
#: news/templates/news/edit_event.html:66
msgid "Velg hovedbilde"
msgstr "Select main image"

#: news/templates/news/edit_event.html:80
#: news/templates/news/edit_event.html:89
msgid "Internt arrangement (Kun Hackerspace-medlemmer kan se arrangementet)"
msgstr "Internal event (Only Hackerspace members can see the event)"

#: news/templates/news/edit_event.html:147 news/templates/news/event.html:105
#: news/templates/news/edit_event.html:156 news/templates/news/event.html:105
msgid "Påmelding"
msgstr "Registration"

#: news/templates/news/edit_event.html:181
#: news/templates/news/edit_event.html:190
msgid "Ferdigheter"
msgstr "Skills"

#: news/templates/news/edit_event.html:198 news/templates/news/event.html:155
#: news/templates/news/edit_event.html:207 news/templates/news/event.html:155
msgid "Filer"
msgstr "Files"

#: news/templates/news/edit_event.html:199
#: news/templates/news/edit_event.html:208
msgid ""
"Det kan være nyttig å legge ved powerpoint eller andre relevante filer i "
"arrangementet. Da får deltakerene mulighet til å gjøre seg klare før "
Expand All @@ -246,15 +250,43 @@ msgstr ""
"It can be beneficial to add relevant documents to let participants prepare "
"ahead of time."

#: news/templates/news/edit_event.html:218
#: news/templates/news/edit_event.html:227
msgid "Ferdig"
msgstr "Done"

#: news/templates/news/edit_event.html:233
#: news/templates/news/edit_event.html:236
#: news/templates/news/edit_event.html:242
#: news/templates/news/edit_event.html:245
msgid "Lagre og publiser arrangement"
msgstr "Save and publish event"

#: news/templates/news/edit_event.html:269
msgid "Kunne ikke hente flere resultater"
msgstr "The results could not be loaded"

#: news/templates/news/edit_event.html:270
msgid "Vennligst skriv inn flere tegn"
msgstr "Please add more characters"

#: news/templates/news/edit_event.html:271
msgid "Vennligst skriv inn færre tegn"
msgstr "Please remove characters"

#: news/templates/news/edit_event.html:272
msgid "Laster flere resultater"
msgstr "Loading more results"

#: news/templates/news/edit_event.html:273
msgid "Du kan ikke velge flere"
msgstr "You cannot choose more"

#: news/templates/news/edit_event.html:274
msgid "Ingen resultater"
msgstr "No results found"

#: news/templates/news/edit_event.html:275
msgid "Fjern alle"
msgstr "Remove all"

#: news/templates/news/event.html:28
msgid "Dette arrangementet er lagret som utkast og dermed kun synlig for deg"
msgstr "This event is saved as a draft and is only visible to you"
Expand All @@ -270,6 +302,7 @@ 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"
Expand Down
58 changes: 45 additions & 13 deletions news/locale/nb/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: news/forms.py:179
msgid "Arrangementansvarlig"
msgstr ""

#: news/templates/news/_event-list-element.html:13
msgid "Skjer nå!"
msgstr ""
Expand All @@ -37,7 +41,7 @@ msgid "Administrator-meny"
msgstr ""

#: news/templates/news/_event_admin_menu.html:14
#: news/templates/news/edit_event.html:12
#: news/templates/news/edit_event.html:21
msgid "Rediger arrangement"
msgstr ""

Expand Down Expand Up @@ -200,12 +204,12 @@ msgid "Lagre"
msgstr ""

#: news/templates/news/edit_article.html:21
#: news/templates/news/edit_event.html:25
#: news/templates/news/edit_event.html:34
msgid "Innhold"
msgstr ""

#: news/templates/news/edit_article.html:42
#: news/templates/news/edit_event.html:47
#: news/templates/news/edit_event.html:56
msgid ""
"Bare markdown støttes i dette feltet, html blir returnert som plaintext. "
"Bilder kan legges til ved drag-and-drop."
Expand All @@ -217,46 +221,74 @@ msgid "Lagre og publiser artikkel"
msgstr ""

#: news/templates/news/edit_article.html:76
#: news/templates/news/edit_event.html:239
#: news/templates/news/edit_event.html:248
msgid "Lagre som utkast"
msgstr ""

#: news/templates/news/edit_event.html:57
#: news/templates/news/edit_event.html:66
msgid "Velg hovedbilde"
msgstr ""

#: news/templates/news/edit_event.html:80
#: news/templates/news/edit_event.html:89
msgid "Internt arrangement (Kun Hackerspace-medlemmer kan se arrangementet)"
msgstr ""

#: news/templates/news/edit_event.html:147 news/templates/news/event.html:105
#: news/templates/news/edit_event.html:156 news/templates/news/event.html:105
msgid "Påmelding"
msgstr ""

#: news/templates/news/edit_event.html:181
#: news/templates/news/edit_event.html:190
msgid "Ferdigheter"
msgstr ""

#: news/templates/news/edit_event.html:198 news/templates/news/event.html:155
#: news/templates/news/edit_event.html:207 news/templates/news/event.html:155
msgid "Filer"
msgstr ""

#: news/templates/news/edit_event.html:199
#: news/templates/news/edit_event.html:208
msgid ""
"Det kan være nyttig å legge ved powerpoint eller andre relevante filer i "
"arrangementet. Da får deltakerene mulighet til å gjøre seg klare før "
"arrangementet starter."
msgstr ""

#: news/templates/news/edit_event.html:218
#: news/templates/news/edit_event.html:227
msgid "Ferdig"
msgstr ""

#: news/templates/news/edit_event.html:233
#: news/templates/news/edit_event.html:236
#: news/templates/news/edit_event.html:242
#: news/templates/news/edit_event.html:245
msgid "Lagre og publiser arrangement"
msgstr ""

#: news/templates/news/edit_event.html:269
msgid "Kunne ikke hente flere resultater"
msgstr ""

#: news/templates/news/edit_event.html:270
msgid "Vennligst skriv inn flere tegn"
msgstr ""

#: news/templates/news/edit_event.html:271
msgid "Vennligst skriv inn færre tegn"
msgstr ""

#: news/templates/news/edit_event.html:272
msgid "Laster flere resultater"
msgstr ""

#: news/templates/news/edit_event.html:273
msgid "Du kan ikke velge flere"
msgstr ""

#: news/templates/news/edit_event.html:274
msgid "Ingen resultater"
msgstr ""

#: news/templates/news/edit_event.html:275
msgid "Fjern alle"
msgstr ""

#: news/templates/news/event.html:28
msgid "Dette arrangementet er lagret som utkast og dermed kun synlig for deg"
msgstr ""
Expand Down
52 changes: 48 additions & 4 deletions news/templates/news/edit_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'news/css/news_style.css' %}">
<link href="{% static 'website/css/select2.min.css' %}" rel="stylesheet" />
<style>
.select-wrapper {
display: none;
}
.select2 {
margin-top: 30px;
}
</style>
{% endblock head %}

{% block content %}
Expand Down Expand Up @@ -82,11 +91,11 @@ <h5>Generelt</h5>
</p>
<span class="helper-text hs-red-text">{{ form.internal.errors }}</span>
</div>
<div class="input-field col s12">
<div class="col s12 input-field">
<i class="material-icons prefix">person</i>
{{ form.responsibles }}
<label for="id_responsibles">{{ form.responsibles.label }}</label>
<span class="helper-text hs-red-text">{{ form.responsibles.errors }}</span>
<label for="responsible-list">{{ form.responsibles.label }}</label>
<div style="margin-top: 40px; margin-bottom: -20px;" class="helper-text hs-red-text">{{ form.responsibles.errors }}</div>
<select id="responsible-list" multiple name="responsibles"></select>
</div>
<div class="input-field col s12 m6">
<i class="material-icons prefix">date_range</i>
Expand Down Expand Up @@ -244,6 +253,41 @@ <h5>{% trans "Ferdig" %}</h5>
</div>
</div>
</form>
<script src="{% static 'website/js/select2.min.js' %}" type="text/javascript" ></script>
<script>
const data = [];
{% for responsible in responsibles.all %}
data.push({
id: "{{ responsible.id }}",
text: "{{ responsible.get_full_name }}",
selected: true
})
{% endfor %}

$("#responsible-list").select2({
data: data,
language: {
errorLoading: () => '{% trans "Kunne ikke hente flere resultater" %}',
inputTooShort: () => '{% trans "Vennligst skriv inn flere tegn" %}',
inputTooLong: () => '{% trans "Vennligst skriv inn færre tegn" %}',
loadingMore: () => '{% trans "Laster flere resultater" %}',
maximumSelected: () => '{% trans "Du kan ikke velge flere" %}',
noResults: () => '{% trans "Ingen resultater" %}',
removeAllItems: () => '{% trans "Fjern alle" %}',
},
ajax: {
url: (params) => `/api/user-search?page-size=10&query=${params.term ?? ''}`,
dataType: "json",
processResults: (res) => {
return {
results: res.map((usr) => ({
id: usr["id"],
text: `${usr["first_name"]} ${usr["last_name"]}`
}))}
},
}
})
</script>
<script src="{% static 'news/js/edit_event.js' %}"></script>
<script src="{% static 'website/js/datetimepicker.js' %}"></script>
<script src="{% static 'news/js/save_draft_or_publish.js' %}"></script>
Expand Down
Loading