# HG changeset patch # User neko259 # Date 2017-10-16 22:24:40 # Node ID 1f7b078874a43b1206300ffe532870cce72cfb3e # Parent d78c60b220a19d64d5047dba879e6a27ec95a1c0 Added local stickers feature diff --git a/boards/abstracts/attachment_alias.py b/boards/abstracts/attachment_alias.py --- a/boards/abstracts/attachment_alias.py +++ b/boards/abstracts/attachment_alias.py @@ -13,7 +13,7 @@ class SessionAttachmentAlias(AttachmentA def get_image(self, alias): settings_manager = SessionSettingsManager(self.session) - return settings_manager.get_image_by_alias(alias) + return settings_manager.get_attachment_by_alias(alias) class ModelAttachmentAlias(AttachmentAlias): diff --git a/boards/abstracts/settingsmanager.py b/boards/abstracts/settingsmanager.py --- a/boards/abstracts/settingsmanager.py +++ b/boards/abstracts/settingsmanager.py @@ -1,5 +1,6 @@ from boards import settings -from boards.models import Tag, TagAlias +from boards.models import Tag, TagAlias, Attachment +from boards.models.attachment import AttachmentSticker from boards.models.thread import FAV_THREAD_NO_UPDATES from boards.models.tag import DEFAULT_LOCALE @@ -164,16 +165,29 @@ class SettingsManager: names = set(name.strip() for name in names) return names - def get_image_by_alias(self, alias): + def get_attachment_by_alias(self, alias): images = self.get_setting(SETTING_IMAGES) - if images is not None and len(images) > 0: - return images.get(alias) + if images and alias in images: + return Attachment.objects.get(id=images.get(alias)) - def add_image_alias(self, alias, image): + def add_attachment_alias(self, alias, attachment): images = self.get_setting(SETTING_IMAGES) if images is None: images = dict() - images.put(alias, image) + images[alias] = attachment.id + self.set_setting(SETTING_IMAGES, images) + + def remove_attachment_alias(self, alias): + images = self.get_setting(SETTING_IMAGES) + del images[alias] + self.set_setting(SETTING_IMAGES, images) + + def get_stickers(self): + images = self.get_setting(SETTING_IMAGES) + if images: + return [AttachmentSticker(name=key, + attachment=Attachment.objects.get(id=value)) + for key, value in images.items()] class SessionSettingsManager(SettingsManager): diff --git a/boards/locale/ru/LC_MESSAGES/django.mo b/boards/locale/ru/LC_MESSAGES/django.mo index 9f4a7ac3acb87e564c1e6dd5462f23a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6BSnhQYwU$7HkAa8m(`?%*Y5B}l)0SK zU`Py7q$?I=9}u}{zbpp&4I%YMJWq&Q3?6k8GTtngpEFdeab|>q*vkY+IQP>@F-oGc zKl1arH4~ViWs#HFa7a+GF6^C`#amRuAuEqoxnc|ErzI&l;mN1OVutdf z)X*l8hkckWm&({R*#zI^Fp8(BpTHaw26Vptn8ZT7lBFp7#;S8CMUv9kq%C8ktrxo1 zw38WjDf=ojOPy=PWdF1m#pIS(Gn4q?k}is(C|%@my+ZLjr+oRXiup)O&V^osR_Zf-i73v=#0*`s>Kr$&O`ARw~xjlE1{9kfB`+v>xf57imAC|8V&ztCr z3oE?lwv*fjB7`!fRGxf|l^K%Wdzn;5si8oUI#uG$0nx=v-gGfOe-geTL0B+8`HG%s zJ;IaGS>J_lUx(I*dLNbU+>4n!0r7QmS$MqA|ncAI7cf-p1e%(2r}=L#2?8tv`|;&k&LH; z>~U(%W=Nz2^$JgJ((w(E^oE*8_urNn?EUOzxHoey3{Fc-5wS4ug`xN-44%X=kn;OV zezXht-Z%Wt5bhk(rJY!3#IC zmCC%quY|MA@0z?>4w4giPV{7;+EQd`jz$yWncN!=;^4VbI$bnPXoSk}1>W)c*8HiJ zL_bfZ8m@VX=j&Ov^*A>`GldNC_%}t|M`^g{Bw{x+$tmuQrt;@XuL*wNmyPUTpx`wq z{}w#Xft7ntV3S-hFaD>fB~E*9&@7vfG;v`Xq5pl#SZdV&`J>3}9g=S-bSyW*a$yPh zHm-8qj}BWA$__rkxBQxyN?T54P>@nT;RdxmwB?{mVt zxRg5oZz77vtkX0Yi6Z^=5`>1D0 eA1FeJ^RL)v*daomGi@r4JTsE{KD?HA)&6fNo(M|- diff --git a/boards/locale/ru/LC_MESSAGES/django.po b/boards/locale/ru/LC_MESSAGES/django.po --- a/boards/locale/ru/LC_MESSAGES/django.po +++ b/boards/locale/ru/LC_MESSAGES/django.po @@ -622,3 +622,12 @@ msgstr "Стикеры" msgid "Available by addresses:" msgstr "Доступно по адресам:" + +msgid "Local stickers" +msgstr "Локальные стикеры" + +msgid "Global stickers" +msgstr "Глобальные стикеры" + +msgid "Remove sticker" +msgstr "Удалить стикер" diff --git a/boards/locale/ru/LC_MESSAGES/djangojs.mo b/boards/locale/ru/LC_MESSAGES/djangojs.mo index 3219613ff9a7e149dcf8c5303f428cf78d4d9901..c48b521be23655a1d2e8f4414e48496ab3389f07 GIT binary patch literal 1175 zc${rgL2naB7@agwz$#UtT#%5M92ym&ad$%y=_aOG;tjR1W6O3x^nkRrCuZq-$C_Cq zsE``Mp{yW z$#FtH1+RdQg1;Zu55SY)CqsTSp5^)nTm&E9MaT^J5*Vw<2g95w$%nwcB;&A`%AGJw?N6CbCxl(?ICyEA_SGlBIN+Bmm&_z3YD>77#Sdp3(S9mLCr8Yay zr3ysk(3-n&&OPhV^IpACsxIZ~yeDMLDykE-*_nPvv8Hfnu2yZb1>lRa=A>G+=@r%yoy^Y&%4E9-D@;XLmGAZ_yE@Ae%GO8cj@eM5_zs%o)3e(kewY3 zqE<>3Z|D2$yp>xJQOqM;cfAKe%&)~?^g=&~W@+oPFBOjq%gseLv!hF5t#HY_s3npg z+@Uky263(y_N5=PMIpP&p;0d_RpG=e&5ni7qt9%sP_XIbBu$RiM8US{SJa|TTAwaV zjYe~Y>ExI?tU24FH*RDWXsl!K*zimpo6Qk@PjBm|dZ3@_4YOu$Q@w@8OEk93ZT-sp zqBp6zY1Z@xn(Jnj=tp{h#*gN%SsVS!^l$KNn49_~)z8f>?AuE91NgS}GotTf-|uD> zqZdg#^*qK1SDT;px_$-uIt8V#f!@^5)9yCW53%F5SxpndiZK86nLFvWhvp~jcsi0G mDfG#EFhMYQky?^1e~hksZ`<5?zj~AW|6VM3H_E%JP4X`x5U`^F diff --git a/boards/locale/ru/LC_MESSAGES/djangojs.po b/boards/locale/ru/LC_MESSAGES/djangojs.po --- a/boards/locale/ru/LC_MESSAGES/djangojs.po +++ b/boards/locale/ru/LC_MESSAGES/djangojs.po @@ -59,3 +59,5 @@ msgstr "Расчёт PoW..." msgid "Duplicates search" msgstr "Поиск дубликатов" +msgid "Add local sticker" +msgstr "Добавить локальный стикер" diff --git a/boards/locale/uk/LC_MESSAGES/django.mo b/boards/locale/uk/LC_MESSAGES/django.mo index f0b7e10e74e1d2962a50cb62f5a8ee19a88a788a..8ac9b88866d658c7cd38790346bfceb553f56a13 GIT binary patch literal 12644 zc%02y3vgWJb^h}r!AWFWmSsRT{{50HTf15rNMJ!2fn_6*A6PO3n$*40UP~A6?p^QQ zwJi*ZErD&owZOO{Au-q_PRLBB$g+fGS(e&qle9DK%x)%~&`z6V(sq(b)9H}Rw3$gW z>37cg@9te`MSvvJYJB(H`#;Wq9^ZM~>+e;5@J|%}=w~Uezxtq3-vW(atN8Eu$CSd5 zdKxqWdJ^;|&}mQ&`g73Lpj97N>JHG`K<9(*2mJ`>QP2gTgP@h5XF)#%dJ*)apqCB( z1}OfiJbpe5`hCzPpg#ir0O+qlD?mShpKCxXK}p2xD}?VV&??YRRLK7OK^KB{R0w~& zLiq19^PdA<40_D$I|I51bfiM${bq&e{oM-Dxuje>Z%uSt$0d1ig;1vQXr` zWudHZ1ziKW1GJ9(zfkP)ve|cjp~&?*==(vhE)>20e4+8bS)T{(1%1=Zw^R!M&6Q%u z2P%cn!(82XuT_e?e`fei8TvPsa?W=u<@|rB6nTG8DSrHk zng6-r`wLJH^uqv41D&@>?DyItIqw^bgzw)O`sO0x^Dm18r$1dJIQ#V?k$X{>a`N2^7@ebuu6F+-oMmh((5q;++VAfxVu;_@%GoC%gFxKa_)bd_4AepUARQ}UAIK`F9WTnI0L=(KImlT ze*xhWpuaM7FM{Y1;tRS5^k#tiDCie&5PYw!kv!8}Bj@g_5jlEmB(9Fuh@9tZ#9k9M zg0sJ^5xss`Bli8z8j)uSz_1Q9yi}eaUMg{s0$odSy;N{By;Su6Dd?{Kuf% z$lm68^K!`#yOzuIf#t>y%SE2^%jMh=&`%JqmkSaL6jq4J(A-gP<^>ItB`s>dT<5B=-u@|5_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ole6L0W0g)zVM2THlAlNY4@7q1ll6QJ0@ z^BdQ*zZ+(fO@7Dhz7*gD4t@X!VtSh9>EO2^e+dmxIi=${`DyY)zMqXw zC3rx$?FbdWh{-#3nNL}!pYG?6Qey-&>H~a$QvX0gbF0wLU35Qn$;1A~IK`;AWcp{y z(UQ4DOA{_EC$~F{$T4L;4i>(3l_TKLe*F2GD>hjS|eH1K~cp)z94-4?!^ z2@(OV617zFX}4VZExtVLCIjqdi?Rtw8tUohsD|9Y&HkQ?Ogb{N>0};$Zx;B9`?hcF Rhn_IWf&486bq=7Y{{^!xhI9Y` diff --git a/boards/locale/uk/LC_MESSAGES/django.po b/boards/locale/uk/LC_MESSAGES/django.po --- a/boards/locale/uk/LC_MESSAGES/django.po +++ b/boards/locale/uk/LC_MESSAGES/django.po @@ -622,3 +622,12 @@ msgstr "Стікери" msgid "Available by addresses:" msgstr "Доступно за адресами:" + +msgid "Local stickers" +msgstr "Локальні стікери" + +msgid "Global stickers" +msgstr "Глобальні стікери" + +msgid "Remove sticker" +msgstr "Видалити стікер" diff --git a/boards/locale/uk/LC_MESSAGES/djangojs.mo b/boards/locale/uk/LC_MESSAGES/djangojs.mo index 5f9713279012b06095bed1c2eb1f134cc80c4fcd..969e75f0458297132ae18f0b268270a157c673e8 GIT binary patch literal 1260 zc$}3|U2hvj6rIrWWdVYUH;}jyBBCl|cGFaZjooI6H?4&oTeedKZ(DofF06N~nRNwH zCE8S=K1AwE36Fq~cy^<>UujaQzhL$c@EhPCaK?7<3qr8c*)#XvbMHN~+TTx|{DI-g z0dE5_@G9_xO`bo1H-JBZ*MSprllaZKNzVfKHLwdl1zw$-^f$q;fWx^-UjiNh-vS>X zK6iq#cfnV{?|{DtzXkpcoCiMxFWJ4|3wF;*#tPsq@FnoCV2onVO?@I{F90uFkJFs> z_Y&|t@ZvPb{7#2r*$!jUY1IBoD7Geh{XrTfU8>8^^7%X~4f=7^4pX5?i%_+%vWg5l z5ZGc}>XZ_h(v}<~9o7_ytx!*B9d?CPG=;h*6bYrInrBfD>B(EOsp^v)^Q-@4RI~fGu`Kb-{936FZpz-=2gpQzNl>kxk{*0-cn(r z<1m%VqxH>7g*N{mn*A&sniIX&GV2Z-2pDZTO#avRPi@1Zd%KQN@X>U@=|qY z8d$BCtHJDkZr;hQ$s`pC)_v25AQfMyANJ!gN>-?SHB?%p#m&|_U!Li#tu3K=khG=! z;2tesiPBs>9;h(p>r(Z!M@fGi>f+fInjDMoC-1pVvFOsm0@*&hZ~-elkbd?d+C$OlBW+55sK#a6D&^ znIAEK4>-iip}B8H*mRiPIqt>OT^KqtPvB-+BhZM<1JKYsLe=I+|0*A1`Ayv50E_?j zINtG#y$T%QJ)VoP*5`dIoF{86*u>hO1-R!m*%`=>j%su-JX5Rl>GTUM1 M=|4OEe+3Ns3+>{}, {}'\ - ' 🔍 '\ + ' 🔍 '\ '' URL_VIEW = '
' \ '{}' \ @@ -100,10 +100,10 @@ def file_exists(filename): class AbstractViewer: - def __init__(self, file, file_type, hash, url): + def __init__(self, file, file_type, id, url): self.file = file self.file_type = file_type - self.hash = hash + self.id = id self.url = url self.extension = get_extension(self.file.name) @@ -122,7 +122,7 @@ class AbstractViewer: return ABSTRACT_VIEW.format(self.get_format_view(), self.file.url, self.file_type, filesizeformat(self.file.size), - self.file_type, search_url, self.file.name) + self.file_type, search_url, self.file.name, self.id) def get_format_view(self): image_name = PLAIN_FILE_FORMATS.get(self.extension, self.extension) @@ -193,7 +193,7 @@ class ImageViewer(AbstractViewer): return IMAGE_FORMAT_VIEW.format(CSS_CLASS_THUMB, thumb_url, - self.hash, + self.id, str(pre_width), str(pre_height), str(width), str(height), full=self.file.url, image_meta=metadata) diff --git a/boards/static/js/main.js b/boards/static/js/main.js --- a/boards/static/js/main.js +++ b/boards/static/js/main.js @@ -160,6 +160,7 @@ function addContextMenu() { var fileSearchUrl = $trigger.data('search-url'); var isImage = IMAGE_TYPES.indexOf($trigger.data('type')) > -1; var hasUrl = fileSearchUrl.length > 0; + var id = $trigger.data('id'); return { items: { duplicates: { @@ -188,8 +189,17 @@ function addContextMenu() { callback: function(key, opts) { window.location = 'http://tineye.com/search?url=' + fileSearchUrl; } + }, + addAlias: { + name: gettext('Add local sticker'), + callback: function(key, opts) { + var alias = prompt(gettext('Input sticker name')); + if (alias) { + window.location = '/stickers/?action=add&name=' + alias + '&id=' + id; + } + } } - }, + } }; } }); diff --git a/boards/templates/boards/aliases.html b/boards/templates/boards/aliases.html --- a/boards/templates/boards/aliases.html +++ b/boards/templates/boards/aliases.html @@ -10,11 +10,24 @@ {% block content %}
- {% for sticker in stickers %} - - {% endfor %} + {% if local_stickers %} +

