Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatih Erikli
committed
Feb 9, 2013
1 parent
1fe1f58
commit e4ee22e
Showing
18 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.contrib import admin | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from blog.models import Post | ||
|
||
|
||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ["title", "slug", "is_published"] | ||
list_filter = ["is_published"] | ||
search_fields = ["title", "slug", "content"] | ||
actions = ["publish", "mark_as_draft"] | ||
prepopulated_fields = { | ||
"slug": ("title", ) | ||
} | ||
|
||
def publish(self, request, qs): | ||
qs.update(is_published=True) | ||
publish.short_description = _("Publish selected posts") | ||
|
||
def mark_as_draft(self, request, qs): | ||
qs.update(is_published=False) | ||
mark_as_draft.short_description = _("Mark as draft selected posts") | ||
|
||
|
||
admin.site.register(Post, PostAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.db import models | ||
from django.utils.encoding import smart_unicode | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from markitup.fields import MarkupField | ||
|
||
class PublishedManager(models.Manager): | ||
""" | ||
Returns published blog posts. | ||
""" | ||
def get_query_set(self): | ||
return super(PublishedManager, self).get_query_set()\ | ||
.filter(is_published=True) | ||
|
||
class Post(models.Model): | ||
""" | ||
Holds blog post data. | ||
""" | ||
title = models.CharField(_("Name"), max_length=255) | ||
slug = models.SlugField(_("Slug"), max_length=255, unique=True) | ||
content = MarkupField(_("Content")) | ||
date_created = models.DateTimeField(auto_now_add=True) | ||
date_modified = models.DateTimeField(auto_now=True, auto_now_add=True) | ||
is_published = models.BooleanField(_("Published"), default=True) | ||
|
||
objects = models.Manager() | ||
published_objects = PublishedManager() | ||
|
||
class Meta: | ||
ordering = ("-date_created", ) | ||
|
||
def __unicode__(self): | ||
return smart_unicode(self.title) | ||
|
||
@models.permalink | ||
def get_absolute_url(self): | ||
return "blog_detail", [self.slug] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.contrib.sitemaps import Sitemap | ||
|
||
from blog.models import Post | ||
|
||
|
||
class BlogSitemap(Sitemap): | ||
changefreq = "never" | ||
priority = 0.9 | ||
|
||
def items(self): | ||
return Post.published_objects.all() | ||
|
||
def lastmod(self, obj): | ||
return obj.date_modified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.conf.urls import patterns, url | ||
|
||
from blog.sitemaps import BlogSitemap | ||
from blog.views import BlogDetailView, BlogIndexView, \ | ||
BlogPostsRssFeed, BlogPostsAtomFeed | ||
|
||
|
||
urlpatterns = patterns('', | ||
|
||
# blog urls | ||
url(r'^$', BlogIndexView.as_view(), name="blog"), | ||
url(r'^(?P<slug>[-\w]+)/$', BlogDetailView.as_view(), name="blog_detail"), | ||
|
||
# rss & atom feed | ||
url(r'^feed/rss$', BlogPostsRssFeed(), name="blog_rss_feed"), | ||
url(r'^feed/atom', BlogPostsAtomFeed(), name="blog_atom_feed"), | ||
|
||
# sitemap | ||
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', | ||
{'sitemaps': { | ||
"blog": BlogSitemap() | ||
}}, name="blog_sitemap"), | ||
|
||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.conf import settings | ||
from django.contrib.syndication.views import Feed | ||
from django.utils.feedgenerator import Atom1Feed | ||
from django.views.generic import ListView | ||
from django.views.generic.detail import DetailView | ||
|
||
from blog.models import Post | ||
|
||
|
||
class BlogIndexView(ListView): | ||
template_name="blog/index.html" | ||
queryset = Post.published_objects.all() | ||
context_object_name = "posts" | ||
paginate_by = 30 | ||
|
||
class BlogDetailView(DetailView): | ||
template_name= "blog/detail.html" | ||
model = Post | ||
context_object_name = "post" | ||
|
||
def get_queryset(self): | ||
if self.request.user.is_superuser: | ||
return self.model.objects.all() | ||
return self.model.published_objects.all() | ||
|
||
class BlogPostsRssFeed(Feed): | ||
title = settings.BLOG_FEED_TITLE | ||
link = settings.BLOG_URL | ||
description = settings.BLOG_FEED_DESCRIPTION | ||
|
||
def items(self): | ||
return Post.objects.all()[:20] | ||
|
||
def item_description(self, post): | ||
return post.content | ||
|
||
def item_pubdate(self, post): | ||
return post.date_created | ||
|
||
def item_categories(self, post): | ||
return [tag.name for tag in post.tags.all()] | ||
|
||
|
||
class BlogPostsAtomFeed(BlogPostsRssFeed): | ||
feed_type = Atom1Feed | ||
subtitle = settings.BLOG_FEED_DESCRIPTION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block footer %}{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends 'blog/base.html' %} | ||
|
||
{% block title %}{{ post.title }}{% endblock %} | ||
|
||
{% block content %} | ||
<section class="content"> | ||
{% include "blog/donation.html" %} | ||
{% include "blog/post.html" %} | ||
<article class="comments"> | ||
<section> | ||
<div id="disqus_thread"></div> | ||
<script type="text/javascript"> | ||
var disqus_shortname = 'dbpatterns'; | ||
(function() { | ||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | ||
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | ||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | ||
})(); | ||
</script> | ||
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | ||
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> | ||
|
||
</section> | ||
</article> | ||
</section> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<aside class="donation"> | ||
<h3>Donations</h3> | ||
<p>Dbpatterns is an open-source project that doesn't have any profit or revenue model. | ||
However dbpatterns needs donations to pay server expenses.</p> | ||
<p>If you want to help us, you can make donation to keep running dbpatterns.</p> | ||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> | ||
<input type="hidden" name="cmd" value="_s-xclick"> | ||
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHLwYJKoZIhvcNAQcEoIIHIDCCBxwCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYAZjk/TNXm1RyV/ilWnSyDiDlMppCXr7xn7cBJ5h5aCNzjI53xfYIenhUyFbktPFLH+6CVhROI8c+qGj7XdgnT9Tx0i0jEITrTWPkKx7hx4duWuzVaUeeip/9pnp2hzuYTexnCSO3INalbrIOLfmuxJbLZx8VyTFHHyWH0+eduzozELMAkGBSsOAwIaBQAwgawGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIz3bbtEsKLXCAgYhMIAMgvQQsBeI1BmxYocySqH3HQjZYVPp6hqrYEERmczn4eKvUFSWl2tV5bZ0X5sjY+qdpRM2Q0Ggtr4YA+AAuW1eNNletjt27faIpwlMtrpftH9DGsqSZnOdnzrA8ZyzKogYQoDNkzczUqKWF4aAON/5vu/O01/XJbuXjhDGSjmveaOjQ003IoIIDhzCCA4MwggLsoAMCAQICAQAwDQYJKoZIhvcNAQEFBQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMB4XDTA0MDIxMzEwMTMxNVoXDTM1MDIxMzEwMTMxNVowgY4xCzAJBgNV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DVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTMwMTI5MTEwNjA3WjAjBgkqhkiG9w0BCQQxFgQUPca31P/ua2cXY+ZIduP5XejoDyYwDQYJKoZIhvcNAQEBBQAEgYBPTyQ4btTNShDHanbOPrgVBiHuoWk/gMU+3LWTmzFmCbWZrbjUyNMezIs2X+8bEv8NJSO3gdvT97nXXbDuk0wDJ6TP02MOH1SBQHSfIY51DvSOZTcOV+1vPS/dLm6Jy7PWXVFco4I0NGMEhIQ/s0EbrrQ4COMHzw/vRMsF1bcwDQ==-----END PKCS7----- | ||
"> | ||
<input type="submit" class="donate" value="Donate"> | ||
<img alt="" border="0" src="https://www.paypalobjects.com/tr_TR/i/scr/pixel.gif" width="1" height="1"> | ||
</form> | ||
</aside> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<section class="content"> | ||
{% include "blog/donation.html" %} | ||
{% for post in posts %} | ||
{% include "blog/post.html" %} | ||
{% endfor %} | ||
{% include "blog/pagination.html" %} | ||
</section> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% if is_paginated %} | ||
{% if page_obj.has_next %} | ||
<a class="more" href="?page={{ page_obj.next_page_number }}">Show more</a> | ||
{% endif %} | ||
{% endif %} |
Oops, something went wrong.