Implemented blog_pages and blog_entry views

This commit is contained in:
Alexandro Sánchez Bach 2014-06-16 18:52:36 +02:00
parent 3931c9a4db
commit 9deb084422
11 changed files with 122 additions and 10 deletions

7
.gitignore vendored
View File

@ -30,9 +30,12 @@ pip-delete-this-directory.txt
*.log
*.pot
# SQLite3
sqlite3.exe
# Python Tools for Visual Studio
*.suo
# Secret stuff:
# Irrelevant files
settings_secret.py
*.sqlite3
db.sqlite3

View File

@ -5,8 +5,9 @@ apt-get install python
apt-get install python-dev
apt-get install python-pip
# Django
# Modules
pip install django
pip install markdown
# Initialize DB
python ../manage.py syncdb

View File

@ -36,6 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="manage.py" />
<Compile Include="website\blog\admin.py" />
<Compile Include="website\blog\models.py" />
<Compile Include="website\blog\tests.py" />
<Compile Include="website\blog\urls.py" />
@ -84,7 +85,8 @@
<Folder Include="website\templates\" />
</ItemGroup>
<ItemGroup>
<Content Include="website\blog\templates\index.html" />
<Content Include="website\blog\templates\blog_article.html" />
<Content Include="website\blog\templates\blog_index.html" />
<Content Include="website\compat\templates\classify.html" />
<Content Include="website\compat\templates\list.html" />
<Content Include="website\compat\templates\index.html" />

5
website/blog/admin.py Normal file
View File

@ -0,0 +1,5 @@
from django.contrib import admin
from website.blog.models import Article, Tag
admin.site.register(Article)
admin.site.register(Tag)

View File

@ -1,3 +1,30 @@
from django.db import models
# Create your models here.
import markdown
from django.template.defaultfilters import slugify
class Tag(models.Model):
tag = models.CharField(max_length=31)
def __unicode__(self):
return self.tag
class Article(models.Model):
title = models.CharField(max_length=255)
content = models.TextField()
date = models.DateTimeField()
visible = models.BooleanField()
tags = models.ManyToManyField(Tag)
slug = models.SlugField()
def __unicode__(self):
return self.title
def save(self):
if not self.id: # Newly created object, so set slug
self.slug = slugify(self.title)
super(Article, self).save(*args, **kwargs)
def get_formatted_content(self):
return markdown.markdown(self.content)

View File

@ -3,7 +3,7 @@
<body>
{{ content }}
Hello World!
</body>
</html>

View File

@ -0,0 +1,39 @@
{% extends 'base.html' %}
{% block content %}
{% for entry in articles %}
<div>
<div>
<h2>
<a href="/blog/{{ entry.get_url }}" title="{{ entry.title }}" rel="bookmark">
{{ entry.title }}
</a>
</h2>
<p>
Written by
<span><a href="#" rel="author">RPCS3 Staff</a></span>
on
<abbr class="published" title="{{ entry.date|date:"c" }}">{{ entry.date|date:"F j, Y" }}</abbr>
/
{% for tag in entry.tags.all %}
<span class="label label-default">{{ tag.tag }}</span>
{% endfor %}
/
<a href="/blog/{{ entry.id }}/" title="Short URL to {{ entry.title }}" rel="shortlink">Short link</a>
</p>
</div>
<div>
{{ entry.get_formatted_content|safe }}
</div>
<br />
</div>
{% endfor %}
<div class="text-center">
<ul class="pagination">
{% for num in pages %}
<li><a href='/blog/page/{{ num }}/'>{{ num }}</a></li>
{% endfor %}
</ul>
</div>
{% endblock %}

View File

@ -1,5 +1,9 @@
from django.conf.urls import patterns, url
urlpatterns = patterns('website.blog.views',
url(r'^$', 'blog_index', name='blog-index'),
url(r'^$', 'blog_pages', name='blog-index'),
url(r'^page/(?P<num>[0-9]+)/$', 'blog_pages'),
url(r'^tags/$', 'blog_pages', name='blog-entry'),
url(r'^tags/(?P<slug>[-\w]+)/$', 'blog_pages', name='blog-entry'),
url(r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'blog_entry', name='blog-entry'),
)

View File

@ -1 +1,32 @@
# Create your views here.
from django.shortcuts import render
from website.blog.models import Article
def blog_pages(request, num="1"):
count = 10 # Articles per page
num = max(1, int(num))
articles = Article.objects.order_by('-date')[count*(num-1):count*num]
objects = {
'articles' : articles,
'pages' : range(1, 1 + Article.objects.all().count()/count),
}
return render(request, 'blog_index.html', objects)
def blog_entry(request, year='', month='', day='', slug=''):
articles = Article.objects.all()
if year:
articles = articles.filter(date__year=year)
if month:
articles = articles.filter(date__month=month)
if day:
articles = articles.filter(date__day=day)
if title:
# Specific article
article = articles.filter(slug=slug)[0]
return render(request, 'blog_article.html', {'article' : article})
else:
# List of articles
objects = {
'articles' : articles,
}
return render(request, 'blog_index.html', objects)

View File

@ -4,7 +4,7 @@ from website.constants import *
class Game(models.Model):
# Static
titleid = models.CharField(max_length=9)
titleid = models.CharField(max_length=9, primary_key=True)
name = models.CharField(max_length=64)
publisher = models.CharField(max_length=64)
developer = models.CharField(max_length=64)

View File

@ -28,7 +28,7 @@
<li><a href='http://www.emunewz.net/forum/forumdisplay.php?fid=199'>Downloads</a></li>
<li><a href='/compat/'>Compatibility</a></li>
<li><a href='https://github.com/DHrpcs3/rpcs3/wiki/FAQ'>FAQ</a></li>
<li><a href='http://rpcs3.net/'>Blog</a></li>
<li><a href='/blog/'>Blog</a></li>
<li><a href='http://www.emunewz.net/forum/forumdisplay.php?fid=162'>Forum</a></li>
<li><a href='/contact/'>Contact</a></li>
</ul>