{% trans "Local stickers" %}

+ {% for sticker in local_stickers %} + + {% endfor %} + {% endif %} + {% if global_stickers %} +

{% trans "Global stickers" %}

+ {% for sticker in global_stickers %} + + {% endfor %} + {% endif %}
{% endblock %} diff --git a/boards/templates/boards/settings.html b/boards/templates/boards/settings.html --- a/boards/templates/boards/settings.html +++ b/boards/templates/boards/settings.html @@ -24,6 +24,7 @@ {% else %}

{% trans 'No hidden tags.' %}

{% endif %} +

{% trans 'Stickers' %}

diff --git a/boards/views/api.py b/boards/views/api.py --- a/boards/views/api.py +++ b/boards/views/api.py @@ -195,7 +195,9 @@ def api_get_stickers(request): if not term: return HttpResponseBadRequest() - stickers = AttachmentSticker.objects.filter(name__contains=term) + global_stickers = AttachmentSticker.objects.filter(name__contains=term) + local_stickers = [sticker for sticker in get_settings_manager(request).get_stickers() if term in sticker.name] + stickers = list(global_stickers) + local_stickers image_dict = [{'thumb': sticker.attachment.get_thumb_url(), 'alias': sticker.name} diff --git a/boards/views/stickers.py b/boards/views/stickers.py --- a/boards/views/stickers.py +++ b/boards/views/stickers.py @@ -1,11 +1,13 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect -from boards.models.attachment import AttachmentSticker +from boards.abstracts.settingsmanager import get_settings_manager +from boards.models.attachment import AttachmentSticker, Attachment from boards.views.base import BaseBoardView -CONTEXT_STICKERS = 'stickers' +CONTEXT_GLOBAL_STICKERS = 'global_stickers' +CONTEXT_LOCAL_STICKERS = 'local_stickers' TEMPLATE = 'boards/aliases.html' @@ -13,13 +15,31 @@ TEMPLATE = 'boards/aliases.html' class AliasesView(BaseBoardView): @method_decorator(csrf_protect) def get(self, request, category=None): + result = self._process_creation(request) + if result: + return result + params = dict() if category: - params[CONTEXT_STICKERS] = AttachmentSticker.objects.filter( + params[CONTEXT_GLOBAL_STICKERS] = AttachmentSticker.objects.filter( name__startswith=(category + '/')) else: - params[CONTEXT_STICKERS] = AttachmentSticker.objects.all() + params[CONTEXT_GLOBAL_STICKERS] = AttachmentSticker.objects.all() + params[CONTEXT_LOCAL_STICKERS] = get_settings_manager(request).get_stickers() return render(request, TEMPLATE, params) + 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')