diff --git a/boards/context_processors.py b/boards/context_processors.py new file mode 100644 --- /dev/null +++ b/boards/context_processors.py @@ -0,0 +1,31 @@ +from boards import utils +from boards.models import Post +from boards.models.post import SETTING_MODERATE +import neboard + +__author__ = 'neko259' + + +def user_and_ui_processor(request): + context = {} + + user = utils.get_user(request) + context['user'] = user + context['tags'] = user.fav_tags.all() + context['posts_per_day'] = float(Post.objects.get_posts_per_day()) + + theme = utils.get_theme(request, user) + context['theme'] = theme + context['theme_css'] = 'css/' + theme + '/base_page.css' + + # This shows the moderator panel + moderate = user.get_setting(SETTING_MODERATE) + if moderate == 'True': + context['moderator'] = user.is_moderator() + else: + context['moderator'] = False + + context['version'] = neboard.settings.VERSION + context['site_name'] = neboard.settings.SITE_NAME + + return context \ No newline at end of file diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -9,7 +9,7 @@ from django.utils.translation import uge from boards.mdx_neboard import formatters from boards.models.post import TITLE_MAX_LENGTH -from boards.models import User, Post +from boards.models import User, Post, PostImage from neboard import settings from boards import utils import boards.settings as board_settings @@ -147,7 +147,7 @@ class PostForm(NeboardForm): for chunk in image.chunks(): md5.update(chunk) image_hash = md5.hexdigest() - if Post.objects.filter(image_hash=image_hash).exists(): + if PostImage.objects.filter(hash=image_hash).exists(): raise forms.ValidationError(ERROR_IMAGE_DUPLICATE) return image diff --git a/boards/locale/ru/LC_MESSAGES/django.mo b/boards/locale/ru/LC_MESSAGES/django.mo index 2b736cfb530f4f34f3b2a4013788800385e7cc59..782ec18751bb3beec2ca0120c7c64b8cbe958db3 GIT binary patch literal 7091 zc$|$_eQ;D)6~DEuB}*^?0u-?A#TJCNyUhk#=|X@&5{OMg%7)g~QRZd$C3&!UZ~NZc z(9E9mlu!AMH4ft&Wc4*NjfJ{-O1E?zwMw z3Crk%eZP0_J@?%6@jK_e{A$@vUlh1Lf!~Mm`{f6Ocn0|L%|cx-+#qdwe~jA)fp2Pj3s?bs8@L+yM=f{rA|aLnmn>qrJAf;I8-OBnus`3^;~xPdz@O^*xAb{$>vR5E!SQ%kkN*v< z0^S(meaj=P=k^Hizca#q-mP&nFhTK(aK4U4Sl{yzw)^D>=j+=Mw)ZDm&o6*C0)HK0 zzkaLF`8#ks@VyAzbN^zV-v-w7?t zTYxKp4+AgXAVe>)31eBsyy~vvcz>pf`Ea(1 z@%v;o`+c~Y{TRk=AMkZxE$~m(oX^`p`Zd6fOPP;*mhw5DTFUnHFJ=8_fqQ^o13m!! z18@h~y^QTUw2XQEG;kB~A9xq=hs!ule*xYJ{3q~Zz_rVHUlJH49xrFVUIi|v`d!X` zyt$m?_m0MQm$UvwH7r+G!*$tQ!|}>!9H?RcPStS!zEHz{e5;1_d|$8sT#tVPTnqdM zu%GgX;@=8@pIsbhtdEQ^iet!vgiu_v1JlU{{&#eVE z5RX@}-%qb%`B#9Ofp4s0y>9^@0{$8Jd*Fk&^8R(JIbZj#=JjS^lJdNo^Y^>e%)|GA z&A=KY`7rTf4e$TK8s$VbsF7-w z&LfVHKJw*u!CZJ)unxLz(nuUwq@VB5Nd7#C-#z$k(Q}kT;tlym`6nB93(h@Vw}|3J zyd>^-;CG+k`l5^KmwE-|iE3p<$sYYWQMEx=n_&JgE0H0-trb^a62JX|dkV$nfZ+P2 zo?3@ry_VZ6xL)ZxC^$FU1asnk{B{cFEycQB%WV|QL8_0Wo+IupEjhoX3$A~v;Z9ntlNrl4WtVFjM?Bf>xYCfec~s5D zL_<0)eWOP-WHQq4g-qHL4LQHpaXqoyuw_dJfo-P6ZYKj#^GRRqF|vND*O2{2#!4H$ z<=C>@uriR@Fz<<@v7FmGjNC%-Lzv#kwh)(v~lpEIhjE z1PLRpKBLE!eL2sUU8aOm(>2pE(PSH48O%G_%SUGo+sue&6UR4OF2s#g%JjU1*lT1m zraPcy#Xc*YHf?ehD;Su{>lQkM?}ei>*bJ-S`+84y4fv)fT5Kbmb)BqhkymitHBzw0 zlNM`?LBca#Uk*4qSLX02t+X_{oPH?x5v3FduGJ_pPYrTe1kg-K(Q4U8r0*a%S;vE< z(_`79onnzC6Wbl>2nYC1PUxIt?0A;% zxC0_-AQVZ{a8tbi-?!`@Pb7Ptqbd!_BUUyGMy%hMf;IjoPr9r)Cdn|Zk2HIxDUsH~ zx=3b`_yl%lvuW(3;NgxSr45{#bwEp3B*D2OCbT%Yo?cExlA_5RJ8F2)Nhb`b{UB2E zs0D^|kdgzoZ#*eFVJCjF&#PNH1%o$c4_U7;TYrPvk7c z=1xUN5>PkR(~DSL&B7w%Sj^KV^}-I^EzXHdJEkXX6!%>RnB|^r9taioYvzS+1{8q zm=y=X<%D?DuzWJ5&$7`Ku)7=P$P5)nMioIQ;F&4MPG2QJ*#eUU8A_+>uHd+_!c;%H zj%(OFVVi7GXe&~NerP6W(M7A1Mmp_Me0o8NE)&e_QoRqga}3X{5WeObjFp{XrU7;!k= z5A!pJjyi7IJ4Ch8;W~%Slpk$LM;}4n&;b*&qhZfO4SSp9BTWaAE&JOeRCul*ZS#7p zbaZ#F$BTA42^s0w-x*a+0h^+Ys_)d*#To{J0NQJbaRommbRv%hw)f#gmQqg zixN{4s*3N+W(>>TrfBS$e*MAD=IGX<92wSay3r;(<)p!rgxuO?`H_xH4k3*;qY-)u zX=l~YtKYm$@?-r*dwsmNzCJEDY>@O=yRJSSmpf&xOsMgW`nqswd;J!AR6A<7$7|(N zPw^JW)NaC_IQG@`J%8H9f10Q7253im@FFIz;2(z2G6I3gU`hn%3x1P9+V8>q+0dCm5xh>zP^4TI!E2B`&L`*) z!rc5h*l_~ma};Onz|zn1JOO8eCENrKlihP(3MvmqM>8s9tZUO>m zzlwEJl=fFtDCUrWL9(6fWvhWI;DRHQg6s*Nk37KBzVlpv>6B`LaTjv^E!c^=z_Fs1k~ ztLhX&6t(AyfgH}CWRjg{oy1tIkHF?4C&7+Wl=A1*fUUlctBUy(>bziznZ|q_BbqK; zQY3tZ2(POoCX01MSt9v)O*B}xj-=5Hke(5BxQ^hlkZ?-dRYwGKBKRs4g}ggMfhqAT zKSZ%2iFq|S8Wvf3iY<&`{v20+X;`Nc+*2r=Ln@@#3+Nkkn2Oy9+c2t%f2d?o@)#EB zXh}<E$t@S_-{jB)!IhF)(US3(bZ7 zaAHA6Ev4ppYR{^7Oj85MAJ>&ZFNTnOGsQD?(*f5f3nf%iOJzH}(sEgaVulMWe1%<9 zQ%W1MbnP3YyyI%>oO)~P`qo8zq0qT6l*X~3HM9?Kt^rR)#uynN5rf3?ub+%^#_`opF0SvITQ5DPxb$|sV% zol%{s&~#N#)1NQ+jS<@mA8x@&O#2D$pA5gOu6YL}cx7C97Y2mhy;oFv2ZWrwUf?uLFtK9A+8&qr z&+(T6ed(4Is3f=4hsQ`5yONHtT5EzLHJuAu{Wbvi!K}(L^_j(8)t8%e3Ra Dm>ZIb 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 @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-05-08 21:35+0300\n" +"POT-Creation-Date: 2014-06-15 12:34+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -98,27 +98,27 @@ msgstr "Подождите %s секунд после последнего постинга" msgid "Tags" msgstr "Теги" -#: forms.py:225 forms.py:344 +#: forms.py:224 forms.py:343 msgid "Inappropriate characters in tags." msgstr "Недопустимые символы в тегах." -#: forms.py:253 forms.py:274 +#: forms.py:252 forms.py:273 msgid "Captcha validation failed" msgstr "Проверка капчи провалена" -#: forms.py:280 +#: forms.py:279 msgid "Theme" msgstr "Тема" -#: forms.py:285 +#: forms.py:284 msgid "Enable moderation panel" msgstr "Включить панель модерации" -#: forms.py:300 +#: forms.py:299 msgid "No such user found" msgstr "Данный пользователь не найден" -#: forms.py:314 +#: forms.py:313 #, python-format msgid "Wait %s minutes after last login" msgstr "Подождите %s минут после последнего входа" @@ -147,41 +147,41 @@ msgstr "лицензией" msgid "Repository" msgstr "Репозиторий" -#: templates/boards/base.html:14 +#: templates/boards/base.html:11 msgid "Feed" msgstr "Лента" -#: templates/boards/base.html:31 +#: templates/boards/base.html:28 msgid "All threads" msgstr "Все темы" -#: templates/boards/base.html:36 +#: templates/boards/base.html:33 msgid "Tag management" msgstr "Управление тегами" -#: templates/boards/base.html:38 templates/boards/settings.html:7 +#: templates/boards/base.html:35 templates/boards/settings.html:7 msgid "Settings" msgstr "Настройки" -#: templates/boards/base.html:50 templates/boards/login.html:6 -#: templates/boards/login.html.py:21 +#: templates/boards/base.html:47 templates/boards/login.html:6 +#: templates/boards/login.html.py:16 msgid "Login" msgstr "Вход" -#: templates/boards/base.html:52 +#: templates/boards/base.html:48 +msgid "Search" +msgstr "Поиск" + +#: templates/boards/base.html:50 #, python-format msgid "Speed: %(ppd)s posts per day" msgstr "Скорость: %(ppd)s сообщений в день" -#: templates/boards/base.html:54 +#: templates/boards/base.html:52 msgid "Up" msgstr "Вверх" -#: templates/boards/login.html:15 -msgid "User ID" -msgstr "ID пользователя" - -#: templates/boards/login.html:24 +#: templates/boards/login.html:19 msgid "Insert your user id above" msgstr "Вставьте свой ID пользователя выше" @@ -386,5 +386,5 @@ msgstr "Перед этими тегами нужна новая строка:" msgid "Comment" msgstr "Комментарий" -#~ msgid "Archive" -#~ msgstr "Архив" +#~ msgid "User ID" +#~ msgstr "ID пользователя" diff --git a/boards/management/__init__.py b/boards/management/__init__.py new file mode 100644 --- /dev/null +++ b/boards/management/__init__.py @@ -0,0 +1,1 @@ +__author__ = 'vurdalak' diff --git a/boards/management/commands/__init__.py b/boards/management/commands/__init__.py new file mode 100644 --- /dev/null +++ b/boards/management/commands/__init__.py @@ -0,0 +1,1 @@ +__author__ = 'vurdalak' diff --git a/boards/management/commands/cleanusers.py b/boards/management/commands/cleanusers.py new file mode 100644 --- /dev/null +++ b/boards/management/commands/cleanusers.py @@ -0,0 +1,29 @@ +from datetime import datetime, timedelta +from django.core.management import BaseCommand +from django.db import transaction +from django.db.models import Count +from boards.models import User, Post + +__author__ = 'neko259' + +OLD_USER_AGE_DAYS = 90 + + +class Command(BaseCommand): + help = 'Removes empty users (that don\'t have posts or tags' + + @transaction.atomic + def handle(self, *args, **options): + old_registration_date = datetime.now().date() - timedelta( + OLD_USER_AGE_DAYS) + + old_users = User.objects.annotate(tags_count=Count('fav_tags')).filter( + tags_count=0).filter(registration_time__lt=old_registration_date) + deleted_users = 0 + for user in old_users: + if not Post.objects.filter(user=user).exists(): + self.stdout.write('Deleting user %s' % user.user_id) + user.delete() + deleted_users += 1 + + self.stdout.write('Deleted %d users' % deleted_users) \ No newline at end of file diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import markdown from markdown.inlinepatterns import Pattern, SubstituteTagPattern from markdown.util import etree @@ -12,6 +14,7 @@ REFLINK_PATTERN = r'((>>)(\d+))' SPOILER_PATTERN = r'%%([^(%%)]+)%%' COMMENT_PATTERN = r'^(//(.+))' STRIKETHROUGH_PATTERN = r'~(.+)~' +DASH_PATTERN = r'--' class TextFormatter(): @@ -144,6 +147,11 @@ class CodePattern(TextFormatter): format_left = ' ' +class DashPattern(Pattern): + def handleMatch(self, m): + return u'—' + + class NeboardMarkdown(markdown.Extension): def extendMarkdown(self, md, md_globals): self._add_neboard_patterns(md) @@ -162,6 +170,7 @@ class NeboardMarkdown(markdown.Extension spoiler = SpoilerPattern(SPOILER_PATTERN, md) comment = CommentPattern(COMMENT_PATTERN, md) strikethrough = StrikeThroughPattern(STRIKETHROUGH_PATTERN, md) + dash = DashPattern(DASH_PATTERN, md) md.inlinePatterns[u'autolink_ext'] = autolink md.inlinePatterns[u'spoiler'] = spoiler @@ -169,6 +178,7 @@ class NeboardMarkdown(markdown.Extension md.inlinePatterns[u'comment'] = comment md.inlinePatterns[u'reflink'] = reflink md.inlinePatterns[u'quote'] = quote + md.inlinePatterns[u'dash'] = dash def make_extension(configs=None): diff --git a/boards/middlewares.py b/boards/middlewares.py --- a/boards/middlewares.py +++ b/boards/middlewares.py @@ -1,8 +1,9 @@ from django.shortcuts import redirect -from boards import views, utils +from boards import utils from boards.models import Ban from django.utils.html import strip_spaces_between_tags from django.conf import settings +from boards.views.banned import BannedView RESPONSE_CONTENT_TYPE = 'Content-Type' @@ -17,7 +18,7 @@ class BanMiddleware: def process_view(self, request, view_func, view_args, view_kwargs): - if view_func != views.banned.BannedView.as_view: + if view_func != BannedView.as_view: ip = utils.get_client_ip(request) bans = Ban.objects.filter(ip=ip) diff --git a/boards/migrations/0026_auto__add_postimage.py b/boards/migrations/0026_auto__add_postimage.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0026_auto__add_postimage.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Adding model 'PostImage' + db.create_table(u'boards_postimage', ( + (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ('width', self.gf('django.db.models.fields.IntegerField')(default=0)), + ('height', self.gf('django.db.models.fields.IntegerField')(default=0)), + ('pre_width', self.gf('django.db.models.fields.IntegerField')(default=0)), + ('pre_height', self.gf('django.db.models.fields.IntegerField')(default=0)), + ('image', self.gf('boards.thumbs.ImageWithThumbsField')(max_length=100, blank=True)), + ('hash', self.gf('django.db.models.fields.CharField')(max_length=36)), + )) + db.send_create_signal('boards', ['PostImage']) + + # Adding M2M table for field images on 'Post' + m2m_table_name = db.shorten_name(u'boards_post_images') + db.create_table(m2m_table_name, ( + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), + ('post', models.ForeignKey(orm['boards.post'], null=False)), + ('postimage', models.ForeignKey(orm['boards.postimage'], null=False)) + )) + db.create_unique(m2m_table_name, ['post_id', 'postimage_id']) + + + def backwards(self, orm): + # Deleting model 'PostImage' + db.delete_table(u'boards_postimage') + + # Removing M2M table for field images on 'Post' + db.delete_table(db.shorten_name(u'boards_post_images')) + + + models = { + 'boards.ban': { + 'Meta': {'object_name': 'Ban'}, + 'can_read': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'reason': ('django.db.models.fields.CharField', [], {'default': "'Auto'", 'max_length': '200'}) + }, + 'boards.post': { + 'Meta': {'ordering': "('id',)", 'object_name': 'Post'}, + '_text_rendered': ('django.db.models.fields.TextField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), + 'image_hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), + 'image_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'images': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'ip+'", 'to': "orm['boards.PostImage']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), + 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), + 'referenced_posts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'rfp+'", 'to': "orm['boards.Post']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'refmap': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), + 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'markdown'", 'max_length': '30'}), + 'thread_new': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.Thread']", 'null': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.User']", 'null': 'True'}) + }, + 'boards.postimage': { + 'Meta': {'ordering': "('id',)", 'object_name': 'PostImage'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), + 'hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), + 'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'width': ('django.db.models.fields.IntegerField', [], {'default': '0'}) + }, + 'boards.setting': { + 'Meta': {'object_name': 'Setting'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.User']"}), + 'value': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'boards.tag': { + 'Meta': {'ordering': "('name',)", 'object_name': 'Tag'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'linked': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'}), + 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tag+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Thread']"}) + }, + 'boards.thread': { + 'Meta': {'object_name': 'Thread'}, + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'bump_time': ('django.db.models.fields.DateTimeField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tre+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['boards.Tag']", 'symmetrical': 'False'}) + }, + 'boards.user': { + 'Meta': {'object_name': 'User'}, + 'fav_tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'fav_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'hidden_tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'ht+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Tag']"}), + 'hidden_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'hth+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'rank': ('django.db.models.fields.IntegerField', [], {}), + 'registration_time': ('django.db.models.fields.DateTimeField', [], {}), + 'user_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + } + } + + complete_apps = ['boards'] \ No newline at end of file diff --git a/boards/migrations/0027_image_field_to_model.py b/boards/migrations/0027_image_field_to_model.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0027_image_field_to_model.py @@ -0,0 +1,110 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import DataMigration +from django.db import models + + +class Migration(DataMigration): + + def forwards(self, orm): + for post in orm['boards.Post'].objects.all(): + if post.image: + image = orm['boards.PostImage']() + + image.width = post.image_width + image.height = post.image_height + + image.pre_width = post.image_pre_width + image.pre_height = post.image_pre_height + + image.image = post.image + image.hash = post.image_hash + + image.save() + + post.images.add(image) + post.save() + + def backwards(self, orm): + "Write your backwards methods here." + + models = { + 'boards.ban': { + 'Meta': {'object_name': 'Ban'}, + 'can_read': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'reason': ('django.db.models.fields.CharField', [], {'default': "'Auto'", 'max_length': '200'}) + }, + 'boards.post': { + 'Meta': {'ordering': "('id',)", 'object_name': 'Post'}, + '_text_rendered': ('django.db.models.fields.TextField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), + 'image_hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), + 'image_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'image_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'images': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'ip+'", 'to': "orm['boards.PostImage']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), + 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), + 'referenced_posts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'rfp+'", 'to': "orm['boards.Post']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'refmap': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), + 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'markdown'", 'max_length': '30'}), + 'thread_new': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.Thread']", 'null': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.User']", 'null': 'True'}) + }, + 'boards.postimage': { + 'Meta': {'ordering': "('id',)", 'object_name': 'PostImage'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), + 'hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), + 'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'width': ('django.db.models.fields.IntegerField', [], {'default': '0'}) + }, + 'boards.setting': { + 'Meta': {'object_name': 'Setting'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.User']"}), + 'value': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'boards.tag': { + 'Meta': {'ordering': "('name',)", 'object_name': 'Tag'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'linked': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'}), + 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tag+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Thread']"}) + }, + 'boards.thread': { + 'Meta': {'object_name': 'Thread'}, + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'bump_time': ('django.db.models.fields.DateTimeField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tre+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['boards.Tag']", 'symmetrical': 'False'}) + }, + 'boards.user': { + 'Meta': {'object_name': 'User'}, + 'fav_tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'fav_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'hidden_tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'ht+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Tag']"}), + 'hidden_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'hth+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'rank': ('django.db.models.fields.IntegerField', [], {}), + 'registration_time': ('django.db.models.fields.DateTimeField', [], {}), + 'user_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + } + } + + complete_apps = ['boards'] + symmetrical = True diff --git a/boards/migrations/0028_auto__del_field_post_image_pre_height__del_field_post_image__del_field.py b/boards/migrations/0028_auto__del_field_post_image_pre_height__del_field_post_image__del_field.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0028_auto__del_field_post_image_pre_height__del_field_post_image__del_field.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Deleting field 'Post.image_pre_height' + db.delete_column(u'boards_post', 'image_pre_height') + + # Deleting field 'Post.image' + db.delete_column(u'boards_post', 'image') + + # Deleting field 'Post.image_pre_width' + db.delete_column(u'boards_post', 'image_pre_width') + + # Deleting field 'Post.image_width' + db.delete_column(u'boards_post', 'image_width') + + # Deleting field 'Post.image_height' + db.delete_column(u'boards_post', 'image_height') + + # Deleting field 'Post.image_hash' + db.delete_column(u'boards_post', 'image_hash') + + + def backwards(self, orm): + # Adding field 'Post.image_pre_height' + db.add_column(u'boards_post', 'image_pre_height', + self.gf('django.db.models.fields.IntegerField')(default=0), + keep_default=False) + + + # User chose to not deal with backwards NULL issues for 'Post.image' + raise RuntimeError("Cannot reverse this migration. 'Post.image' and its values cannot be restored.") + + # The following code is provided here to aid in writing a correct migration # Adding field 'Post.image' + db.add_column(u'boards_post', 'image', + self.gf('boards.thumbs.ImageWithThumbsField')(max_length=100, blank=True), + keep_default=False) + + # Adding field 'Post.image_pre_width' + db.add_column(u'boards_post', 'image_pre_width', + self.gf('django.db.models.fields.IntegerField')(default=0), + keep_default=False) + + # Adding field 'Post.image_width' + db.add_column(u'boards_post', 'image_width', + self.gf('django.db.models.fields.IntegerField')(default=0), + keep_default=False) + + # Adding field 'Post.image_height' + db.add_column(u'boards_post', 'image_height', + self.gf('django.db.models.fields.IntegerField')(default=0), + keep_default=False) + + + # User chose to not deal with backwards NULL issues for 'Post.image_hash' + raise RuntimeError("Cannot reverse this migration. 'Post.image_hash' and its values cannot be restored.") + + # The following code is provided here to aid in writing a correct migration # Adding field 'Post.image_hash' + db.add_column(u'boards_post', 'image_hash', + self.gf('django.db.models.fields.CharField')(max_length=36), + keep_default=False) + + + models = { + 'boards.ban': { + 'Meta': {'object_name': 'Ban'}, + 'can_read': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'reason': ('django.db.models.fields.CharField', [], {'default': "'Auto'", 'max_length': '200'}) + }, + 'boards.post': { + 'Meta': {'ordering': "('id',)", 'object_name': 'Post'}, + '_text_rendered': ('django.db.models.fields.TextField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'images': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'ip+'", 'to': "orm['boards.PostImage']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'poster_ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39'}), + 'poster_user_agent': ('django.db.models.fields.TextField', [], {}), + 'pub_time': ('django.db.models.fields.DateTimeField', [], {}), + 'referenced_posts': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'rfp+'", 'to': "orm['boards.Post']", 'blank': 'True', 'symmetrical': 'False', 'null': 'True', 'db_index': 'True'}), + 'refmap': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'text': ('markupfield.fields.MarkupField', [], {'rendered_field': 'True'}), + 'text_markup_type': ('django.db.models.fields.CharField', [], {'default': "'markdown'", 'max_length': '30'}), + 'thread_new': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.Thread']", 'null': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': "orm['boards.User']", 'null': 'True'}) + }, + 'boards.postimage': { + 'Meta': {'ordering': "('id',)", 'object_name': 'PostImage'}, + 'hash': ('django.db.models.fields.CharField', [], {'max_length': '36'}), + 'height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'image': ('boards.thumbs.ImageWithThumbsField', [], {'max_length': '100', 'blank': 'True'}), + 'pre_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'pre_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'width': ('django.db.models.fields.IntegerField', [], {'default': '0'}) + }, + 'boards.setting': { + 'Meta': {'object_name': 'Setting'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.User']"}), + 'value': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'boards.tag': { + 'Meta': {'ordering': "('name',)", 'object_name': 'Tag'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'linked': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'}), + 'threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tag+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Thread']"}) + }, + 'boards.thread': { + 'Meta': {'object_name': 'Thread'}, + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'bump_time': ('django.db.models.fields.DateTimeField', [], {}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_edit_time': ('django.db.models.fields.DateTimeField', [], {}), + 'replies': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'tre+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['boards.Tag']", 'symmetrical': 'False'}) + }, + 'boards.user': { + 'Meta': {'object_name': 'User'}, + 'fav_tags': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['boards.Tag']", 'null': 'True', 'blank': 'True'}), + 'fav_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + 'hidden_tags': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'ht+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Tag']"}), + 'hidden_threads': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'hth+'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['boards.Post']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'rank': ('django.db.models.fields.IntegerField', [], {}), + 'registration_time': ('django.db.models.fields.DateTimeField', [], {}), + 'user_id': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + } + } + + complete_apps = ['boards'] \ No newline at end of file diff --git a/boards/models/__init__.py b/boards/models/__init__.py --- a/boards/models/__init__.py +++ b/boards/models/__init__.py @@ -1,7 +1,8 @@ __author__ = 'neko259' +from boards.models.image import PostImage +from boards.models.thread import Thread from boards.models.post import Post -from boards.models.post import Thread from boards.models.tag import Tag from boards.models.user import Ban from boards.models.user import Setting diff --git a/boards/models/base.py b/boards/models/base.py new file mode 100644 --- /dev/null +++ b/boards/models/base.py @@ -0,0 +1,10 @@ +__author__ = 'neko259' + + +class Viewable(): + def __init__(self): + pass + + def get_view(self, *args, **kwargs): + """Get an HTML view for a model""" + pass \ No newline at end of file diff --git a/boards/models/image.py b/boards/models/image.py new file mode 100644 --- /dev/null +++ b/boards/models/image.py @@ -0,0 +1,60 @@ +import hashlib +import os +from random import random +import time +from django.db import models +from boards import thumbs + +__author__ = 'neko259' + + +IMAGE_THUMB_SIZE = (200, 150) +IMAGES_DIRECTORY = 'images/' +FILE_EXTENSION_DELIMITER = '.' + + +class PostImage(models.Model): + class Meta: + app_label = 'boards' + ordering = ('id',) + + @staticmethod + def _update_image_filename(filename): + """ + Gets unique image filename + """ + + path = IMAGES_DIRECTORY + new_name = str(int(time.mktime(time.gmtime()))) + new_name += str(int(random() * 1000)) + new_name += FILE_EXTENSION_DELIMITER + new_name += filename.split(FILE_EXTENSION_DELIMITER)[-1:][0] + + return os.path.join(path, new_name) + + width = models.IntegerField(default=0) + height = models.IntegerField(default=0) + + pre_width = models.IntegerField(default=0) + pre_height = models.IntegerField(default=0) + + image = thumbs.ImageWithThumbsField(upload_to=_update_image_filename, + blank=True, sizes=(IMAGE_THUMB_SIZE,), + width_field='width', + height_field='height', + preview_width_field='pre_width', + preview_height_field='pre_height') + hash = models.CharField(max_length=36) + + def save(self, *args, **kwargs): + """ + Saves the model and computes the image hash for deduplication purposes. + """ + + if not self.pk and self.image: + md5 = hashlib.md5() + for chunk in self.image.chunks(): + md5.update(chunk) + self.hash = md5.hexdigest() + super(PostImage, self).save(*args, **kwargs) + diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -10,9 +10,13 @@ import hashlib from django.core.cache import cache from django.core.urlresolvers import reverse from django.db import models, transaction +from django.template.loader import render_to_string from django.utils import timezone from markupfield.fields import MarkupField +from boards.models import PostImage +from boards.models.base import Viewable +from boards.models.thread import Thread from neboard import settings from boards import thumbs @@ -21,7 +25,6 @@ APP_LABEL_BOARDS = 'boards' CACHE_KEY_PPD = 'ppd' CACHE_KEY_POST_URL = 'post_url' -CACHE_KEY_OPENING_POST = 'opening_post_id' POSTS_PER_DAY_RANGE = range(7) @@ -33,10 +36,20 @@ TITLE_MAX_LENGTH = 200 DEFAULT_MARKUP_TYPE = 'markdown' +# TODO This should be removed when no code relies on it because thread id field +# was removed a long time ago NO_PARENT = -1 + +# TODO This should be removed NO_IP = '0.0.0.0' + +# TODO Real user agent should be saved instead of this UNKNOWN_UA = '' + +# TODO This should be checked for usage and removed because a nativa +# paginator is used now ALL_PAGES = -1 + IMAGES_DIRECTORY = 'images/' FILE_EXTENSION_DELIMITER = '.' @@ -70,13 +83,18 @@ class PostManager(models.Manager): text=text, pub_time=posting_time, thread_new=thread, - image=image, poster_ip=ip, poster_user_agent=UNKNOWN_UA, # TODO Get UA at # last! last_edit_time=posting_time, user=user) + if image: + post_image = PostImage.objects.create(image=image) + post.images.add(post_image) + logger.info('Created image #%d for post #%d' % (post_image.id, + post.id)) + thread.replies.add(post) if tags: linked_tags = [] @@ -124,6 +142,9 @@ class PostManager(models.Manager): map(self.delete_post, posts) # TODO Move this method to thread manager + # TODO Rename it, because the threads are archived instead of plain + # removal. Split the delete and archive methods and make a setting to + # enable or disable archiving. def _delete_old_threads(self): """ Preserves maximum thread count. If there are too many threads, @@ -193,7 +214,7 @@ class PostManager(models.Manager): return ppd -class Post(models.Model): +class Post(models.Model, Viewable): """A post is a message.""" objects = PostManager() @@ -202,38 +223,13 @@ class Post(models.Model): app_label = APP_LABEL_BOARDS ordering = ('id',) - # TODO Save original file name to some field - def _update_image_filename(self, filename): - """ - Gets unique image filename - """ - - path = IMAGES_DIRECTORY - new_name = str(int(time.mktime(time.gmtime()))) - new_name += str(int(random() * 1000)) - new_name += FILE_EXTENSION_DELIMITER - new_name += filename.split(FILE_EXTENSION_DELIMITER)[-1:][0] - - return os.path.join(path, new_name) - title = models.CharField(max_length=TITLE_MAX_LENGTH) pub_time = models.DateTimeField() text = MarkupField(default_markup_type=DEFAULT_MARKUP_TYPE, escape_html=False) - image_width = models.IntegerField(default=0) - image_height = models.IntegerField(default=0) - - image_pre_width = models.IntegerField(default=0) - image_pre_height = models.IntegerField(default=0) - - image = thumbs.ImageWithThumbsField(upload_to=_update_image_filename, - blank=True, sizes=(IMAGE_THUMB_SIZE,), - width_field='image_width', - height_field='image_height', - preview_width_field='image_pre_width', - preview_height_field='image_pre_height') - image_hash = models.CharField(max_length=36) + images = models.ManyToManyField(PostImage, null=True, blank=True, + related_name='ip+', db_index=True) poster_ip = models.GenericIPAddressField() poster_user_agent = models.TextField() @@ -289,18 +285,6 @@ class Post(models.Model): return self.get_thread().get_opening_post_id() == self.id - def save(self, *args, **kwargs): - """ - Saves the model and computes the image hash for deduplication purposes. - """ - - if not self.pk and self.image: - md5 = hashlib.md5() - for chunk in self.image.chunks(): - md5.update(chunk) - self.image_hash = md5.hexdigest() - super(Post, self).save(*args, **kwargs) - @transaction.atomic def add_tag(self, tag): edit_time = timezone.now() @@ -359,145 +343,39 @@ class Post(models.Model): def get_referenced_posts(self): return self.referenced_posts.only('id', 'thread_new') - -class Thread(models.Model): - - class Meta: - app_label = APP_LABEL_BOARDS - - tags = models.ManyToManyField('Tag') - bump_time = models.DateTimeField() - last_edit_time = models.DateTimeField() - replies = models.ManyToManyField('Post', symmetrical=False, null=True, - blank=True, related_name='tre+') - archived = models.BooleanField(default=False) - - def get_tags(self): - """ - Gets a sorted tag list. - """ - - return self.tags.order_by('name') - - def bump(self): - """ - Bumps (moves to up) thread if possible. - """ - - if self.can_bump(): - self.bump_time = timezone.now() - - logger.info('Bumped thread %d' % self.id) - - def get_reply_count(self): - return self.replies.count() + def get_text(self): + return self.text - def get_images_count(self): - return self.replies.filter(image_width__gt=0).count() - - def can_bump(self): - """ - Checks if the thread can be bumped by replying to it. - """ - - if self.archived: - return False - - post_count = self.get_reply_count() - - return post_count < settings.MAX_POSTS_PER_THREAD + def get_view(self, moderator=False, need_open_link=False, + truncated=False, *args, **kwargs): + if 'is_opening' in kwargs: + is_opening = kwargs['is_opening'] + else: + is_opening = self.is_opening() - def delete_with_posts(self): - """ - Completely deletes thread and all its posts - """ - - if self.replies.exists(): - self.replies.all().delete() - - self.delete() - - def get_last_replies(self): - """ - Gets several last replies, not including opening post - """ - - if settings.LAST_REPLIES_COUNT > 0: - reply_count = self.get_reply_count() + if 'thread' in kwargs: + thread = kwargs['thread'] + else: + thread = self.get_thread() - if reply_count > 0: - reply_count_to_show = min(settings.LAST_REPLIES_COUNT, - reply_count - 1) - last_replies = self.replies.order_by( - 'pub_time').defer('image_hash', 'poster_user_agent', - 'text_markup_type')[ - reply_count - reply_count_to_show:] - - return last_replies - - def get_skipped_replies_count(self): - """ - Gets number of posts between opening post and last replies. - """ - reply_count = self.get_reply_count() - last_replies_count = min(settings.LAST_REPLIES_COUNT, - reply_count - 1) - return reply_count - last_replies_count - 1 + if 'can_bump' in kwargs: + can_bump = kwargs['can_bump'] + else: + can_bump = thread.can_bump() - def get_replies(self, view_fields_only=False): - """ - Gets sorted thread posts - """ - - query = self.replies.order_by('pub_time') - if view_fields_only: - query = query.defer( - 'image_hash', 'poster_user_agent', 'text_markup_type') - return query.all() - - def add_tag(self, tag): - """ - Connects thread to a tag and tag to a thread - """ - - self.tags.add(tag) - tag.threads.add(self) + opening_post_id = thread.get_opening_post_id() - def remove_tag(self, tag): - self.tags.remove(tag) - tag.threads.remove(self) - - def get_opening_post(self, only_id=False): - """ - Gets the first post of the thread - """ - - query = self.replies.order_by('pub_time') - if only_id: - query = query.only('id') - opening_post = query.first() - - return opening_post + return render_to_string('boards/post.html', { + 'post': self, + 'moderator': moderator, + 'is_opening': is_opening, + 'thread': thread, + 'bumpable': can_bump, + 'need_open_link': need_open_link, + 'truncated': truncated, + 'opening_post_id': opening_post_id, + }) - def get_opening_post_id(self): - """ - Gets ID of the first thread post. - """ - - cache_key = CACHE_KEY_OPENING_POST + str(self.id) - opening_post_id = cache.get(cache_key) - if not opening_post_id: - opening_post_id = self.get_opening_post(only_id=True).id - cache.set(cache_key, opening_post_id) + def get_first_image(self): + return self.images.earliest('id') - return opening_post_id - - def __unicode__(self): - return str(self.id) - - def get_pub_time(self): - """ - Gets opening post's pub time because thread does not have its own one. - """ - - return self.get_opening_post().pub_time diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -1,9 +1,13 @@ +from django.template.loader import render_to_string from boards.models import Thread, Post from django.db import models from django.db.models import Count, Sum +from django.core.urlresolvers import reverse +from boards.models.base import Viewable __author__ = 'neko259' +# TODO Tag popularity ratings are not used any more, remove all of this MAX_TAG_FONT = 1 MIN_TAG_FONT = 0.2 @@ -20,13 +24,12 @@ class TagManager(models.Manager): """ tags = self.annotate(Count('threads')) \ - .filter(threads__count__gt=0).filter(threads__archived=False) \ - .order_by('name') + .filter(threads__count__gt=0).order_by('name') return tags -class Tag(models.Model): +class Tag(models.Model, Viewable): """ A tag is a text node assigned to the thread. The tag serves as a board section. There can be multiple tags for each thread @@ -56,6 +59,7 @@ class Tag(models.Model): def get_thread_count(self): return self.threads.count() + # TODO Remove, not used any more def get_popularity(self): """ Gets tag's popularity value as a percentage of overall board post @@ -97,6 +101,7 @@ class Tag(models.Model): linked_tag.get_linked_tags_list(tag_list) + # TODO Remove def get_font_value(self): """ Gets tag font value to differ most popular tags in the list @@ -126,3 +131,11 @@ class Tag(models.Model): posts_count = 0 return posts_count + + def get_url(self): + return reverse('tag', kwargs={'tag_name': self.name}) + + def get_view(self, *args, **kwargs): + return render_to_string('boards/tag.html', { + 'tag': self, + }) diff --git a/boards/models/thread.py b/boards/models/thread.py new file mode 100644 --- /dev/null +++ b/boards/models/thread.py @@ -0,0 +1,163 @@ +import logging +from django.db.models import Count +from django.utils import timezone +from django.core.cache import cache +from django.db import models +from neboard import settings + +__author__ = 'neko259' + + +logger = logging.getLogger(__name__) + + +CACHE_KEY_OPENING_POST = 'opening_post_id' + + +class Thread(models.Model): + + class Meta: + app_label = 'boards' + + tags = models.ManyToManyField('Tag') + bump_time = models.DateTimeField() + last_edit_time = models.DateTimeField() + replies = models.ManyToManyField('Post', symmetrical=False, null=True, + blank=True, related_name='tre+') + archived = models.BooleanField(default=False) + + def get_tags(self): + """ + Gets a sorted tag list. + """ + + return self.tags.order_by('name') + + def bump(self): + """ + Bumps (moves to up) thread if possible. + """ + + if self.can_bump(): + self.bump_time = timezone.now() + + logger.info('Bumped thread %d' % self.id) + + def get_reply_count(self): + return self.replies.count() + + def get_images_count(self): + # TODO Use sum + total_count = 0 + for post_with_image in self.replies.annotate(images_count=Count( + 'images')): + total_count += post_with_image.images_count + return total_count + + def can_bump(self): + """ + Checks if the thread can be bumped by replying to it. + """ + + if self.archived: + return False + + post_count = self.get_reply_count() + + return post_count < settings.MAX_POSTS_PER_THREAD + + def delete_with_posts(self): + """ + Completely deletes thread and all its posts + """ + + if self.replies.exists(): + self.replies.all().delete() + + self.delete() + + def get_last_replies(self): + """ + Gets several last replies, not including opening post + """ + + if settings.LAST_REPLIES_COUNT > 0: + reply_count = self.get_reply_count() + + if reply_count > 0: + reply_count_to_show = min(settings.LAST_REPLIES_COUNT, + reply_count - 1) + replies = self.get_replies() + last_replies = replies[reply_count - reply_count_to_show:] + + return last_replies + + def get_skipped_replies_count(self): + """ + Gets number of posts between opening post and last replies. + """ + reply_count = self.get_reply_count() + last_replies_count = min(settings.LAST_REPLIES_COUNT, + reply_count - 1) + return reply_count - last_replies_count - 1 + + def get_replies(self, view_fields_only=False): + """ + Gets sorted thread posts + """ + + query = self.replies.order_by('pub_time').prefetch_related('images') + if view_fields_only: + query = query.defer('poster_user_agent', 'text_markup_type') + return query.all() + + def get_replies_with_images(self, view_fields_only=False): + return self.get_replies(view_fields_only).annotate(images_count=Count( + 'images')).filter(images_count__gt=0) + + def add_tag(self, tag): + """ + Connects thread to a tag and tag to a thread + """ + + self.tags.add(tag) + tag.threads.add(self) + + def remove_tag(self, tag): + self.tags.remove(tag) + tag.threads.remove(self) + + def get_opening_post(self, only_id=False): + """ + Gets the first post of the thread + """ + + query = self.replies.order_by('pub_time') + if only_id: + query = query.only('id') + opening_post = query.first() + + return opening_post + + def get_opening_post_id(self): + """ + Gets ID of the first thread post. + """ + + cache_key = CACHE_KEY_OPENING_POST + str(self.id) + opening_post_id = cache.get(cache_key) + if not opening_post_id: + opening_post_id = self.get_opening_post(only_id=True).id + cache.set(cache_key, opening_post_id) + + return opening_post_id + + def __unicode__(self): + return str(self.id) + + def get_pub_time(self): + """ + Gets opening post's pub time because thread does not have its own one. + """ + + return self.get_opening_post().pub_time diff --git a/boards/search_indexes.py b/boards/search_indexes.py new file mode 100644 --- /dev/null +++ b/boards/search_indexes.py @@ -0,0 +1,24 @@ +from haystack import indexes +from boards.models import Post, Tag + +__author__ = 'neko259' + + +class PostIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return Post + + def index_queryset(self, using=None): + return self.get_model().objects.all() + + +class TagIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return Tag + + def index_queryset(self, using=None): + return self.get_model().objects.get_not_empty_tags() diff --git a/boards/static/css/3party/highlight.css b/boards/static/css/3party/highlight.css new file mode 100644 --- /dev/null +++ b/boards/static/css/3party/highlight.css @@ -0,0 +1,1 @@ +.hljs{display:block;padding:.5em;background:#f0f0f0}.hljs,.hljs-subst,.hljs-tag .hljs-title,.lisp .hljs-title,.clojure .hljs-built_in,.nginx .hljs-title{color:black}.hljs-string,.hljs-title,.hljs-constant,.hljs-parent,.hljs-tag .hljs-value,.hljs-rules .hljs-value,.hljs-rules .hljs-value .hljs-number,.hljs-preprocessor,.hljs-pragma,.haml .hljs-symbol,.ruby .hljs-symbol,.ruby .hljs-symbol .hljs-string,.hljs-aggregate,.hljs-template_tag,.django .hljs-variable,.smalltalk .hljs-class,.hljs-addition,.hljs-flow,.hljs-stream,.bash .hljs-variable,.apache .hljs-tag,.apache .hljs-cbracket,.tex .hljs-command,.tex .hljs-special,.erlang_repl .hljs-function_or_atom,.asciidoc .hljs-header,.markdown .hljs-header,.coffeescript .hljs-attribute{color:#800}.smartquote,.hljs-comment,.hljs-annotation,.hljs-template_comment,.diff .hljs-header,.hljs-chunk,.asciidoc .hljs-blockquote,.markdown .hljs-blockquote{color:#888}.hljs-number,.hljs-date,.hljs-regexp,.hljs-literal,.hljs-hexcolor,.smalltalk .hljs-symbol,.smalltalk .hljs-char,.go .hljs-constant,.hljs-change,.lasso .hljs-variable,.makefile .hljs-variable,.asciidoc .hljs-bullet,.markdown .hljs-bullet,.asciidoc .hljs-link_url,.markdown .hljs-link_url{color:#080}.hljs-label,.hljs-javadoc,.ruby .hljs-string,.hljs-decorator,.hljs-filter .hljs-argument,.hljs-localvars,.hljs-array,.hljs-attr_selector,.hljs-important,.hljs-pseudo,.hljs-pi,.haml .hljs-bullet,.hljs-doctype,.hljs-deletion,.hljs-envvar,.hljs-shebang,.apache .hljs-sqbracket,.nginx .hljs-built_in,.tex .hljs-formula,.erlang_repl .hljs-reserved,.hljs-prompt,.asciidoc .hljs-link_label,.markdown .hljs-link_label,.vhdl .hljs-attribute,.clojure .hljs-attribute,.asciidoc .hljs-attribute,.lasso .hljs-attribute,.coffeescript .hljs-property,.hljs-phony{color:#88F}.hljs-keyword,.hljs-id,.hljs-title,.hljs-built_in,.hljs-aggregate,.css .hljs-tag,.hljs-javadoctag,.hljs-phpdoc,.hljs-yardoctag,.smalltalk .hljs-class,.hljs-winutils,.bash .hljs-variable,.apache .hljs-tag,.go .hljs-typename,.tex .hljs-command,.asciidoc .hljs-strong,.markdown .hljs-strong,.hljs-request,.hljs-status{font-weight:bold}.asciidoc .hljs-emphasis,.markdown .hljs-emphasis{font-style:italic}.nginx .hljs-built_in{font-weight:normal}.coffeescript .javascript,.javascript .xml,.lasso .markup,.tex .hljs-formula,.xml .javascript,.xml .vbscript,.xml .css,.xml .hljs-cdata{opacity:.5} \ No newline at end of file diff --git a/boards/static/css/base.css b/boards/static/css/base.css --- a/boards/static/css/base.css +++ b/boards/static/css/base.css @@ -73,4 +73,9 @@ textarea, input { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; -} \ No newline at end of file +} + +.compact-form-text > textarea { + height: 100px; + width: 100%; +} diff --git a/boards/static/css/md/base_page.css b/boards/static/css/md/base_page.css --- a/boards/static/css/md/base_page.css +++ b/boards/static/css/md/base_page.css @@ -12,14 +12,6 @@ body { color: #00FF00 } -.input_field { - -} - -.input_field_name { - -} - .input_field_error { color: #FF0000; } @@ -39,9 +31,7 @@ body { } .tag { - /*color: #F5FFC9;*/ color: #FFD37D; - /*color: #b4cfec;*/ } .post_id { @@ -165,7 +155,7 @@ p { margin-bottom: 0.5ex; } -input[type="submit"] { +.post-form input[type="submit"], input[type="submit"] { background: #222; border: solid 2px #fff; color: #fff; @@ -413,3 +403,19 @@ pre { margin: 0.2ex; padding: 0.1ex; } + +#id_models li { + list-style: none; +} + +#id_q { + margin-left: 1ex; +} + +ul { + padding-left: 0px; +} + +.post_preview { + border: solid 2px white; +} diff --git a/boards/static/css/sw/base_page.css b/boards/static/css/sw/base_page.css --- a/boards/static/css/sw/base_page.css +++ b/boards/static/css/sw/base_page.css @@ -360,4 +360,12 @@ li { .swappable-form-full > form { display: table; width: 100%; -} \ No newline at end of file +} + +#id_models li { + list-style: none; +} + +#id_q { + margin-left: 1ex; +} diff --git a/boards/static/js/3party/highlight.min.js b/boards/static/js/3party/highlight.min.js new file mode 100644 --- /dev/null +++ b/boards/static/js/3party/highlight.min.js @@ -0,0 +1,1 @@ +var hljs=new function(){function k(v){return v.replace(/&/gm,"&").replace(//gm,">")}function t(v){return v.nodeName.toLowerCase()}function i(w,x){var v=w&&w.exec(x);return v&&v.index==0}function d(v){return Array.prototype.map.call(v.childNodes,function(w){if(w.nodeType==3){return b.useBR?w.nodeValue.replace(/\n/g,""):w.nodeValue}if(t(w)=="br"){return"\n"}return d(w)}).join("")}function r(w){var v=(w.className+" "+(w.parentNode?w.parentNode.className:"")).split(/\s+/);v=v.map(function(x){return x.replace(/^language-/,"")});return v.filter(function(x){return j(x)||x=="no-highlight"})[0]}function o(x,y){var v={};for(var w in x){v[w]=x[w]}if(y){for(var w in y){v[w]=y[w]}}return v}function u(x){var v=[];(function w(y,z){for(var A=y.firstChild;A;A=A.nextSibling){if(A.nodeType==3){z+=A.nodeValue.length}else{if(t(A)=="br"){z+=1}else{if(A.nodeType==1){v.push({event:"start",offset:z,node:A});z=w(A,z);v.push({event:"stop",offset:z,node:A})}}}}return z})(x,0);return v}function q(w,y,C){var x=0;var F="";var z=[];function B(){if(!w.length||!y.length){return w.length?w:y}if(w[0].offset!=y[0].offset){return(w[0].offset"}function E(G){F+=""}function v(G){(G.event=="start"?A:E)(G.node)}while(w.length||y.length){var D=B();F+=k(C.substr(x,D[0].offset-x));x=D[0].offset;if(D==w){z.reverse().forEach(E);do{v(D.splice(0,1)[0]);D=B()}while(D==w&&D.length&&D[0].offset==x);z.reverse().forEach(A)}else{if(D[0].event=="start"){z.push(D[0].node)}else{z.pop()}v(D.splice(0,1)[0])}}return F+k(C.substr(x))}function m(y){function v(z){return(z&&z.source)||z}function w(A,z){return RegExp(v(A),"m"+(y.cI?"i":"")+(z?"g":""))}function x(D,C){if(D.compiled){return}D.compiled=true;D.k=D.k||D.bK;if(D.k){var z={};function E(G,F){if(y.cI){F=F.toLowerCase()}F.split(" ").forEach(function(H){var I=H.split("|");z[I[0]]=[G,I[1]?Number(I[1]):1]})}if(typeof D.k=="string"){E("keyword",D.k)}else{Object.keys(D.k).forEach(function(F){E(F,D.k[F])})}D.k=z}D.lR=w(D.l||/\b[A-Za-z0-9_]+\b/,true);if(C){if(D.bK){D.b=D.bK.split(" ").join("|")}if(!D.b){D.b=/\B|\b/}D.bR=w(D.b);if(!D.e&&!D.eW){D.e=/\B|\b/}if(D.e){D.eR=w(D.e)}D.tE=v(D.e)||"";if(D.eW&&C.tE){D.tE+=(D.e?"|":"")+C.tE}}if(D.i){D.iR=w(D.i)}if(D.r===undefined){D.r=1}if(!D.c){D.c=[]}var B=[];D.c.forEach(function(F){if(F.v){F.v.forEach(function(G){B.push(o(F,G))})}else{B.push(F=="self"?D:F)}});D.c=B;D.c.forEach(function(F){x(F,D)});if(D.starts){x(D.starts,C)}var A=D.c.map(function(F){return F.bK?"\\.?\\b("+F.b+")\\b\\.?":F.b}).concat([D.tE]).concat([D.i]).map(v).filter(Boolean);D.t=A.length?w(A.join("|"),true):{exec:function(F){return null}};D.continuation={}}x(y)}function c(S,L,J,R){function v(U,V){for(var T=0;T";U+=Z+'">';return U+X+Y}function N(){var U=k(C);if(!I.k){return U}var T="";var X=0;I.lR.lastIndex=0;var V=I.lR.exec(U);while(V){T+=U.substr(X,V.index-X);var W=E(I,V);if(W){H+=W[1];T+=w(W[0],V[0])}else{T+=V[0]}X=I.lR.lastIndex;V=I.lR.exec(U)}return T+U.substr(X)}function F(){if(I.sL&&!f[I.sL]){return k(C)}var T=I.sL?c(I.sL,C,true,I.continuation.top):g(C);if(I.r>0){H+=T.r}if(I.subLanguageMode=="continuous"){I.continuation.top=T.top}return w(T.language,T.value,false,true)}function Q(){return I.sL!==undefined?F():N()}function P(V,U){var T=V.cN?w(V.cN,"",true):"";if(V.rB){D+=T;C=""}else{if(V.eB){D+=k(U)+T;C=""}else{D+=T;C=U}}I=Object.create(V,{parent:{value:I}})}function G(T,X){C+=T;if(X===undefined){D+=Q();return 0}var V=v(X,I);if(V){D+=Q();P(V,X);return V.rB?0:X.length}var W=z(I,X);if(W){var U=I;if(!(U.rE||U.eE)){C+=X}D+=Q();do{if(I.cN){D+=""}H+=I.r;I=I.parent}while(I!=W.parent);if(U.eE){D+=k(X)}C="";if(W.starts){P(W.starts,"")}return U.rE?0:X.length}if(A(X,I)){throw new Error('Illegal lexeme "'+X+'" for mode "'+(I.cN||"")+'"')}C+=X;return X.length||1}var M=j(S);if(!M){throw new Error('Unknown language: "'+S+'"')}m(M);var I=R||M;var D="";for(var K=I;K!=M;K=K.parent){if(K.cN){D=w(K.cN,D,true)}}var C="";var H=0;try{var B,y,x=0;while(true){I.t.lastIndex=x;B=I.t.exec(L);if(!B){break}y=G(L.substr(x,B.index-x),B[0]);x=B.index+y}G(L.substr(x));for(var K=I;K.parent;K=K.parent){if(K.cN){D+=""}}return{r:H,value:D,language:S,top:I}}catch(O){if(O.message.indexOf("Illegal")!=-1){return{r:0,value:k(L)}}else{throw O}}}function g(y,x){x=x||b.languages||Object.keys(f);var v={r:0,value:k(y)};var w=v;x.forEach(function(z){if(!j(z)){return}var A=c(z,y,false);A.language=z;if(A.r>w.r){w=A}if(A.r>v.r){w=v;v=A}});if(w.language){v.second_best=w}return v}function h(v){if(b.tabReplace){v=v.replace(/^((<[^>]+>|\t)+)/gm,function(w,z,y,x){return z.replace(/\t/g,b.tabReplace)})}if(b.useBR){v=v.replace(/\n/g,"
")}return v}function p(z){var y=d(z);var A=r(z);if(A=="no-highlight"){return}var v=A?c(A,y,true):g(y);var w=u(z);if(w.length){var x=document.createElementNS("http://www.w3.org/1999/xhtml","pre");x.innerHTML=v.value;v.value=q(w,u(x),y)}v.value=h(v.value);z.innerHTML=v.value;z.className+=" hljs "+(!A&&v.language||"");z.result={language:v.language,re:v.r};if(v.second_best){z.second_best={language:v.second_best.language,re:v.second_best.r}}}var b={classPrefix:"hljs-",tabReplace:null,useBR:false,languages:undefined};function s(v){b=o(b,v)}function l(){if(l.called){return}l.called=true;var v=document.querySelectorAll("pre code");Array.prototype.forEach.call(v,p)}function a(){addEventListener("DOMContentLoaded",l,false);addEventListener("load",l,false)}var f={};var n={};function e(v,x){var w=f[v]=x(this);if(w.aliases){w.aliases.forEach(function(y){n[y]=v})}}function j(v){return f[v]||f[n[v]]}this.highlight=c;this.highlightAuto=g;this.fixMarkup=h;this.highlightBlock=p;this.configure=s;this.initHighlighting=l;this.initHighlightingOnLoad=a;this.registerLanguage=e;this.getLanguage=j;this.inherit=o;this.IR="[a-zA-Z][a-zA-Z0-9_]*";this.UIR="[a-zA-Z_][a-zA-Z0-9_]*";this.NR="\\b\\d+(\\.\\d+)?";this.CNR="(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)";this.BNR="\\b(0b[01]+)";this.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~";this.BE={b:"\\\\[\\s\\S]",r:0};this.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[this.BE]};this.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[this.BE]};this.CLCM={cN:"comment",b:"//",e:"$"};this.CBLCLM={cN:"comment",b:"/\\*",e:"\\*/"};this.HCM={cN:"comment",b:"#",e:"$"};this.NM={cN:"number",b:this.NR,r:0};this.CNM={cN:"number",b:this.CNR,r:0};this.BNM={cN:"number",b:this.BNR,r:0};this.REGEXP_MODE={cN:"regexp",b:/\//,e:/\/[gim]*/,i:/\n/,c:[this.BE,{b:/\[/,e:/\]/,r:0,c:[this.BE]}]};this.TM={cN:"title",b:this.IR,r:0};this.UTM={cN:"title",b:this.UIR,r:0}}();hljs.registerLanguage("bash",function(b){var a={cN:"variable",v:[{b:/\$[\w\d#@][\w\d_]*/},{b:/\$\{(.*?)\}/}]};var d={cN:"string",b:/"/,e:/"/,c:[b.BE,a,{cN:"variable",b:/\$\(/,e:/\)/,c:[b.BE]}]};var c={cN:"string",b:/'/,e:/'/};return{l:/-?[a-z\.]+/,k:{keyword:"if then else elif fi for break continue while in do done exit return set declare case esac export exec",literal:"true false",built_in:"printf echo read cd pwd pushd popd dirs let eval unset typeset readonly getopts source shopt caller type hash bind help sudo",operator:"-ne -eq -lt -gt -f -d -e -s -l -a"},c:[{cN:"shebang",b:/^#![^\n]+sh\s*$/,r:10},{cN:"function",b:/\w[\w\d_]*\s*\(\s*\)\s*\{/,rB:true,c:[b.inherit(b.TM,{b:/\w[\w\d_]*/})],r:0},b.HCM,b.NM,d,c,a]}});hljs.registerLanguage("cs",function(b){var a="abstract as base bool break byte case catch char checked const continue decimal default delegate do double else enum event explicit extern false finally fixed float for foreach goto if implicit in int interface internal is lock long new null object operator out override params private protected public readonly ref return sbyte sealed short sizeof stackalloc static string struct switch this throw true try typeof uint ulong unchecked unsafe ushort using virtual volatile void while async await ascending descending from get group into join let orderby partial select set value var where yield";return{k:a,c:[{cN:"comment",b:"///",e:"$",rB:true,c:[{cN:"xmlDocTag",b:"///|"},{cN:"xmlDocTag",b:""}]},b.CLCM,b.CBLCLM,{cN:"preprocessor",b:"#",e:"$",k:"if else elif endif define undef warning error line region endregion pragma checksum"},{cN:"string",b:'@"',e:'"',c:[{b:'""'}]},b.ASM,b.QSM,b.CNM,{bK:"protected public private internal",e:/[{;=]/,k:a,c:[{bK:"class namespace interface",starts:{c:[b.TM]}},{b:b.IR+"\\s*\\(",rB:true,c:[b.TM]}]}]}});hljs.registerLanguage("ruby",function(e){var h="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?";var g="and false then defined module in return redo if BEGIN retry end for true self when next until do begin unless END rescue nil else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor";var a={cN:"yardoctag",b:"@[A-Za-z]+"};var i={cN:"comment",v:[{b:"#",e:"$",c:[a]},{b:"^\\=begin",e:"^\\=end",c:[a],r:10},{b:"^__END__",e:"\\n$"}]};var c={cN:"subst",b:"#\\{",e:"}",k:g};var d={cN:"string",c:[e.BE,c],v:[{b:/'/,e:/'/},{b:/"/,e:/"/},{b:"%[qw]?\\(",e:"\\)"},{b:"%[qw]?\\[",e:"\\]"},{b:"%[qw]?{",e:"}"},{b:"%[qw]?<",e:">",r:10},{b:"%[qw]?/",e:"/",r:10},{b:"%[qw]?%",e:"%",r:10},{b:"%[qw]?-",e:"-",r:10},{b:"%[qw]?\\|",e:"\\|",r:10},{b:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/}]};var b={cN:"params",b:"\\(",e:"\\)",k:g};var f=[d,i,{cN:"class",bK:"class module",e:"$|;",i:/=/,c:[e.inherit(e.TM,{b:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{cN:"inheritance",b:"<\\s*",c:[{cN:"parent",b:"("+e.IR+"::)?"+e.IR}]},i]},{cN:"function",bK:"def",e:" |$|;",r:0,c:[e.inherit(e.TM,{b:h}),b,i]},{cN:"constant",b:"(::)?(\\b[A-Z]\\w*(::)?)+",r:0},{cN:"symbol",b:":",c:[d,{b:h}],r:0},{cN:"symbol",b:e.UIR+"(\\!|\\?)?:",r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{cN:"variable",b:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{b:"("+e.RSR+")\\s*",c:[i,{cN:"regexp",c:[e.BE,c],i:/\n/,v:[{b:"/",e:"/[a-z]*"},{b:"%r{",e:"}[a-z]*"},{b:"%r\\(",e:"\\)[a-z]*"},{b:"%r!",e:"![a-z]*"},{b:"%r\\[",e:"\\][a-z]*"}]}],r:0}];c.c=f;b.c=f;return{k:g,c:f}});hljs.registerLanguage("diff",function(a){return{c:[{cN:"chunk",r:10,v:[{b:/^\@\@ +\-\d+,\d+ +\+\d+,\d+ +\@\@$/},{b:/^\*\*\* +\d+,\d+ +\*\*\*\*$/},{b:/^\-\-\- +\d+,\d+ +\-\-\-\-$/}]},{cN:"header",v:[{b:/Index: /,e:/$/},{b:/=====/,e:/=====$/},{b:/^\-\-\-/,e:/$/},{b:/^\*{3} /,e:/$/},{b:/^\+\+\+/,e:/$/},{b:/\*{5}/,e:/\*{5}$/}]},{cN:"addition",b:"^\\+",e:"$"},{cN:"deletion",b:"^\\-",e:"$"},{cN:"change",b:"^\\!",e:"$"}]}});hljs.registerLanguage("javascript",function(a){return{aliases:["js"],k:{keyword:"in if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const class",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require"},c:[{cN:"pi",b:/^\s*('|")use strict('|")/,r:10},a.ASM,a.QSM,a.CLCM,a.CBLCLM,a.CNM,{b:"("+a.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[a.CLCM,a.CBLCLM,a.REGEXP_MODE,{b:/;/,r:0,sL:"xml"}],r:0},{cN:"function",bK:"function",e:/\{/,c:[a.inherit(a.TM,{b:/[A-Za-z$_][0-9A-Za-z$_]*/}),{cN:"params",b:/\(/,e:/\)/,c:[a.CLCM,a.CBLCLM],i:/["'\(]/}],i:/\[|%/},{b:/\$[(.]/},{b:"\\."+a.IR,r:0}]}});hljs.registerLanguage("xml",function(a){var c="[A-Za-z0-9\\._:-]+";var d={b:/<\?(php)?(?!\w)/,e:/\?>/,sL:"php",subLanguageMode:"continuous"};var b={eW:true,i:/]+/}]}]}]};return{aliases:["html"],cI:true,c:[{cN:"doctype",b:"",r:10,c:[{b:"\\[",e:"\\]"}]},{cN:"comment",b:"",r:10},{cN:"cdata",b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{cN:"tag",b:"|$)",e:">",k:{title:"style"},c:[b],starts:{e:"",rE:true,sL:"css"}},{cN:"tag",b:"|$)",e:">",k:{title:"script"},c:[b],starts:{e:"<\/script>",rE:true,sL:"javascript"}},{b:"<%",e:"%>",sL:"vbscript"},d,{cN:"pi",b:/<\?\w+/,e:/\?>/,r:10},{cN:"tag",b:"",c:[{cN:"title",b:"[^ /><]+",r:0},b]}]}});hljs.registerLanguage("markdown",function(a){return{c:[{cN:"header",v:[{b:"^#{1,6}",e:"$"},{b:"^.+?\\n[=-]{2,}$"}]},{b:"<",e:">",sL:"xml",r:0},{cN:"bullet",b:"^([*+-]|(\\d+\\.))\\s+"},{cN:"strong",b:"[*_]{2}.+?[*_]{2}"},{cN:"emphasis",v:[{b:"\\*.+?\\*"},{b:"_.+?_",r:0}]},{cN:"blockquote",b:"^>\\s+",e:"$"},{cN:"code",v:[{b:"`.+?`"},{b:"^( {4}|\t)",e:"$",r:0}]},{cN:"horizontal_rule",b:"^[-\\*]{3,}",e:"$"},{b:"\\[.+?\\][\\(\\[].+?[\\)\\]]",rB:true,c:[{cN:"link_label",b:"\\[",e:"\\]",eB:true,rE:true,r:0},{cN:"link_url",b:"\\]\\(",e:"\\)",eB:true,eE:true},{cN:"link_reference",b:"\\]\\[",e:"\\]",eB:true,eE:true,}],r:10},{b:"^\\[.+\\]:",e:"$",rB:true,c:[{cN:"link_reference",b:"\\[",e:"\\]",eB:true,eE:true},{cN:"link_url",b:"\\s",e:"$"}]}]}});hljs.registerLanguage("css",function(a){var b="[a-zA-Z-][a-zA-Z0-9_-]*";var c={cN:"function",b:b+"\\(",e:"\\)",c:["self",a.NM,a.ASM,a.QSM]};return{cI:true,i:"[=/|']",c:[a.CBLCLM,{cN:"id",b:"\\#[A-Za-z0-9_-]+"},{cN:"class",b:"\\.[A-Za-z0-9_-]+",r:0},{cN:"attr_selector",b:"\\[",e:"\\]",i:"$"},{cN:"pseudo",b:":(:)?[a-zA-Z0-9\\_\\-\\+\\(\\)\\\"\\']+"},{cN:"at_rule",b:"@(font-face|page)",l:"[a-z-]+",k:"font-face page"},{cN:"at_rule",b:"@",e:"[{;]",c:[{cN:"keyword",b:/\S+/},{b:/\s/,eW:true,eE:true,r:0,c:[c,a.ASM,a.QSM,a.NM]}]},{cN:"tag",b:b,r:0},{cN:"rules",b:"{",e:"}",i:"[^\\s]",r:0,c:[a.CBLCLM,{cN:"rule",b:"[^\\s]",rB:true,e:";",eW:true,c:[{cN:"attribute",b:"[A-Z\\_\\.\\-]+",e:":",eE:true,i:"[^\\s]",starts:{cN:"value",eW:true,eE:true,c:[c,a.NM,a.QSM,a.ASM,a.CBLCLM,{cN:"hexcolor",b:"#[0-9A-Fa-f]+"},{cN:"important",b:"!important"}]}}]}]}]}});hljs.registerLanguage("http",function(a){return{i:"\\S",c:[{cN:"status",b:"^HTTP/[0-9\\.]+",e:"$",c:[{cN:"number",b:"\\b\\d{3}\\b"}]},{cN:"request",b:"^[A-Z]+ (.*?) HTTP/[0-9\\.]+$",rB:true,e:"$",c:[{cN:"string",b:" ",e:" ",eB:true,eE:true}]},{cN:"attribute",b:"^\\w",e:": ",eE:true,i:"\\n|\\s|=",starts:{cN:"string",e:"$"}},{b:"\\n\\n",starts:{sL:"",eW:true}}]}});hljs.registerLanguage("java",function(b){var a="false synchronized int abstract float private char boolean static null if const for true while long throw strictfp finally protected import native final return void enum else break transient new catch instanceof byte super volatile case assert short package default double public try this switch continue throws";return{k:a,i:/<\//,c:[{cN:"javadoc",b:"/\\*\\*",e:"\\*/",c:[{cN:"javadoctag",b:"(^|\\s)@[A-Za-z]+"}],r:10},b.CLCM,b.CBLCLM,b.ASM,b.QSM,{bK:"protected public private",e:/[{;=]/,k:a,c:[{cN:"class",bK:"class interface",eW:true,i:/[:"<>]/,c:[{bK:"extends implements",r:10},b.UTM]},{b:b.UIR+"\\s*\\(",rB:true,c:[b.UTM]}]},b.CNM,{cN:"annotation",b:"@[A-Za-z]+"}]}});hljs.registerLanguage("php",function(b){var e={cN:"variable",b:"\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"};var a={cN:"preprocessor",b:/<\?(php)?|\?>/};var c={cN:"string",c:[b.BE,a],v:[{b:'b"',e:'"'},{b:"b'",e:"'"},b.inherit(b.ASM,{i:null}),b.inherit(b.QSM,{i:null})]};var d={v:[b.BNM,b.CNM]};return{cI:true,k:"and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally",c:[b.CLCM,b.HCM,{cN:"comment",b:"/\\*",e:"\\*/",c:[{cN:"phpdoc",b:"\\s@[A-Za-z]+"},a]},{cN:"comment",b:"__halt_compiler.+?;",eW:true,k:"__halt_compiler",l:b.UIR},{cN:"string",b:"<<<['\"]?\\w+['\"]?$",e:"^\\w+;",c:[b.BE]},a,e,{cN:"function",bK:"function",e:/[;{]/,i:"\\$|\\[|%",c:[b.UTM,{cN:"params",b:"\\(",e:"\\)",c:["self",e,b.CBLCLM,c,d]}]},{cN:"class",bK:"class interface",e:"{",i:/[:\(\$"]/,c:[{bK:"extends implements",r:10},b.UTM]},{bK:"namespace",e:";",i:/[\.']/,c:[b.UTM]},{bK:"use",e:";",c:[b.UTM]},{b:"=>"},c,d]}});hljs.registerLanguage("python",function(a){var f={cN:"prompt",b:/^(>>>|\.\.\.) /};var b={cN:"string",c:[a.BE],v:[{b:/(u|b)?r?'''/,e:/'''/,c:[f],r:10},{b:/(u|b)?r?"""/,e:/"""/,c:[f],r:10},{b:/(u|r|ur)'/,e:/'/,r:10},{b:/(u|r|ur)"/,e:/"/,r:10},{b:/(b|br)'/,e:/'/,},{b:/(b|br)"/,e:/"/,},a.ASM,a.QSM]};var d={cN:"number",r:0,v:[{b:a.BNR+"[lLjJ]?"},{b:"\\b(0o[0-7]+)[lLjJ]?"},{b:a.CNR+"[lLjJ]?"}]};var e={cN:"params",b:/\(/,e:/\)/,c:["self",f,d,b]};var c={e:/:/,i:/[${=;\n]/,c:[a.UTM,e]};return{k:{keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda nonlocal|10 None True False",built_in:"Ellipsis NotImplemented"},i:/(<\/|->|\?)/,c:[f,d,b,a.HCM,a.inherit(c,{cN:"function",bK:"def",r:10}),a.inherit(c,{cN:"class",bK:"class"}),{cN:"decorator",b:/@/,e:/$/},{b:/\b(print|exec)\(/}]}});hljs.registerLanguage("sql",function(a){return{cI:true,i:/[<>]/,c:[{cN:"operator",b:"\\b(begin|end|start|commit|rollback|savepoint|lock|alter|create|drop|rename|call|delete|do|handler|insert|load|replace|select|truncate|update|set|show|pragma|grant|merge)\\b(?!:)",e:";",eW:true,k:{keyword:"all partial global month current_timestamp using go revoke smallint indicator end-exec disconnect zone with character assertion to add current_user usage input local alter match collate real then rollback get read timestamp session_user not integer bit unique day minute desc insert execute like ilike|2 level decimal drop continue isolation found where constraints domain right national some module transaction relative second connect escape close system_user for deferred section cast current sqlstate allocate intersect deallocate numeric public preserve full goto initially asc no key output collation group by union session both last language constraint column of space foreign deferrable prior connection unknown action commit view or first into float year primary cascaded except restrict set references names table outer open select size are rows from prepare distinct leading create only next inner authorization schema corresponding option declare precision immediate else timezone_minute external varying translation true case exception join hour default double scroll value cursor descriptor values dec fetch procedure delete and false int is describe char as at in varchar null trailing any absolute current_time end grant privileges when cross check write current_date pad begin temporary exec time update catalog user sql date on identity timezone_hour natural whenever interval work order cascade diagnostics nchar having left call do handler load replace truncate start lock show pragma exists number trigger if before after each row merge matched database",aggregate:"count sum min max avg"},c:[{cN:"string",b:"'",e:"'",c:[a.BE,{b:"''"}]},{cN:"string",b:'"',e:'"',c:[a.BE,{b:'""'}]},{cN:"string",b:"`",e:"`",c:[a.BE]},a.CNM]},a.CBLCLM,{cN:"comment",b:"--",e:"$"}]}});hljs.registerLanguage("ini",function(a){return{cI:true,i:/\S/,c:[{cN:"comment",b:";",e:"$"},{cN:"title",b:"^\\[",e:"\\]"},{cN:"setting",b:"^[a-z0-9\\[\\]_-]+[ \\t]*=[ \\t]*",e:"$",c:[{cN:"value",eW:true,k:"on off true false yes no",c:[a.QSM,a.NM],r:0}]}]}});hljs.registerLanguage("perl",function(c){var d="getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qqfileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent shutdown dump chomp connect getsockname die socketpair close flock exists index shmgetsub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedirioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when";var f={cN:"subst",b:"[$@]\\{",e:"\\}",k:d};var g={b:"->{",e:"}"};var a={cN:"variable",v:[{b:/\$\d/},{b:/[\$\%\@\*](\^\w\b|#\w+(\:\:\w+)*|{\w+}|\w+(\:\:\w*)*)/},{b:/[\$\%\@\*][^\s\w{]/,r:0}]};var e={cN:"comment",b:"^(__END__|__DATA__)",e:"\\n$",r:5};var h=[c.BE,f,a];var b=[a,c.HCM,e,{cN:"comment",b:"^\\=\\w",e:"\\=cut",eW:true},g,{cN:"string",c:h,v:[{b:"q[qwxr]?\\s*\\(",e:"\\)",r:5},{b:"q[qwxr]?\\s*\\[",e:"\\]",r:5},{b:"q[qwxr]?\\s*\\{",e:"\\}",r:5},{b:"q[qwxr]?\\s*\\|",e:"\\|",r:5},{b:"q[qwxr]?\\s*\\<",e:"\\>",r:5},{b:"qw\\s+q",e:"q",r:5},{b:"'",e:"'",c:[c.BE]},{b:'"',e:'"'},{b:"`",e:"`",c:[c.BE]},{b:"{\\w+}",c:[],r:0},{b:"-?\\w+\\s*\\=\\>",c:[],r:0}]},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{b:"(\\/\\/|"+c.RSR+"|\\b(split|return|print|reverse|grep)\\b)\\s*",k:"split return print reverse grep",r:0,c:[c.HCM,e,{cN:"regexp",b:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",r:10},{cN:"regexp",b:"(m|qr)?/",e:"/[a-z]*",c:[c.BE],r:0}]},{cN:"sub",bK:"sub",e:"(\\s*\\(.*?\\))?[;{]",r:5},{cN:"operator",b:"-\\w\\b",r:0}];f.c=b;g.c=b;return{k:d,c:b}});hljs.registerLanguage("objectivec",function(a){var d={keyword:"int float while char export sizeof typedef const struct for union unsigned long volatile static bool mutable if do return goto void enum else break extern asm case short default double register explicit signed typename this switch continue wchar_t inline readonly assign self synchronized id nonatomic super unichar IBOutlet IBAction strong weak @private @protected @public @try @property @end @throw @catch @finally @synthesize @dynamic @selector @optional @required",literal:"false true FALSE TRUE nil YES NO NULL",built_in:"NSString NSDictionary CGRect CGPoint UIButton UILabel UITextView UIWebView MKMapView UISegmentedControl NSObject UITableViewDelegate UITableViewDataSource NSThread UIActivityIndicator UITabbar UIToolBar UIBarButtonItem UIImageView NSAutoreleasePool UITableView BOOL NSInteger CGFloat NSException NSLog NSMutableString NSMutableArray NSMutableDictionary NSURL NSIndexPath CGSize UITableViewCell UIView UIViewController UINavigationBar UINavigationController UITabBarController UIPopoverController UIPopoverControllerDelegate UIImage NSNumber UISearchBar NSFetchedResultsController NSFetchedResultsChangeType UIScrollView UIScrollViewDelegate UIEdgeInsets UIColor UIFont UIApplication NSNotFound NSNotificationCenter NSNotification UILocalNotification NSBundle NSFileManager NSTimeInterval NSDate NSCalendar NSUserDefaults UIWindow NSRange NSArray NSError NSURLRequest NSURLConnection UIInterfaceOrientation MPMoviePlayerController dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once"};var c=/[a-zA-Z@][a-zA-Z0-9_]*/;var b="@interface @class @protocol @implementation";return{k:d,l:c,i:""}]},{cN:"preprocessor",b:"#",e:"$"},{cN:"class",b:"("+b.split(" ").join("|")+")\\b",e:"({|$)",k:b,l:c,c:[a.UTM]},{cN:"variable",b:"\\."+a.UIR,r:0}]}});hljs.registerLanguage("coffeescript",function(c){var b={keyword:"in if for while finally new do return else break catch instanceof throw try this switch continue typeof delete debugger super then unless until loop of by when and or is isnt not",literal:"true false null undefined yes no on off",reserved:"case default function var void with const let enum export import native __hasProp __extends __slice __bind __indexOf",built_in:"npm require console print module exports global window document"};var a="[A-Za-z$_][0-9A-Za-z$_]*";var f=c.inherit(c.TM,{b:a});var e={cN:"subst",b:/#\{/,e:/}/,k:b};var d=[c.BNM,c.inherit(c.CNM,{starts:{e:"(\\s*/)?",r:0}}),{cN:"string",v:[{b:/'''/,e:/'''/,c:[c.BE]},{b:/'/,e:/'/,c:[c.BE]},{b:/"""/,e:/"""/,c:[c.BE,e]},{b:/"/,e:/"/,c:[c.BE,e]}]},{cN:"regexp",v:[{b:"///",e:"///",c:[e,c.HCM]},{b:"//[gim]*",r:0},{b:"/\\S(\\\\.|[^\\n])*?/[gim]*(?=\\s|\\W|$)"}]},{cN:"property",b:"@"+a},{b:"`",e:"`",eB:true,eE:true,sL:"javascript"}];e.c=d;return{k:b,c:d.concat([{cN:"comment",b:"###",e:"###"},c.HCM,{cN:"function",b:"("+a+"\\s*=\\s*)?(\\(.*\\))?\\s*\\B[-=]>",e:"[-=]>",rB:true,c:[f,{cN:"params",b:"\\(",rB:true,c:[{b:/\(/,e:/\)/,k:b,c:["self"].concat(d)}]}]},{cN:"class",bK:"class",e:"$",i:/[:="\[\]]/,c:[{bK:"extends",eW:true,i:/[:="\[\]]/,c:[f]},f]},{cN:"attribute",b:a+":",e:":",rB:true,eE:true,r:0}])}});hljs.registerLanguage("nginx",function(c){var b={cN:"variable",v:[{b:/\$\d+/},{b:/\$\{/,e:/}/},{b:"[\\$\\@]"+c.UIR}]};var a={eW:true,l:"[a-z/_]+",k:{built_in:"on off yes no true false none blocked debug info notice warn error crit select break last permanent redirect kqueue rtsig epoll poll /dev/poll"},r:0,i:"=>",c:[c.HCM,{cN:"string",c:[c.BE,b],v:[{b:/"/,e:/"/},{b:/'/,e:/'/}]},{cN:"url",b:"([a-z]+):/",e:"\\s",eW:true,eE:true},{cN:"regexp",c:[c.BE,b],v:[{b:"\\s\\^",e:"\\s|{|;",rE:true},{b:"~\\*?\\s+",e:"\\s|{|;",rE:true},{b:"\\*(\\.[a-z\\-]+)+"},{b:"([a-z\\-]+\\.)+\\*"}]},{cN:"number",b:"\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d{1,5})?\\b"},{cN:"number",b:"\\b\\d+[kKmMgGdshdwy]*\\b",r:0},b]};return{c:[c.HCM,{b:c.UIR+"\\s",e:";|{",rB:true,c:[c.inherit(c.UTM,{starts:a})],r:0}],i:"[^\\s\\}]"}});hljs.registerLanguage("json",function(a){var e={literal:"true false null"};var d=[a.QSM,a.CNM];var c={cN:"value",e:",",eW:true,eE:true,c:d,k:e};var b={b:"{",e:"}",c:[{cN:"attribute",b:'\\s*"',e:'"\\s*:\\s*',eB:true,eE:true,c:[a.BE],i:"\\n",starts:c}],i:"\\S"};var f={b:"\\[",e:"\\]",c:[a.inherit(c,{cN:null})],i:"\\S"};d.splice(d.length,0,b,f);return{c:d,k:e,i:"\\S"}});hljs.registerLanguage("apache",function(a){var b={cN:"number",b:"[\\$%]\\d+"};return{cI:true,c:[a.HCM,{cN:"tag",b:""},{cN:"keyword",b:/\w+/,r:0,k:{common:"order deny allow setenv rewriterule rewriteengine rewritecond documentroot sethandler errordocument loadmodule options header listen serverroot servername"},starts:{e:/$/,r:0,k:{literal:"on off all"},c:[{cN:"sqbracket",b:"\\s\\[",e:"\\]$"},{cN:"cbracket",b:"[\\$%]\\{",e:"\\}",c:["self",b]},b,a.QSM]}}],i:/\S/}});hljs.registerLanguage("cpp",function(a){var b={keyword:"false int float while private char catch export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const struct for static_cast|10 union namespace unsigned long throw volatile static protected bool template mutable if public friend do return goto auto void enum else break new extern using true class asm case typeid short reinterpret_cast|10 default double register explicit signed typename try this switch continue wchar_t inline delete alignof char16_t char32_t constexpr decltype noexcept nullptr static_assert thread_local restrict _Bool complex _Complex _Imaginary",built_in:"std string cin cout cerr clog stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap array shared_ptr abort abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf"};return{aliases:["c"],k:b,i:"",i:"\\n"},a.CLCM]},{cN:"stl_container",b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:b,r:10,c:["self"]}]}});hljs.registerLanguage("makefile",function(a){var b={cN:"variable",b:/\$\(/,e:/\)/,c:[a.BE]};return{c:[a.HCM,{b:/^\w+\s*\W*=/,rB:true,r:0,starts:{cN:"constant",e:/\s*\W*=/,eE:true,starts:{e:/$/,r:0,c:[b],}}},{cN:"title",b:/^[\w]+:\s*$/},{cN:"phony",b:/^\.PHONY:/,e:/$/,k:".PHONY",l:/[\.\w]+/},{b:/^\t+/,e:/$/,c:[a.QSM,b]}]}}); \ No newline at end of file diff --git a/boards/static/js/form.js b/boards/static/js/form.js --- a/boards/static/js/form.js +++ b/boards/static/js/form.js @@ -1,4 +1,4 @@ -var isCompact = true; +var isCompact = false; $('input[name=image]').wrap($('
')); @@ -21,25 +21,21 @@ var isCompact = true; } }); -var compactForm = $('.swappable-form-compact'); var fullForm = $('.swappable-form-full'); function swapForm() { - compactForm.toggle(); - fullForm.toggle(); + if (isCompact) { + // TODO Use IDs (change the django form code) instead of absolute numbers + fullForm.find('textarea').appendTo(fullForm.find('.form-row')[4]); + fullForm.find('.file_wrap').appendTo(fullForm.find('.form-row')[7]); + fullForm.find('.form-row').show(); - if (isCompact) { - var oldText = compactForm.find('textarea')[0].value; - fullForm.find('textarea')[0].value = oldText; + scrollToBottom(); } else { - var oldText = fullForm.find('textarea')[0].value; - compactForm.find('textarea')[0].value = oldText; + fullForm.find('textarea').appendTo($('.compact-form-text')); + fullForm.find('.file_wrap').insertBefore($('.compact-form-text')); + fullForm.find('.form-row').hide(); + fullForm.find('input[type=text]').val(''); } isCompact = !isCompact; - - scrollToBottom(); } - -if (compactForm.length > 0) { - fullForm.toggle(); -} 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 @@ -31,6 +31,15 @@ function hideEmailFromForm() { $('.form-email').parent().parent().hide(); } +/** + * Highlight code blocks with code highlighter + */ +function highlightCode() { + $('pre code').each(function(i, e) { + hljs.highlightBlock(e); + }); +} + $( document ).ready(function() { hideEmailFromForm(); @@ -42,4 +51,6 @@ function hideEmailFromForm() { addImgPreview(); addRefLinkPreview(); + + highlightCode(); }); diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js --- a/boards/static/js/thread.js +++ b/boards/static/js/thread.js @@ -56,4 +56,6 @@ function scrollToBottom() { $target.animate({scrollTop: $target.height()}, "fast"); } -$('#full-form').toggle(); +$(document).ready(function() { + swapForm(); +}) diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -69,6 +69,7 @@ function updateThread() { post.appendTo(lastPost.parent()); addRefLinkPreview(post[0]); + highlightCode(); lastPost = post; blink(post); @@ -90,6 +91,7 @@ function updateThread() { oldPost.replaceWith(post); addRefLinkPreview(post[0]); + highlightCode(); blink(post); } diff --git a/boards/templates/boards/base.html b/boards/templates/boards/base.html --- a/boards/templates/boards/base.html +++ b/boards/templates/boards/base.html @@ -6,12 +6,10 @@ - - - + + + + @@ -43,11 +41,13 @@ + - {% if post.image %} + {% if post.images.exists %} + {% with post.images.all.0 as image %} + {% endwith %} {% endif %}
{% autoescape off %} @@ -81,6 +83,7 @@ {% cache 600 post_thread thread.id thread.last_edit_time LANGUAGE_CODE need_open_link %}