##// END OF EJS Templates
Extracted some magic strings
Extracted some magic strings

File last commit:

r1940:1f7b0788 default
r2002:a3d63355 default
Show More
stickers.py
45 lines | 1.7 KiB | text/x-python | PythonLexer
neko259
Added local stickers feature
r1940 from django.shortcuts import render, redirect
neko259
Added sticker as a separate entity for the attachment aliases
r1937 from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
neko259
Added local stickers feature
r1940 from boards.abstracts.settingsmanager import get_settings_manager
from boards.models.attachment import AttachmentSticker, Attachment
neko259
Added sticker as a separate entity for the attachment aliases
r1937 from boards.views.base import BaseBoardView
neko259
Added local stickers feature
r1940 CONTEXT_GLOBAL_STICKERS = 'global_stickers'
CONTEXT_LOCAL_STICKERS = 'local_stickers'
neko259
Added sticker as a separate entity for the attachment aliases
r1937
TEMPLATE = 'boards/aliases.html'
class AliasesView(BaseBoardView):
@method_decorator(csrf_protect)
def get(self, request, category=None):
neko259
Added local stickers feature
r1940 result = self._process_creation(request)
if result:
return result
neko259
Added sticker as a separate entity for the attachment aliases
r1937 params = dict()
if category:
neko259
Added local stickers feature
r1940 params[CONTEXT_GLOBAL_STICKERS] = AttachmentSticker.objects.filter(
neko259
Added sticker as a separate entity for the attachment aliases
r1937 name__startswith=(category + '/'))
else:
neko259
Added local stickers feature
r1940 params[CONTEXT_GLOBAL_STICKERS] = AttachmentSticker.objects.all()
params[CONTEXT_LOCAL_STICKERS] = get_settings_manager(request).get_stickers()
neko259
Added sticker as a separate entity for the attachment aliases
r1937
return render(request, TEMPLATE, params)
neko259
Added local stickers feature
r1940 def _process_creation(self, request):
action = request.GET.get('action')
if action == 'add' and 'name' in request.GET and 'id' in request.GET:
name = request.GET['name']
id = request.GET['id']
attachment = Attachment.objects.get(id=id)
get_settings_manager(request).add_attachment_alias(name, attachment)
return redirect('stickers')
if action == 'remove' and 'name' in request.GET:
name = request.GET['name']
get_settings_manager(request).remove_attachment_alias(name)
return redirect('stickers')