Skip to content

Commit

Permalink
Create dashboard for application periods
Browse files Browse the repository at this point in the history
  • Loading branch information
oleast committed Mar 28, 2020
1 parent e34ce33 commit b77cb57
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 3 deletions.
38 changes: 38 additions & 0 deletions apps/approval/dashboard/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django import forms
from django.core.exceptions import ValidationError
from django.utils import timezone

from apps.dashboard.widgets import DatetimePickerInput, multiple_widget_generator

from ..models import CommitteeApplicationPeriod


class CommitteeApplicationPeriodForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
data = cleaned_data.copy()
data.pop("committees")
period = CommitteeApplicationPeriod(**data)

minimum_duration = timezone.timedelta(days=1)
if period.start + minimum_duration >= period.deadline:
raise ValidationError("En opptaksperiode må vare i minst én dag")

actual_deadline = period.deadline + period.deadline_delta
overlapping_periods = CommitteeApplicationPeriod.objects.filter_overlapping(
period.start, actual_deadline
)

if overlapping_periods.exists():
raise ValidationError("Opptaksperioder kan ikke overlappe med hverandre")

return cleaned_data

class Meta:
model = CommitteeApplicationPeriod
fields = ("title", "start", "deadline", "deadline_delta", "committees")

dtp_fields = (("start", {}), ("deadline", {}))
widgetlist = [(DatetimePickerInput, dtp_fields)]

widgets = multiple_widget_generator(widgetlist)
26 changes: 26 additions & 0 deletions apps/approval/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-

from django.conf.urls import url
from django.urls import path

from apps.approval.dashboard import views

Expand All @@ -16,4 +17,29 @@
views.decline_application,
name="approval_decline_application",
),
path(
"application-periods/",
views.ApplicationPeriodList.as_view(),
name="application-periods-list",
),
path(
"application-periods/create/",
views.ApplicationPeriodCreate.as_view(),
name="application-periods-create",
),
path(
"application-periods/<int:pk>/",
views.ApplicationPeriodDetail.as_view(),
name="application-periods-detail",
),
path(
"application-periods/<int:pk>/update",
views.ApplicationPeriodUpdate.as_view(),
name="application-periods-update",
),
path(
"application-periods/<int:pk>/delete",
views.ApplicationPeriodDelete.as_view(),
name="application-periods-delete",
),
]
63 changes: 61 additions & 2 deletions apps/approval/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
from django.core.exceptions import PermissionDenied
from django.http import Http404, HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import (
CreateView,
DeleteView,
DetailView,
TemplateView,
UpdateView,
)
from guardian.decorators import permission_required

from apps.approval.models import MembershipApproval
from apps.authentication.models import AllowedUsername
from apps.dashboard.tools import get_base_context, has_access
from apps.dashboard.tools import DashboardPermissionMixin, get_base_context, has_access

from ..models import CommitteeApplicationPeriod, MembershipApproval
from .forms import CommitteeApplicationPeriodForm


@ensure_csrf_cookie
Expand Down Expand Up @@ -178,3 +188,52 @@ def decline_application(request):
return HttpResponse(status=200)

raise Http404


class ApplicationPeriodList(DashboardPermissionMixin, TemplateView):
model = CommitteeApplicationPeriod
template_name = "approval/dashboard/application_period/index.html"
permission_required = "approval.view_committeeapplicationperiod"

def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["application_periods"] = CommitteeApplicationPeriod.objects.all()
return context


class ApplicationPeriodCreate(DashboardPermissionMixin, CreateView):
model = CommitteeApplicationPeriod
template_name = "approval/dashboard/application_period/create.html"
permission_required = "approval.add_committeeapplicationperiod"
form_class = CommitteeApplicationPeriodForm

def get_success_url(self):
return reverse("application-periods-list")


class ApplicationPeriodDetail(DashboardPermissionMixin, DetailView):
model = CommitteeApplicationPeriod
template_name = "approval/dashboard/application_period/detail.html"
permission_required = "approval.change_committeeapplicationperiod"
context_object_name = "application_period"


class ApplicationPeriodUpdate(DashboardPermissionMixin, UpdateView):
model = CommitteeApplicationPeriod
template_name = "approval/dashboard/application_period/create.html"
permission_required = "approval.delete_committeeapplicationperiod"
form_class = CommitteeApplicationPeriodForm
context_object_name = "application_period"

def get_success_url(self):
return reverse("application-periods-detail", kwargs={"pk": self.object.pk})


class ApplicationPeriodDelete(DashboardPermissionMixin, DeleteView):
model = CommitteeApplicationPeriod
template_name = "approval/dashboard/application_period/delete.html"
permission_required = "approval.delete_committeeapplicationperiod"
context_object_name = "application_period"

def get_success_url(self):
return reverse("application-periods-list")
40 changes: 40 additions & 0 deletions templates/approval/dashboard/application_period/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends 'dashboard_base.html' %}
{% load render_bundle from webpack_loader %}
{% load crispy_forms_tags %}

{% block title %}Opptakerperiode - Legg til{% endblock %}

{% block styles %}
{{ block.super }}
{% endblock %}

{% block js %}
{{ block.super }}
{% endblock %}

{% block page-header %}
{% endblock %}

{% block breadcrumbs %}
<li><a href="/dashboard/approval/application-periods/">Opptaksperioder</a></li>
{% endblock %}

