Commit a10ac3e0 authored by Matthias Prellwitz's avatar Matthias Prellwitz

filter for broadcast template list view refs #32

parent 05ec13f8
Pipeline #1561 passed with stage
in 9 minutes and 44 seconds
import datetime
from program.models import Broadcast
from program.models import Broadcast, BroadcastTemplate, WEEKDAYS_BITCHOICE
from django_filters import FilterSet
from django_filters.filters import DateFilter
from django_filters.filters import DateFilter, ChoiceFilter
class BroadcastFilter(FilterSet):
......@@ -22,3 +22,28 @@ class BroadcastFilter(FilterSet):
if data is None:
data = {'date': datetime.date.today()}
super(BroadcastFilter, self).__init__(data, *args, **kwargs)
class BroadcastTemplateFilter(FilterSet):
def has_weekday(queryset, name, value):
if value != "":
return queryset.extra(where=['weekdays & {} > 0'.format(value)])
return queryset
hasweekday = ChoiceFilter(
choices=WEEKDAYS_BITCHOICE._choices,
method=has_weekday,
empty_label='- alle -',
label='Wochentag')
class Meta:
model = BroadcastTemplate
fields = {'program', 'weekrepeat'}
extra_fields = {'hasweekday'}
def __init__(self, data=None, *args, **kwargs):
super(BroadcastTemplateFilter, self).__init__(data, *args, **kwargs)
if self.data == {}:
self.queryset = self.queryset.none()
......@@ -2,6 +2,7 @@ from django.db import models
from django.urls import reverse
from program.helper import BitChoices
WEEKDAYS_BITCHOICE = BitChoices((('mon', 'Montag'), ('tue', 'Dienstag'), ('wed', 'Mittwoch'),
('thu', 'Donnerstag'), ('fri', 'Freitag'), ('sat', 'Samstag'),
('sun', 'Sonntag')))
......@@ -80,6 +81,9 @@ class BroadcastTemplate(models.Model):
def get_absolute_url(self):
return reverse('show-broadcast-template', args=[self.pk])
class Meta:
ordering = ('start_time',)
class BroadcastRepeatTemplate(models.Model):
origin = models.ForeignKey(
......
......@@ -6,13 +6,27 @@
{% endblock %}
{% block heading_title %}Sendungsvorlagen{% endblock %}
{% block heading_action %}
<a href="{% url 'create-broadcast-template' %}" class="btn btn-secondary" role="button">
<a href="{% url 'create-broadcast-template' %}" class="btn btn-success" role="button">
Sendungsvorlage erstellen
</a>
{% endblock %}
{% block content %}
{% include 'program/_broadcasttemplate_list.html' with broadcasttemplates=object_list %}
<form action="" method="get">
<div class="row">
<div class="col-3">{% field filter.form.program %}</div>
<div class="col-3">{% field filter.form.hasweekday %}</div>
<div class="col-3">{% field filter.form.weekrepeat %}</div>
<div class="col-md-3 text-right">
<a class="btn btn-secondary" href="{% url 'list-broadcast-templates' %}" role="button">
Zurücksetzen
</a>
<button class="btn btn-primary">Filtern</button>
</div>
</div>
</form>
{% include 'program/_broadcasttemplate_list.html' with broadcasttemplates=broadcasttemplates %}
{% include 'program/_pagination.html' %}
{% endblock %}
from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy
from django.views.generic import CreateView, DetailView, ListView, UpdateView, DeleteView
from django.views.generic import CreateView, DetailView, UpdateView, DeleteView
from django_filters.views import FilterView
from program.models import Broadcast, BroadcastTemplate, BroadcastRepeatTemplate
from program.forms import BroadcastAddReportForm, BroadcastTemplateForm
from program.filters import BroadcastFilter
from program.filters import BroadcastFilter, BroadcastTemplateFilter
class BroadcastList(FilterView):
......@@ -37,10 +37,12 @@ class BroadcastAddReport(UpdateView):
template_name = 'program/broadcast_add_report.html'
class BroadcastTemplateList(ListView):
model = BroadcastTemplate
ordering = ['start_time', 'weekrepeat']
class BroadcastTemplateList(FilterView):
filterset_class = BroadcastTemplateFilter
context_object_name = 'broadcasttemplates'
paginate_by = 10
template_name = 'program/broadcasttemplate_list.html'
strict = False
class BroadcastTemplateDetail(DetailView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment