Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mpicms/mpicms/personal/views.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (37 sloc)
2.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.list import ListView | |
from django.shortcuts import get_object_or_404 | |
from .models import Contact, Group, Position, SpecialFunction | |
class ContactListView(ListView): | |
model = Contact | |
def get_queryset(self): | |
group_pk = self.request.GET.get('group') | |
position_pk = self.request.GET.get('position') | |
special_function_pk = self.request.GET.get('special_function') | |
qs = super().get_queryset(); | |
if group_pk is not None and group_pk != "": | |
qs = qs.filter(groups__group_id=group_pk) | |
if position_pk is not None and position_pk != "": | |
qs = qs.filter(positions__position_id=position_pk) | |
if special_function_pk is not None and special_function_pk != "": | |
qs = qs.filter(special_functions=special_function_pk) | |
return qs | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
context['groups'] = Group.objects.all().order_by("name") | |
context['positions'] = Position.objects.all().order_by("title") | |
context['special_functions'] = SpecialFunction.objects.all().order_by("title") | |
group_pk = self.request.GET.get('group') | |
if group_pk is not None and group_pk != "": | |
context['selected_group_pk'] = group_pk | |
context['selected_group'] = get_object_or_404(Group, pk=group_pk) if group_pk else "" | |
position_pk = self.request.GET.get('position') | |
if position_pk is not None and position_pk != "": | |
context['selected_position_pk'] = position_pk | |
context['selected_position'] = get_object_or_404(Position, pk=position_pk) if position_pk else "" | |
special_function_pk = self.request.GET.get('special_function') | |
if special_function_pk is not None and special_function_pk != "": | |
context['selected_special_function_pk'] = special_function_pk | |
context['selected_special_function'] = get_object_or_404(SpecialFunction, pk=special_function_pk) if special_function_pk else "" | |
return context | |
class RawContactListView(ContactListView): | |
template_name = 'personal/contact_list_raw.html' |