diff --git a/aleksis/apps/alsijil/filters.py b/aleksis/apps/alsijil/filters.py index c924aec0d78b5c28032407f805000d5481def23e..1e03f7ba399699055a7fda25b4d8680f3617b6f3 100644 --- a/aleksis/apps/alsijil/filters.py +++ b/aleksis/apps/alsijil/filters.py @@ -5,7 +5,7 @@ from material import Layout, Row from aleksis.core.models import SchoolTerm -from .models import PersonalNote +from .models import Instruction, PersonalNote class PersonalNoteFilter(FilterSet): @@ -45,3 +45,22 @@ class PersonalNoteFilter(FilterSet): "excuse_type": ["exact"], "extra_marks": ["exact"], } + + +class InstructionFilter(FilterSet): + def __init__(self, data=None, *args, **kwargs): + current_school_term = SchoolTerm.current + + # if data is not None: + data = data.copy() if data is not None else {} + + if "school_term" not in data and current_school_term: + data["school_term"] = current_school_term + + super().__init__(data, *args, **kwargs) + + class Meta: + model = Instruction + fields = { + "school_term": ["exact"], + } diff --git a/aleksis/apps/alsijil/templates/alsijil/instruction/list.html b/aleksis/apps/alsijil/templates/alsijil/instruction/list.html index 02320901a0bfc927d3c2e95dd174e26f24904370..eddfc6f9cc0099083dd2a7a2bbc06bbf991af0a7 100644 --- a/aleksis/apps/alsijil/templates/alsijil/instruction/list.html +++ b/aleksis/apps/alsijil/templates/alsijil/instruction/list.html @@ -2,52 +2,73 @@ {% extends "core/base.html" %} -{% load i18n rules %} +{% load i18n rules material_form %} {% block browser_title %}{% blocktrans %}Instructions{% endblocktrans %}{% endblock %} {% block page_title %}{% blocktrans %}Instructions{% endblocktrans %}{% endblock %} {% block content %} - {% has_perm "alsijil.add_instruction_rule" user as can_add %} - {% if can_add %} - <a class="btn green waves-effect waves-light" href="{% url 'create_instruction' %}"> - <i class="material-icons left">add</i> - {% trans "Create instruction" %} - </a> - {% endif %} + <div class="row no-margin"> + <div class="col s12"> + {% has_perm "alsijil.add_instruction_rule" user as can_add %} + {% if can_add %} + <a class="btn green waves-effect waves-light margin-bottom" href="{% url 'create_instruction' %}"> + <i class="material-icons left">add</i> + {% trans "Create instruction" %} + </a> + {% endif %} + <form action="" method="get"> + <div class="card"> + <div class="card-content"> + <div class="card-title">{% trans "Filter instructions" %}</div> + {% form form=filter.form %}{% endform %} + </div> + <div class="card-action-light"> + <button type="submit" class="btn waves-effect waves-light green"> + <i class="material-icons left">filter_alt</i> + {% trans "Filter" %} + </button> + <a href="{% url "instructions" %}" class="btn waves-effect waves-light red"> + <i class="material-icons left">cancel</i> + {% trans "Reset filter" %} + </a> + </div> + </div> + </form> + </div> + </div> + - <ul class="collection"> + <div class="row"> {% for instruction in instruction_list %} - <li class="collection-item avatar"> - <i class="material-icons materialize-circle primary-color">{{ instruction.icon|default:"rule" }}</i> - <span class="title"> {{ instruction.name }}</span> - <div class="right"> - {% has_perm "alsijil.edit_instruction_rule" user as can_edit %} - {% has_perm "alsijil.delete_instruction_rule" user as can_delete %} - {% if can_edit %} - <a class="btn-flat waves-effect waves-orange orange-text" - href="{% url "edit_instruction" instruction.pk %}"> - <i class="material-icons left">edit</i> - {% trans "Edit" %} + <div class=" col s12 m12 l6 xl4"> + <div class="card"> + <div class="card-content"> + <i class="material-icons materialize-circle primary-color-text left small">{{ instruction.icon|default:"rule" }}</i> + <span class="card-title"> {{ instruction.name }}</span> + {% has_perm "alsijil.edit_instruction_rule" user as can_edit %} + {% has_perm "alsijil.delete_instruction_rule" user as can_delete %} + {% if can_edit %} + <a class="btn-flat waves-effect waves-orange orange-text" + href="{% url "edit_instruction" instruction.pk %}"> + <i class="material-icons left">edit</i> + {% trans "Edit" %} + </a> + {% endif %} + {% if can_delete %} + <a class="btn-flat waves-effect waves-red red-text" href="{% url "delete_instruction" instruction.pk %}"> + <i class="material-icons left">delete</i> + {% trans "Delete" %} + </a> + {% endif %} + </div> + <div class="card-action"> + <a class="" href="{{ instruction.pdf_file.url }}" target="_blank"> + {% trans "Show PDF file with instruction" %} </a> - {% endif %} - {% if can_delete %} - <a class="btn-flat waves-effect waves-red red-text" href="{% url "delete_instruction" instruction.pk %}"> - <i class="material-icons left">delete</i> - {% trans "Delete" %} - </a> - {% endif %} - - <a class="btn-flat waves-effect waves-green right" href="{{ instruction.pdf_file.url }}" target="_blank"> - <i class="material-icons left">picture_as_pdf</i> - {% trans "Show PDF file with instruction" %} - </a> + </div> </div> - </li> - {% empty %} - <li class="collection-item"> - {% trans "No instructions available." %} - </li> + </div> {% endfor %} - </ul> + </div> {% endblock %} diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index a3751bcc25c02ad01e942468d94a4052ee966205..4605624cddf8e914e0be81a8a2ef6a6e96f74adc 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -17,10 +17,11 @@ from django.utils.http import url_has_allowed_host_and_scheme from django.utils.translation import ugettext as _ from django.views import View from django.views.decorators.cache import never_cache -from django.views.generic import DetailView, ListView +from django.views.generic import DetailView import reversion from calendarweek import CalendarWeek +from django_filters.views import FilterView from django_tables2 import RequestConfig, SingleTableView from guardian.core import ObjectPermissionChecker from guardian.shortcuts import get_objects_for_user @@ -43,7 +44,7 @@ from aleksis.core.util.core_helpers import get_site_preferences, objectgetter_op from aleksis.core.util.pdf import render_pdf from aleksis.core.util.predicates import check_global_permission -from .filters import PersonalNoteFilter +from .filters import InstructionFilter, PersonalNoteFilter from .forms import ( AssignGroupRoleForm, ExcuseTypeForm, @@ -1420,12 +1421,13 @@ class AllRegisterObjectsView(PermissionRequiredMixin, View): return render(request, "alsijil/class_register/all_objects.html", context) -class InstructionsListView(PermissionRequiredMixin, ListView): +class InstructionsListView(PermissionRequiredMixin, FilterView): """Table of all instructions.""" model = Instruction permission_required = "alsijil.view_instructions_rule" template_name = "alsijil/instruction/list.html" + filterset_class = InstructionFilter def get_queryset(self): if self.request.user.has_perm("alsijil.view_instruction"):