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

Mulig å godkjenne eget oppmøte på arrangementer #740

Merged
Merged
1,771 changes: 1,238 additions & 533 deletions fixtures.json

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions news/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from django.contrib import admin
from markdownx.admin import MarkdownxModelAdmin

from .models import Article, Event, EventRegistration, Upload
from .models import Article, Event, Event_responsible, EventRegistration, Upload


class EventRegistrationInline(admin.TabularInline):
model = Event_responsible
extra = 1
verbose_name = "Event responsible"
verbose_name_plural = "Event responsible"


@admin.register(Event)
Expand Down Expand Up @@ -33,10 +40,11 @@ class Eventadmin(MarkdownxModelAdmin):
},
),
("Skills", {"fields": ["skills"]}),
("Advanced", {"fields": ["draft", "internal", "responsible"]}),
("Advanced", {"fields": ["draft", "internal"]}),
]
search_fields = ["title"]
list_display = ["title", "pub_date", "draft", "internal"]
inlines = [EventRegistrationInline]


@admin.register(Article)
Expand Down
6 changes: 3 additions & 3 deletions news/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, *args, **kwargs):
)


class UserFullnameChoiceField(forms.ModelChoiceField):
class UserFullnameChoiceField(forms.ModelMultipleChoiceField):
"""
Denne klassen overrider ModelChoiceField for å vise vanlige
fulle navn istedenfor brukernavn
Expand Down Expand Up @@ -174,7 +174,7 @@ class EventForm(UpdatePubDateOnDraftPublishMixin, forms.ModelForm):
registration_end = SplitDateTimeFieldCustom(label="Påmeldingsfrist")
deregistration_end = SplitDateTimeFieldCustom(label="Avmeldingsfrist")

responsible = UserFullnameChoiceField(
responsibles = UserFullnameChoiceField(
label="Arrangementansvarlig",
queryset=User.objects.all()
.filter(groups__name__in=get_committees())
Expand All @@ -188,7 +188,7 @@ class Meta:
"main_content",
"ingress_content",
"thumbnail",
"responsible",
"responsibles",
"internal",
"registration",
"max_limit",
Expand Down
58 changes: 58 additions & 0 deletions news/migrations/0033_to_responsible_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 3.2.17 on 2023-03-28 18:44

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


def to_responsible_list(apps, schema_editor):
Event = apps.get_model('news', 'Event')
Event_responsible = apps.get_model('news', 'Event_responsible')
for event in Event.objects.all():
if event.responsible:
Event_responsible.objects.create(event=event, responsible=event.responsible)
event.save()

def reverse_to_responsible_list(apps, schema_editor):
Event = apps.get_model('news', 'Event')
for event in Event.objects.all():
responsibles = event.responsibles.all()
if responsibles:
event.responsible = responsibles.first()
event.save()


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('news', '0032_alter_article_main_content'),
]

operations = [
migrations.AlterModelOptions(
name='event',
options={'ordering': ('time_start',), 'permissions': (('can_view_internal_event', 'Can see internal events'),)},
),
migrations.CreateModel(
name='Event_responsible',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('event', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='news.event')),
('responsible', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='event',
name='responsibles',
field=models.ManyToManyField(related_name='responsibles', through='news.Event_responsible', to=settings.AUTH_USER_MODEL, verbose_name='Arrangementansvarlig'),
),
migrations.RunPython(
to_responsible_list,
reverse_to_responsible_list
),
migrations.RemoveField(
model_name='event',
name='responsible',
)
]
33 changes: 20 additions & 13 deletions news/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,10 @@ class Event(models.Model):
default=timezone.now, verbose_name="Publiseringsdato"
)
author = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
responsible = models.ForeignKey(
User,
related_name="responsible",
on_delete=models.SET_NULL,
blank=True,
null=True,
responsibles = models.ManyToManyField(
to=User,
through="news.Event_responsible",
related_name="responsibles",
verbose_name="Arrangementansvarlig",
)

Expand Down Expand Up @@ -313,13 +311,7 @@ def wait_list(self):
class Meta:
app_label = "news"
ordering = ("time_start",)
permissions = (
(
"can_see_attendees",
"Can see attending, waitlist, register meetup in a event",
),
("can_view_internal_event", "Can see internal events"),
)
permissions = (("can_view_internal_event", "Can see internal events"),)

def formatted_markdown(self):
return clean(markdownify(self.main_content), markdown_tags, markdown_attrs)
Expand Down Expand Up @@ -387,3 +379,18 @@ def is_waitlisted(self):
:return: The waitlist
"""
return self.event.is_waiting(self.user)


