big func update

- tweaked statpage handling, added markdown support
- added footer plus menu
- added category view
- added Cantarell default font
This commit is contained in:
ottona 2018-02-25 12:21:28 +01:00
parent 9268aee8df
commit 4195802ace
14 changed files with 188 additions and 66 deletions

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-19 09:32
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('blogapp', '0002_auto_20170529_2023'),
]
operations = [
migrations.AlterField(
model_name='blogcomment',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -1,6 +1,7 @@
from django.db import models
from django.contrib.auth.models import User
class blogcategory(models.Model):
name = models.CharField(max_length=100)
@ -8,7 +9,6 @@ class blogcategory(models.Model):
return self.name
class blogentry(models.Model):
user = models.ForeignKey(User)
date = models.DateTimeField('date')
@ -21,9 +21,10 @@ class blogentry(models.Model):
def __str__(self):
return self.header
class blogcomment(models.Model):
blogentry = models.ForeignKey(blogentry, on_delete=models.CASCADE)
user = models.ForeignKey(User, null = True)
user = models.ForeignKey(User, null=True, blank=True)
guestname = models.CharField(max_length=20)
body = models.CharField(max_length=300)
date = models.DateTimeField('date')

View File

@ -5,13 +5,16 @@
{% block content %}
{% autoescape off %}
{% if category %}
<h1>Blog posts for category {{ category }}</h1>
{% endif %}
{% if blogentries %}
{% for blogentry in blogentries %}
{% if blogentry.published %}
<h1>{{ blogentry.header }}</h1>
<small>posted on: {{blogentry.date}} by {{blogentry.user.username}}</small>
<p>{{blogentry.intro|linebreaks}}
<small>Filed under: {% for category in blogentry.categories.all %} {{ category }} {% endfor %}</small>
<small>Filed under: {% for category in blogentry.categories.all %} <a href="{% url 'category' category.id %}">{{ category }}</a> {% endfor %}</small>
</p><a href="{% url 'detail' blogentry.id %}">Read more...</a><br/>
{% endif %}
{% endfor %}

View File

@ -5,5 +5,6 @@ from . import views
urlpatterns = [
url(r'^$', views.listall, name='listall'),
url(r'^(?P<blogentry_id>\d+)/$', views.detail, name='detail'),
url(r'^category/(?P<category_id>\d+)/$', views.list_category, name='category'),
#url(r'^$', views.detail, name='detail'),
]

View File

@ -1,21 +1,12 @@
from blogapp.models import blogentry, blogcomment
from blogapp.models import blogentry, blogcomment, blogcategory
from django.shortcuts import render, get_object_or_404
# from django.template import RequestContext
from django import forms
from imageapp.models import BlogImage
from polysite.globals import CustomRenderer
import datetime
import mistune
class CustomRenderer(mistune.Renderer):
def image(self, src, title, alt_text):
try:
img = BlogImage.objects.get(pk=src)
return '<div id="textimg"><img width="100%" src="' + img.image.url + '"/><br>Title: ' + img.title + '<br>Caption: ' + img.caption + '</div>'
except BlogImage.DoesNotExist:
return '<i>Should display an image here but none with id ' + src + ' was found.</i>'
class BlogCommentForm(forms.Form):
guestname = forms.CharField()
blogcomment = forms.CharField(widget=forms.Textarea(attrs={'rows': 3, 'cols': 30}))
@ -27,6 +18,13 @@ def listall(request):
return render(request, 'blogapp/blogindex.html', context)
def list_category(request, category_id):
category = get_object_or_404(blogcategory, pk=category_id)
blogentries = blogentry.objects.all().filter(categories=category)
context = {'blogentries': blogentries, 'category': category}
return render(request, 'blogapp/blogindex.html', context)
def detail(request, blogentry_id):
blogdetail = get_object_or_404(blogentry, pk=blogentry_id)
@ -38,10 +36,10 @@ def detail(request, blogentry_id):
bc.guestname = fml.cleaned_data['guestname']
bc.body = fml.cleaned_data['blogcomment']
bc.date = datetime.datetime.now()
bc.save
bc.save()
renderer = CustomRenderer()
md = mistune.Markdown(renderer = renderer, hard_wrap = True)
md = mistune.Markdown(renderer=renderer, hard_wrap=True)
blogdetail.body = md(blogdetail.body)
form = BlogCommentForm()

Binary file not shown.

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-19 09:32
from __future__ import unicode_literals
from django.db import migrations, models
import imageapp.models
class Migration(migrations.Migration):
dependencies = [
('imageapp', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='blogimage',
name='image',
field=models.ImageField(upload_to=imageapp.models.UploadToPathAndRename('')),
),
]

View File

@ -1,17 +1,24 @@
from pageapp.models import page
from django.shortcuts import render, get_object_or_404
from django.template import RequestContext
from polysite.globals import CustomRenderer
import mistune
def getpage(request, page_id):
pagedetail = get_object_or_404(page, pk=page_id)
renderer = CustomRenderer()
md = mistune.Markdown(renderer=renderer, hard_wrap=True)
pagedetail.body = md(pagedetail.body)
return render(request, 'pageapp/page.html', {'page': pagedetail})
def aboutpage(request):
about = get_object_or_404(page, pk=1)
return render(request, 'pageapp/page.html', {'page': about})
# about = get_object_or_404(page, pk=1)
# return render(request, 'pageapp/page.html', {'page': about})
return getpage(request, 1)
def contactpage(request):
contact = get_object_or_404(page, pk=2)
return render(request, 'pageapp/page.html', {'page': contact})
# contact = get_object_or_404(page, pk=2)
# return render(request, 'pageapp/page.html', {'page': contact})
return getpage(request, 2)

25
polysite/globals.py Normal file
View File

@ -0,0 +1,25 @@
import mistune
from imageapp.models import BlogImage
from blogapp.models import blogentry, blogcategory, blogcomment
class CustomRenderer(mistune.Renderer):
def image(self, src, title, alt_text):
try:
img = BlogImage.objects.get(pk=src)
return '<div id="textimg"><img width="100%" src="' + img.image.url + '"/><br>Title: ' + img.title + '<br>Caption: ' + img.caption + '</div>'
except BlogImage.DoesNotExist:
return '<i>Should display an image here but none with id ' + src + ' was found.</i>'
def footer_info(request):
blogentries = blogentry.objects.all().order_by('-date')[:5]
blogcategories = blogcategory.objects.all()
blogcomments = blogcomment.objects.all().order_by('-date')[:5]
return {'blogentries': blogentries, 'blogcategories': blogcategories, 'blogcomments': blogcomments}
# def getincludes(request):
# eventlist = evententry.objects.all().order_by('-date')[:10]
# appointmentlist = event.objects.all().filter(eventend__gte = datetime.datetime.now()).order_by('eventstart')[:5]
# return {'eventlist' : eventlist, 'appointmentlist' : appointmentlist}

View File

@ -69,6 +69,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'polysite.globals.footer_info',
],
},
},