{% block content %}
<div class="row">
<form method="POST" action="">
<div class="col-md-12">
<button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Lagre</button>
</div>
</div>
<br>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Opptaksperiode</h3>
</div>
<div class="panel-body">
{% csrf_token %}
{{ form | crispy }}
</form>
</div>
</div>
{% endblock %}
32 changes: 32 additions & 0 deletions templates/approval/dashboard/application_period/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends 'dashboard_base.html' %}
{% load render_bundle from webpack_loader %}
{% load crispy_forms_tags %}

{% block title %}Opptakerperiode - Legg til{% endblock %}

{% block styles %}
{{ block.super }}
{% endblock %}

{% block js %}
{{ block.super }}
{% endblock %}

{% block page-header %}
{% endblock %}

{% block breadcrumbs %}
<li><a href="/dashboard/approval/application-periods/">Opptaksperioder</a></li>
{% endblock %}

{% block content %}
<div class="row">
<form method="POST" action="">
<p>Er du helt sikker på at du ønsker å slette "{{ object }}"?</p>
<div class="col-md-12">
<button type="submit" class="btn btn-danger"><i class="fa fa-times"></i>Slett</button>
</div>
{% csrf_token %}
</form>
</div>
{% endblock %}
76 changes: 76 additions & 0 deletions templates/approval/dashboard/application_period/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends 'dashboard_base.html' %}
{% load render_bundle from webpack_loader %}
{% load crispy_forms_tags %}

{% block title %}{{ application_period }}{% endblock %}

{% block styles %}
{{ block.super }}
{% endblock %}

{% block js %}
{{ block.super }}
{% endblock %}

{% block page-header %}
{{ application_period }}
{% endblock %}

{% block breadcrumbs %}
<li><a href="/dashboard/approval/application-periods/">Opptaksperioder</a></li>
<li>{{ application_period }}</li>
{% endblock %}

{% block content %}
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Søkere
</h3>
</div>
<br />
<div class="panel-body">
<p>Dette opptaket har mottat {{ application_period.applications.all | length }} søknader</p>
<a href="{% url 'application-periods-update' pk=application_period.id %}" class="btn btn-warning"><i class="fa fa-cogs"></i> Endre</a>
<a href="{% url 'application-periods-delete' pk=application_period.id %}" class="btn btn-danger pull-right"><i class="fa fa-times"></i> Slett</a>
<br />
<table class="table table-striped" id="applications">
<thead>
<tr>
<th>Navn</th>
<th>Søkte grupper</th>
<th>Prioritert rekkefølge</th>
<th>Tidspunkt</th>
</tr>
</thead>
<tbody id="applications-list">
{% for application in application_period.applications.all %}
<tr>
<td>
{% if application.applicant %}
<a href="{% url 'profiles_view' application.applicant.username %}">{{ application.applicant.get_full_name }}</a>
{% else %}
<p>{{ application.name }} ({{ application.email }})</p>
{% endif %}
</td>
<td>
<p>{{ application.committees.all | join:"; " }}
</td>
<td>
<i class="fa fa-lg {% if application.prioritized %}fa-check-square-o checked{% else %}fa-square-o{% endif %}"></i>
</td>
<td>
{{ application.created | date:"Y-m-j H:i"}}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
47 changes: 47 additions & 0 deletions templates/approval/dashboard/application_period/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends 'dashboard_base.html' %}
{% block title %}Opptaksperioder{% endblock %}

{% block page-header %}
Grupper
{% endblock %}

{% block breadcrumbs %}
<li>Grupper</li>
{% endblock %}

{% block content %}
<div class="row">
<div class="col-md-12">
<p></p>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Tittel</th>
<th>Starttid</th>
<th>Frist</th>
<th>Tar imot søknader nå</th>
<th>Antall søknader</th>
</tr>
</thead>
<tbody>
{% for application_period in application_periods %}
<tr>
<td><a href="{% url 'application-periods-detail' pk=application_period.id %}">{{ application_period }}</a></td>
<td>{{ application_period.start | date:"Y-m-j H:i"}}</td>
<td>{{ application_period.deadline | date:"Y-m-j H:i"}}</td>
<td>
<i class="fa fa-lg {% if application_period.accepting_applications %}fa-check-square-o checked{% else %}fa-square-o{% endif %}"></i>
</td>
<td>{{ application_period.applications.count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

{% block js %}
{{ block.super }}
<!-- Dashboard JS here -->
{% endblock %}
14 changes: 13 additions & 1 deletion templates/dashboard_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,23 @@ <h4 class="center-text"><small>Velkommen</small><br />{{ request.user.first_name
{% if 'approval.view_membershipapproval' in user_permissions %}
<li>
<a href="{% url 'approvals' %}">
<i class="fa fa-envelope-o blue"></i> <span>Søknader</span>
<i class="fa fa-envelope-o blue"></i> <span>Medlemsskapsøknader</span>
{% if approval_pending %}<small class="badge pull-right">{{ approval_pending }}</small>{% endif %}
</a>
</li>
{% endif %}
{% if 'approval.view_committeeapplicationperiod' in user_permissions and 'approval.view_committeeapplication' in user_permissions %}
<li class="treeview">
<a href="#">
<i class="fa fa-inbox blue"></i> <span>Komitésøknader</span>
<i class="fa fa-angle-down pull-right"></i>
</a>
<ul class="treeview-menu">
<li><a href="{% url 'application-periods-create' %}"><i class="fa fa-angle-double-right orange"></i>Ny opptaksperiode</a></li>
<li><a href="{% url 'application-periods-list' %}"><i class="fa fa-angle-double-right orange"></i>Se opptaksperioder</a></li>
</ul>
</li>
{% endif %}
{% if 'feedback.view_feedback' in user_permissions %}
<li class="treeview">
<a href="#">
Expand Down

0 comments on commit b77cb57

Please sign in to comment.