class Event_responsible(models.Model):
event = models.ForeignKey(
Event,
on_delete=models.SET_NULL,
blank=True,
null=True,
)
responsible = models.ForeignKey(
User,
on_delete=models.SET_NULL,
blank=True,
null=True,
)
8 changes: 4 additions & 4 deletions news/templates/news/_event_admin_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ <h5>{% trans "Administrator-meny" %}</h5>
<span class="collection-icon-text">{% trans "Rediger arrangement" %}</span></a>
</li>
{% endif %}
{% if event.registration and perms.news.can_see_attendees %}
{% if event.registration and user in event.responsibles %}
<li class="collection-item"><a href="/events/{{ event.id }}/attended">
<i class="material-icons">check</i>
<span class="collection-icon-text">{% trans "Registrer oppmøte" %}</span>
</a></li>
{% endif %}
{% if event.skills.all and perms.news.can_see_attendees %}
{% if event.skills.all and user in event.responsibles %}
<li class="collection-item">
<a href="/events/{{ event.id }}/skills">
<i class="material-icons">how_to_reg</i>
Expand All @@ -37,7 +37,7 @@ <h5>{% trans "Administrator-meny" %}</h5>
</ul>
</div>
</div>
{% if event.registration and perms.news.can_see_attendees %}
{% if event.registration and user in event.responsibles %}
<div class="row">
<div class="col s12 m12 l6">
<ul class="collection with-header">
Expand Down Expand Up @@ -88,7 +88,7 @@ <h5>{% trans "Alle påmeldte" %}</h5>
</div>
</div>
{% if event.servering %}
{% if user == event.responsible or user.is_superuser %}
{% if user in event.responsibles or user.is_superuser %}
<div class="row">
<div class="col s12 m12">
<ul class="collection with-header">
Expand Down
6 changes: 3 additions & 3 deletions news/templates/news/edit_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ <h5>Generelt</h5>
</div>
<div class="input-field col s12">
<i class="material-icons prefix">person</i>
{{ form.responsible }}
<label for="id_responsible">{{ form.responsible.label }}</label>
<span class="helper-text hs-red-text">{{ form.responsible.errors }}</span>
{{ form.responsibles }}
<label for="id_responsibles">{{ form.responsibles.label }}</label>
<span class="helper-text hs-red-text">{{ form.responsibles.errors }}</span>
</div>
<div class="input-field col s12 m6">
<i class="material-icons prefix">date_range</i>
Expand Down
8 changes: 5 additions & 3 deletions news/templates/news/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ <h3 class="hide-on-small-only">{{ event.title }}</h3>
<div class="divider"></div>
</div>
<div class="col s12">
{% if event.responsible %}
<p>{% trans 'Arrangementansvarlig' %}: <a href="{% url 'userprofile:profile_by_id' event.responsible.id %}">{{ event.responsible.get_full_name }}</a></p>
{% endif %}
<p>Arrangementansvarlige:
{% for user in event.responsibles.all %}
<a href="{% url 'userprofile:profile_by_id' user.id %}">{{ user.get_full_name }},</a>
{% endfor %}
</p>
{% if event.time_end|date:"d. F Y" != event.time_start|date:"d. F Y" %}
<p><i class="material-icons small">event</i> {% trans 'Fra' %} {{ event.time_start }}</p>
<p><i class="material-icons small">event_busy</i> {% trans 'Til' %} {{ event.time_end }}</p>
Expand Down
2 changes: 0 additions & 2 deletions news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class EventAttendeeEditView(PermissionRequiredMixin, UpdateView):
template_name = "news/attendee_form.html"
model = Event
fields = ["title"]
permission_required = "news.can_see_attendees"

def get_context_data(self, **kwargs):
context = super(EventAttendeeEditView, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -179,7 +178,6 @@ class EventAttendeeSkillsView(PermissionRequiredMixin, UpdateView):
template_name = "news/skills_form.html"
model = Event
fields = ["title"]
permission_required = "news.can_see_attendees"

def get_context_data(self, **kwargs):
context = super(EventAttendeeSkillsView, self).get_context_data(**kwargs)
Expand Down