Binary file not shown.

View File

@ -1,11 +1,17 @@
@font-face {
font-family: Cantarell;
src: url(/static/Cantarell-Regular.otf);
}
body {
color: #555;
line-height: 1.5;
padding: 4em 1em;
padding-bottom: 0;
margin-left: auto;
margin-right: auto;
max-width: 50em;
font-family: "Helvetica", "Arial", sans-serif;
font-family: Cantarell, sans-serif;
}
h1,
@ -42,6 +48,8 @@ div#nav li{
div#main{
padding-top: 1em;
padding-bottom: 4em;
min-height: 50em;
}
div#textimg{
@ -50,3 +58,21 @@ div#textimg{
margin-left: auto;
margin-right: auto;
}
div#footer{
background-color: #222222;
min-height: 15em;
color: white;
}
.column {
float: left;
width: 33%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}

View File

@ -14,7 +14,7 @@
viewBox="0 0 420.96346 108.77486"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="poly.svg"
inkscape:export-filename="/home/ottona/Projekte/polysite/blogapp/static/blogapp/poly.png"
inkscape:export-xdpi="35.141472"
@ -28,23 +28,29 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.9899495"
inkscape:cx="-54.469216"
inkscape:cy="-24.655005"
inkscape:zoom="2.8"
inkscape:cx="304.30863"
inkscape:cy="22.855508"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
showguides="true"
inkscape:guide-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="1010"
inkscape:window-width="3840"
inkscape:window-height="2044"
inkscape:window-x="0"
inkscape:window-y="33"
inkscape:window-y="60"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
fit-margin-bottom="0">
<sodipodi:guide
position="297.83717,34.802911"
orientation="0,1"
id="guide827"
inkscape:locked="false" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
@ -53,7 +59,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
@ -124,37 +130,17 @@
inkscape:export-filename="/home/ottona/Projekte/polysite/static/poly.png"
inkscape:export-xdpi="35.91761"
inkscape:export-ydpi="35.91761" />
<g
style="font-style:normal;font-weight:normal;font-size:62.34859085px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="text4244">
<path
d="m 307.65103,263.79957 q 4.75682,0 7.30648,-3.69129 2.54965,-3.6913 2.54965,-10.76944 0,-7.00204 -2.43549,-10.57917 -2.43549,-3.57713 -7.19231,-3.57713 -10.16057,0 -10.19862,13.54742 0,15.06961 9.97029,15.06961 z m -18.38035,22.56635 0,-57.04378 7.04009,0 0.87526,7.15426 q 3.57712,-7.83924 12.67216,-7.83924 5.06126,0 8.79061,2.70187 3.72934,2.70187 5.59402,7.38258 1.86467,4.64266 1.86467,10.69334 0,9.24725 -4.68071,15.0696 -4.64266,5.78429 -12.51995,5.78429 -3.72935,0 -6.62149,-1.75051 -2.89215,-1.75051 -4.68071,-4.75682 l 0.19027,7.23037 0,15.37404 -8.52422,0 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4139" />
<path
d="m 351.26155,270.26884 q -8.75255,0 -14.11824,-5.74623 -5.32764,-5.74624 -5.32764,-15.10766 0,-9.58975 5.21348,-15.18377 5.21347,-5.59402 14.2324,-5.59402 8.86672,0 14.11824,5.67013 5.28959,5.63207 5.28959,15.10766 0,9.47558 -5.28959,15.18377 -5.28958,5.67012 -14.11824,5.67012 z m 0,-6.46927 q 5.25153,0 8.02952,-3.7674 2.77798,-3.80546 2.77798,-10.61722 0,-6.81177 -2.77798,-10.50306 -2.77799,-3.72935 -8.02952,-3.72935 -5.17542,0 -8.02951,3.72935 -2.81604,3.72934 -2.81604,10.50306 0,6.77371 2.81604,10.57916 2.81604,3.80546 8.02951,3.80546 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4141" />
<path
d="m 396.24204,269.81219 -2.73993,0 q -3.15853,0 -5.40375,-0.30444 -2.20716,-0.34249 -4.07183,-1.17969 -1.86468,-0.8372 -2.96826,-2.24522 -1.10358,-1.44607 -1.71245,-3.65323 -0.57082,-2.20717 -0.57082,-5.28959 l 0,-43.11581 8.44811,-0.7611 0,44.56189 q 0,2.8541 1.29385,3.99573 1.33191,1.14164 4.60461,1.40802 l 3.61518,0.30444 -0.49471,6.279 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4143" />
<path
d="m 416.33485,286.48009 -7.68702,-1.21775 6.54539,-17.12455 -15.90681,-38.81565 8.56228,0 11.11193,28.73119 9.70391,-28.73119 8.7906,0 -21.12028,57.15795 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4145" />
<path
d="m 460.63036,269.81219 -2.73993,0 q -3.15853,0 -5.40374,-0.30444 -2.20717,-0.34249 -4.07184,-1.17969 -1.86468,-0.8372 -2.96826,-2.24522 -1.10358,-1.44607 -1.71245,-3.65323 -0.57082,-2.20717 -0.57082,-5.28959 l 0,-43.11581 8.44811,-0.7611 0,44.56189 q 0,2.8541 1.29386,3.99573 1.3319,1.14164 4.6046,1.40802 l 3.61518,0.30444 -0.49471,6.279 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4147" />
<path
d="m 501.34873,229.32214 0,40.26172 -6.81177,0 -0.8372,-6.279 q -1.86467,3.65324 -5.0232,5.32764 -3.15853,1.63634 -7.68702,1.63634 -6.96398,0 -10.69333,-3.99572 -3.72935,-3.99573 -3.72935,-11.91108 l 0,-25.0399 8.52422,0 0,24.69741 q 0,4.90904 1.82662,7.34453 1.86468,2.43549 6.12679,2.43549 5.4418,0 7.61091,-3.23464 2.16911,-3.27269 2.16911,-9.66586 l 0,-21.57693 8.52422,0 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4149" />
<path
d="m 536.39699,269.58386 -10.73139,-14.91738 -9.97029,14.91738 -8.98088,0 14.68906,-20.89195 -13.92797,-19.36977 9.39948,0 10.23668,14.19435 9.28531,-14.19435 9.05698,0 -14.04213,20.16891 14.46073,20.09281 -9.47558,0 z"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:77.93573761px;font-family:Oxygen-Sans;-inkscape-font-specification:'Oxygen-Sans Bold';fill:#4d4d4d"
id="path4151" />
</g>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:80px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#4d4d4d;fill-opacity:1;stroke:none;stroke-width:0.9375"
x="264.34479"
y="269.24091"
id="text825"><tspan
sodipodi:role="line"
id="tspan823"
x="264.34479"
y="269.24091"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:80px;font-family:Cantarell;-inkscape-font-specification:'Cantarell Bold';letter-spacing:1.875px;fill:#4d4d4d;fill-opacity:1;stroke-width:0.9375"
dx="0 0 0 0 0.11">polylux</tspan></text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -25,7 +25,38 @@
{% endblock %}
</div>
<div id="footer">
<div class="row">
<div class="column">
Blog Post Categories:<br/>
<ul>
{% for cat in blogcategories %}
<li> <a href="{% url 'category' cat.id %}">{{ cat }}</a> </li>
{% endfor %}
</ul>
</div>
<div class="column">
Recent Posts:<br/>
<ul>
{% for post in blogentries %}
<li> <a href="{% url 'detail' post.id %}">{{ post }}</a> </li>
{% endfor %}
</ul>
</div>
</body></html>
<div class="column">Recent Comments:<br/>
<ul>
{% for comment in blogcomments %}
{% if comment.user is not null %}
<li> <a href="{% url 'detail' comment.blogentry.id %}"><b>{{ comment.user }}</b> in {{ comment.blogentry }}</a> </li>
{% else %}
<li> <a href="{% url 'detail' comment.blogentry.id %}"><i>{{ comment.guestname }}</i> in {{ comment.blogentry }}</a> </li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
</body>
</html>