diff --git a/blog/models.py b/blog/models.py index 346fa7e..eda5dad 100644 --- a/blog/models.py +++ b/blog/models.py @@ -5,9 +5,9 @@ from taggit.managers import TaggableManager class Post(models.Model): user = models.ForeignKey(User) - created_at = models.DateTimeField(auto_now_add=True) + created_at = models.DateTimeField(auto_now_add = True) title = models.CharField(max_length = 100) - slug = models.SlugField(editable=False, max_length = 100) + slug = models.SlugField(editable = False, max_length = 100) content = models.TextField() draft = models.BooleanField() tags = TaggableManager() @@ -23,10 +23,10 @@ class Post(models.Model): class CodeChunk(models.Model): language = models.CharField(max_length = 20) - created_at = models.DateTimeField(auto_now_add=True) + created_at = models.DateTimeField(auto_now_add = True) title = models.CharField(max_length = 100) slug = models.SlugField(editable = False, max_length = 100) - description = models.TextField(blank=True) + description = models.TextField(blank = True) content = models.TextField() def save(self, *args, **kwargs): diff --git a/blog/templatetags/code_chunks.py b/blog/templatetags/code_chunks.py index 86d8040..476274e 100644 --- a/blog/templatetags/code_chunks.py +++ b/blog/templatetags/code_chunks.py @@ -25,12 +25,17 @@ class CodeFormatter(HtmlFormatter): def hilite(language, code): lexer = get_lexer_by_name(language) - formatter = CodeFormatter(style = SolarizedDarkStyle, linenos = False, cssclass = language + " code", noclasses = True) + formatter = CodeFormatter( + style = SolarizedDarkStyle, + linenos = False, + cssclass = language + " code", + noclasses = True + ) return highlight(code, lexer, formatter) -@register.filter(needs_autoescape=True) +@register.filter(needs_autoescape = True) @stringfilter -def remove_code_chunks(value, autoescape=None): +def remove_code_chunks(value, autoescape = None): p = re.compile('\[\$ code:(?P[^:]+):(?P[^ ]+) \$\]') i = p.finditer(value) diff = 0 @@ -61,9 +66,9 @@ def remove_code_chunks(value, autoescape=None): return mark_safe(value) -@register.filter(needs_autoescape=True) +@register.filter(needs_autoescape = True) @stringfilter -def insert_code_chunks(value, autoescape=None): +def insert_code_chunks(value, autoescape = None): p = re.compile('\[\$ code:(?P[^:]+):(?P[^ ]+) \$\]') i = p.finditer(value) diff = 0 @@ -74,8 +79,12 @@ def insert_code_chunks(value, autoescape=None): start += diff end += diff try: - chunk = CodeChunk.objects.get(language = match.group('lang'), slug = match.group('slug')) - # TODO: This is an ugly hack, as it includes template logic in code. BAD! + chunk = CodeChunk.objects.get( + language = match.group('lang'), + slug = match.group('slug') + ) + # TODO: This is an ugly hack, as it includes template logic in + # code. BAD! newstr = "
" + hilite(match.group('lang'), chunk.content) + "
" except CodeChunk.DoesNotExist: newstr = "" @@ -94,7 +103,8 @@ def insert_code_chunks(value, autoescape=None): start += diff end += diff - # TODO: This is an ugly hack, as it includes template logic in code. BAD! + # TODO: This is an ugly hack, as it includes template logic in code. + # BAD! newstr = "
" + hilite(match.group('lang'), match.group('code')) + "
" newlen = len(newstr) @@ -103,9 +113,9 @@ def insert_code_chunks(value, autoescape=None): return mark_safe(value) -@register.filter(needs_autoescape=True) +@register.filter(needs_autoescape = True) @stringfilter -def syhilite(value, language, autoescape=None): +def syhilite(value, language, autoescape = None): if language == "php": value = "\d+)$', views.indexpage, name = 'indexpage'), - url(r'^tag/(?P[^/]+)$', views.taglist, name = 'taglist'), - url(r'^tag/(?P[^/]+)/page/(?P\d+)$', views.tagpage, name = 'tagpage'), - url(r'^(?P\d+)/(?P\d+)/(?P\d+)/?$', views.datelist, name = 'datelist'), - url(r'^(?P\d+)/(?P\d+)/(?P\d+)/page/(?P\d+)$', views.datepage, name = 'datepage'), - url(r'^(?P\d+)/(?P\d+)/(?P\d+)/(?P[^/]+)$', views.read, name = 'read'), - url(r'^code-chunk/(?P[^/]+)/(?P[^/]+)$', views.codechunk, name = 'codechunk'), - url(r'^feed$', views.feed, name = 'feed'), + url( + r'^$', + views.index, + name = 'index' + ), + url( + r'^page/(?P\d+)$', + views.indexpage, + name = 'indexpage' + ), + url( + r'^tag/(?P[^/]+)$', + views.taglist, + name = 'taglist' + ), + url( + r'^tag/(?P[^/]+)/page/(?P\d+)$', + views.tagpage, + name = 'tagpage' + ), + url( + r'^(?P\d+)/(?P\d+)/(?P\d+)/?$', + views.datelist, + name = 'datelist' + ), + url( + r'^(?P\d+)/(?P\d+)/(?P\d+)/page/(?P\d+)$', + views.datepage, + name = 'datepage' + ), + url( + r'^(?P\d+)/(?P\d+)/(?P\d+)/(?P[^/]+)$', + views.read, + name = 'read' + ), + url( + r'^code-chunk/(?P[^/]+)/(?P[^/]+)$', + views.codechunk, + name = 'codechunk' + ), + url( + r'^feed$', + views.feed, + name = 'feed' + ), ) diff --git a/blog/views.py b/blog/views.py index 5bdaf10..6e85059 100644 --- a/blog/views.py +++ b/blog/views.py @@ -13,10 +13,10 @@ def listing(request, tag, year, month, day, page): view = 'index' if (tag == None): - view = "index" + view = 'index' else: kwargs['tags__slug'] = tag - view = "tag" + view = 'tag' if (year != None): kwargs['created_at__year'] = year @@ -40,7 +40,11 @@ def listing(request, tag, year, month, day, page): if paginator.num_pages > 1: view = view + 'page' - return render(request, 'blog/listing.html', { 'posts': posts, 'tag': tag, 'view': "blog:" + view }) + return render(request, 'blog/listing.html', { + 'posts': posts, + 'tag': tag, + 'view': "blog:" + view + }) def index(request): return listing(request, None, None, None, None, 1) @@ -61,7 +65,13 @@ def datepage(request, year, month, day, page): return listing(request, None, year, month, day, page) def read(request, year, month, day, slug): - post = get_object_or_404(Post, created_at__year=int(year), created_at__month=int(month), created_at__day=int(day), slug=slug, draft=False) + post = get_object_or_404(Post, + created_at__year = int(year), + created_at__month = int(month), + created_at__day = int(day), + slug = slug, + draft = False + ) next_post = Post.objects.filter(created_at__gt = post.created_at).order_by('created_at')[0:1] prev_post = Post.objects.filter(created_at__lt = post.created_at).order_by('-created_at')[0:1] @@ -75,10 +85,14 @@ def read(request, year, month, day, slug): else: prev_post = prev_post[0] - return render(request, 'blog/view.html', {'post': post, 'prev_post': prev_post, 'next_post': next_post}) + return render(request, 'blog/view.html', { + 'post': post, + 'prev_post': prev_post, + 'next_post': next_post, + }) def codechunk(request, language, slug): - chunk = get_object_or_404(CodeChunk, language=language, slug=slug) + chunk = get_object_or_404(CodeChunk, language = language, slug = slug) return render(request, 'blog/code-chunk.html', {'codechunk': chunk}) def feed(request): diff --git a/gergelypolonkaiweb/helper.py b/gergelypolonkaiweb/helper.py index f7124e4..e0edc4b 100644 --- a/gergelypolonkaiweb/helper.py +++ b/gergelypolonkaiweb/helper.py @@ -7,12 +7,19 @@ import os from random import choice def randomheader(request): - header_file = choice(filter(lambda x: os.path.isfile(settings.HEADER_DIR + os.path.sep + x), os.listdir(settings.HEADER_DIR))) + header_file = choice(filter( + lambda x: os.path.isfile( + settings.HEADER_DIR + os.path.sep + x + ), + os.listdir(settings.HEADER_DIR) + )) return {'header': header_file} def tagcloud(request): tagcloud = [] - tagcloudlist = Tag.objects.annotate(ct=Count('taggit_taggeditem_items')).order_by('-ct') + tagcloudlist = Tag.objects.annotate( + ct = Count('taggit_taggeditem_items') + ).order_by('-ct') if (len(tagcloudlist) > 0): tmax = tagcloudlist[0].ct @@ -26,9 +33,13 @@ def tagcloud(request): if (tagcount >= tmin): size = int(floor((5.0 * (tagcount - tmin)) / (tmax - tmin))) - tagcloud.append({'name': cloudelement.name, 'slug': cloudelement.slug, 'size': size}) + tagcloud.append({ + 'name': cloudelement.name, + 'slug': cloudelement.slug, + 'size': size + }) - tagcloud.sort(key=itemgetter('name')) + tagcloud.sort(key = itemgetter('name')) return {'tagcloud': tagcloud} diff --git a/gergelypolonkaiweb/solarized_dark.py b/gergelypolonkaiweb/solarized_dark.py index 74e044f..2bf3d84 100644 --- a/gergelypolonkaiweb/solarized_dark.py +++ b/gergelypolonkaiweb/solarized_dark.py @@ -8,7 +8,21 @@ """ from pygments.style import Style -from pygments.token import Comment, Error, Generic, Keyword, Literal, Name, Number, Operator, Other, Punctuation, String, Text, Token, Whitespace +from pygments.token import \ + Comment, \ + Error, \ + Generic, \ + Keyword, \ + Literal, \ + Name, \ + Number, \ + Operator, \ + Other, \ + Punctuation, \ + String, \ + Text, \ + Token, \ + Whitespace class SolarizedDarkStyle(Style): """ diff --git a/gergelypolonkaiweb/urls.py b/gergelypolonkaiweb/urls.py index 3dd2fd3..f60abf9 100644 --- a/gergelypolonkaiweb/urls.py +++ b/gergelypolonkaiweb/urls.py @@ -10,13 +10,40 @@ handler403 = 'basics.views.forbidden' handler400 = 'basics.views.badrequest' urlpatterns = patterns('', - # Examples: - url(r'^$', 'blog.views.mainpage', name='home'), - url(r'^google150e54bda5f96d97', 'basics.views.googlevalidator'), - url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type = 'text/plain')), - url(r'^blog/', include('blog.urls', namespace='blog')), + url( + r'^$', + 'blog.views.mainpage', + name = 'home' + ), + url( + r'^google150e54bda5f96d97', + 'basics.views.googlevalidator' + ), + url( + r'^robots\.txt$', + TemplateView.as_view(template_name = 'robots.txt', content_type = 'text/plain') + ), + url( + r'^blog/', + include( + 'blog.urls', + namespace = 'blog' + ) + ), # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - url(r'^admin/', include(admin.site.urls)), - url(r'^', include('basics.urls', namespace='basics')), + #url( + # r'^admin/doc/', + # include('django.contrib.admindocs.urls') + # ), + url( + r'^admin/', + include(admin.site.urls) + ), + url( + r'^', + include( + 'basics.urls', + namespace = 'basics' + ) + ), )