-
Notifications
You must be signed in to change notification settings - Fork 2
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
Created angular-free version of committees page #100
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1c914d
Created angular free version of committees page
jgadelange 8323a17
Added select/prefetch related to committee view
jgadelange 0abf972
Added order by for committees
jgadelange 10c90c4
Added query string templatetag
jgadelange dca13e4
Added pagination on committees page
jgadelange File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# As found on https://djangosnippets.org/snippets/2413/ | ||
import re | ||
from django.template import Library, Node, TemplateSyntaxError | ||
from django.http import QueryDict | ||
from django.utils.encoding import smart_str | ||
|
||
register = Library() | ||
|
||
@register.tag | ||
def query_string(parser, token): | ||
""" | ||
Template tag for creating and modifying query strings. | ||
|
||
Syntax: | ||
{% query_string [<base_querystring>] [modifier]* [as <var_name>] %} | ||
|
||
modifier is <name><op><value> where op in {=, +, -} | ||
|
||
Parameters: | ||
- base_querystring: literal query string, e.g. '?tag=python&tag=django&year=2011', | ||
or context variable bound to either | ||
- a literal query string, | ||
- a python dict with potentially lists as values, or | ||
- a django QueryDict object | ||
May be '' or None or missing altogether. | ||
- modifiers may be repeated and have the form <name><op><value>. | ||
They are processed in the order they appear. | ||
name is taken as is for a parameter name. | ||
op is one of {=, +, -}. | ||
= replace all existing values of name with value(s) | ||
+ add value(s) to existing values for name | ||
- remove value(s) from existing values if present | ||
value is either a literal parameter value | ||
or a context variable. If it is a context variable | ||
it may also be bound to a list. | ||
- as <var name>: bind result to context variable instead of injecting in output | ||
(same as in url tag). | ||
|
||
Examples: | ||
1. {% query_string '?tag=a&m=1&m=3&tag=b' tag+'c' m=2 tag-'b' as myqs %} | ||
|
||
Result: myqs == '?m=2&tag=a&tag=c' | ||
|
||
2. context = {'qs': {'tag': ['a', 'b'], 'year': 2011, 'month': 2}, | ||
'tags': ['c', 'd'], | ||
'm': 4,} | ||
|
||
{% query_string qs tag+tags month=m %} | ||
|
||
Result: '?tag=a&tag=b&tag=c&tag=d&year=2011&month=4 | ||
""" | ||
# matches 'tagname1+val1' or 'tagname1=val1' but not 'anyoldvalue' | ||
mod_re = re.compile(r"^(\w+)(=|\+|-)(.*)$") | ||
bits = token.split_contents() | ||
qdict = None | ||
mods = [] | ||
asvar = None | ||
bits = bits[1:] | ||
if len(bits) >= 2 and bits[-2] == 'as': | ||
asvar = bits[-1] | ||
bits = bits[:-2] | ||
if len(bits) >= 1: | ||
first = bits[0] | ||
if not mod_re.match(first): | ||
qdict = parser.compile_filter(first) | ||
bits = bits[1:] | ||
for bit in bits: | ||
match = mod_re.match(bit) | ||
if not match: | ||
raise TemplateSyntaxError("Malformed arguments to query_string tag") | ||
name, op, value = match.groups() | ||
mods.append((name, op, parser.compile_filter(value))) | ||
return QueryStringNode(qdict, mods, asvar) | ||
|
||
class QueryStringNode(Node): | ||
def __init__(self, qdict, mods, asvar): | ||
self.qdict = qdict | ||
self.mods = mods | ||
self.asvar = asvar | ||
def render(self, context): | ||
mods = [(smart_str(k, 'ascii'), op, v.resolve(context)) | ||
for k, op, v in self.mods] | ||
if self.qdict: | ||
qdict = self.qdict.resolve(context) | ||
else: | ||
qdict = None | ||
# Internally work only with QueryDict | ||
qdict = self._get_initial_query_dict(qdict) | ||
#assert isinstance(qdict, QueryDict) | ||
for k, op, v in mods: | ||
qdict.setlist(k, self._process_list(qdict.getlist(k), op, v)) | ||
qstring = qdict.urlencode() | ||
if qstring: | ||
qstring = '?' + qstring | ||
if self.asvar: | ||
context[self.asvar] = qstring | ||
return '' | ||
else: | ||
return qstring | ||
def _get_initial_query_dict(self, qdict): | ||
if not qdict: | ||
qdict = QueryDict(None, mutable=True) | ||
elif isinstance(qdict, QueryDict): | ||
qdict = qdict.copy() | ||
elif isinstance(qdict, basestring): | ||
if qdict.startswith('?'): | ||
qdict = qdict[1:] | ||
qdict = QueryDict(qdict, mutable=True) | ||
else: | ||
# Accept any old dict or list of pairs. | ||
try: | ||
pairs = qdict.items() | ||
except: | ||
pairs = qdict | ||
qdict = QueryDict(None, mutable=True) | ||
# Enter each pair into QueryDict object: | ||
try: | ||
for k, v in pairs: | ||
# Convert values to unicode so that detecting | ||
# membership works for numbers. | ||
if isinstance(v, (list, tuple)): | ||
for e in v: | ||
qdict.appendlist(k,unicode(e)) | ||
else: | ||
qdict.appendlist(k, unicode(v)) | ||
except: | ||
# Wrong data structure, qdict remains empty. | ||
pass | ||
return qdict | ||
def _process_list(self, current_list, op, val): | ||
if not val: | ||
if op == '=': | ||
return [] | ||
else: | ||
return current_list | ||
# Deal with lists only. | ||
if not isinstance(val, (list, tuple)): | ||
val = [val] | ||
val = [unicode(v) for v in val] | ||
# Remove | ||
if op == '-': | ||
for v in val: | ||
while v in current_list: | ||
current_list.remove(v) | ||
# Replace | ||
elif op == '=': | ||
current_list = val | ||
# Add | ||
elif op == '+': | ||
for v in val: | ||
current_list.append(v) | ||
return current_list |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import django_filters | ||
from ldb.models import CommitteeMembership | ||
|
||
|
||
class CommitteeMembershipFilter(django_filters.FilterSet): | ||
|
||
class Meta: | ||
model = CommitteeMembership | ||
fields = ('board', 'committee') |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% extends 'ldb/base.html' %} | ||
{% load i18n static bootstrap3 query_string %} | ||
|
||
{% block title %}{% trans 'Committees' %}{% endblock %} | ||
|
||
{% block content %} | ||
<h2 class="page-header">{% trans 'Committees' %}</h2> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title"> | ||
{% trans 'Filter' %} | ||
</h3> | ||
</div> | ||
<div class="panel-body"> | ||
<form class="form-inline"> | ||
{% bootstrap_form filter.form layout='inline' %} | ||
<button type="submit" class="btn btn-primary"><i class="fa fa-filter"></i> Filter</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title"> | ||
{% trans 'Search results' %} <span class="badge">{{ filter.count }}</span> | ||
</h3> | ||
</div> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>{% trans "Board" %}</th> | ||
<th>{% trans "Committee" %}</th> | ||
<th>{% trans "Name" %}</th> | ||
<th>{% trans "Position" %}</th> | ||
<th>{% trans "RAS" %}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for obj in object_list %} | ||
<tr> | ||
<td>{{ obj.board }}</td> | ||
<td>{{ obj.committee }}</td> | ||
<td><a href="{{ obj.person.get_absolute_url }}">{{ obj.person }}</a></td> | ||
<td>{{ obj.position }}</td> | ||
<td>{{ obj.ras_months }}</td> | ||
</tr> | ||
{% empty %} | ||
<tr> | ||
<td colspan="5">{% trans "No people found." %}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
{% if is_paginated %} | ||
<nav> | ||
<ul class="pager"> | ||
<li{% if not page_obj.has_previous %} class="disabled"{% endif %}> | ||
<a {% if page_obj.has_previous %} | ||
href="{% query_string request.META.QUERY_STRING page=page_obj.previous_page_number %}"{% endif %}> | ||
<span aria-hidden="true">←</span> {% trans "Previous" %} | ||
</a> | ||
</li> | ||
<li{% if not page_obj.has_next %} class="disabled"{% endif %}> | ||
<a {% if page_obj.has_next %} | ||
href="{% query_string request.META.QUERY_STRING page=page_obj.next_page_number %}"{% endif %}> | ||
{% trans "Next" %} <span aria-hidden="true">→</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
{% endif %} | ||
{% endblock %} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waar is dit voor nodig?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
om 1 of andere reden kon ik in de templates niet
request.META
benaderen ofzo, dus toen heb ik dit toegevoegd.Als je vraagt waarom het tegenwoordig in een
TEMPLATES
variable zit, dat is omdat je makkelijker je template renderer kan wisselen sinds django 1.8, dus je kan ook per template backend andere settings hebben.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright :)