Kaydet (Commit) 5d9dc30a authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

Syntax highlight, extended list view

üst 1d7637c9
......@@ -2,7 +2,8 @@
{% block title %}Home{% endblock %}
{% block css %}
<link rel="stylesheet" href="https://prismjs.com/themes/prism.css" data-noprefix />
<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css">
{% endblock %}
{% block content %}
{% if user.is_authenticated %}
......@@ -18,5 +19,6 @@
{% endif %}
{% endblock %}
{% block js %}
<script src="https://prismjs.com/prism.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
{% endblock %}
<div>
<pre>
<code class="language-py">{{ item.text }}</code>
</pre>
<fieldset>
<legend>{{ item.author }}</legend>
<pre>
<code class="python">
{{ item.text }}
</code>
</pre>
<br>
-- wrote this at {{ item.pub_date }};
</fieldset>
</div>
from itertools import chain
from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from django.views.generic import CreateView, ListView
from django.views.generic.base import TemplateView
from social.models import Post, Snippet
from operator import or_
from functools import wraps, reduce
def ret_or_super(func):
def wrapper(*args, **kwargs):
try:
res = func(*args, **kwargs)
except:
self = args[0]
res = getattr(super(self.__class__, self), func.__name__)(*args, **kwargs)
return res
return wrapper
class ExtendedListView(ListView):
def get_queryset(self):
queryset = reduce(or_, map(lambda model: model._default_manager.all(), self.models))
return queryset
return chain.from_iterable(map(lambda model: model._default_manager.all(), self.models))
class Home(ExtendedListView):
models = Post, Snippet
template_name = 'home.html'
context_object_name = 'feed'
def get_queryset(self):
qs = list(super().get_queryset())
qs.sort(key = (lambda item: item.pub_date))
return qs
class Register(CreateView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment