##// END OF EJS Templates
New backend for fav threads. Now only last post ids are saved, no thread ids
New backend for fav threads. Now only last post ids are saved, no thread ids

File last commit:

r2035:3dd433d2 default
r2044:227641ed default
Show More
mixins.py
53 lines | 1.4 KiB | text/x-python | PythonLexer
PARAM_NEXT = 'next'
PARAMETER_METHOD = 'method'
PARAMETER_CURRENT_PAGE = 'current_page'
PARAMETER_PAGINATOR = 'paginator'
PARAMETER_PREV_LINK = 'prev_page_link'
PARAMETER_NEXT_LINK = 'next_page_link'
class DispatcherMixin:
"""
This class contains a dispather method that can run a method specified by
'method' request parameter.
"""
def __init__(self):
self.user = None
def dispatch_method(self, *args, **kwargs):
request = args[0]
self.user = request.user
method_name = None
if PARAMETER_METHOD in request.GET:
method_name = request.GET[PARAMETER_METHOD]
elif PARAMETER_METHOD in request.POST:
method_name = request.POST[PARAMETER_METHOD]
if method_name:
return getattr(self, method_name)(*args, **kwargs)
class PaginatedMixin:
def get_page_context(self, paginator, page):
"""
Get pagination context variables
"""
params = {}
params[PARAMETER_PAGINATOR] = paginator
current_page = paginator.page(int(page))
params[PARAMETER_CURRENT_PAGE] = current_page
if current_page.has_previous():
params[PARAMETER_PREV_LINK] = paginator.get_page_url(
current_page.previous_page_number())
if current_page.has_next():
params[PARAMETER_NEXT_LINK] = paginator.get_page_url(
current_page.next_page_number())
return params