From: Brett Parker Date: Sun, 22 Mar 2009 16:28:59 +0000 (+0000) Subject: Update to 1.0 compatibility X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/2d5a803e2b8bd6ed72de946d4cfbb7b880493bf6?ds=sidebyside;hp=-c Update to 1.0 compatibility * Change admin registration and add registers for the right parts * Seperate cms url config from main site config * Update pagination views * Mark cms content as safe (will add a check with the clean function later, as validators have been deprecated) * update gitignore file to remove some other pants --- 2d5a803e2b8bd6ed72de946d4cfbb7b880493bf6 diff --git a/.gitignore b/.gitignore index 686a99c..f1fb70f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.py[oc] /sommitrealweird.db +/sommitrealweird/localsettings.py +/tmp diff --git a/sommitrealweird/blog/admin.py b/sommitrealweird/blog/admin.py new file mode 100644 index 0000000..8b3dcf9 --- /dev/null +++ b/sommitrealweird/blog/admin.py @@ -0,0 +1,13 @@ +from models import BlogEntry, BlogSection +from django.contrib import admin + +class BlogEntryAdmin(admin.ModelAdmin): + prepulated_fields = { "slug": ("title") } + +#admin.site.register(BlogEntry, BlogEntryAdmin) + +class BlogSectionAdmin(admin.ModelAdmin): + prepopulated_fields = { "slug": ("title") + +#admin.site.register(BlogSection, BlogSectionAdmin) + diff --git a/sommitrealweird/blog/models.py b/sommitrealweird/blog/models.py index 7573674..1634754 100644 --- a/sommitrealweird/blog/models.py +++ b/sommitrealweird/blog/models.py @@ -1,5 +1,6 @@ from django.db import models from django.conf import settings +from django.contrib import admin FORMAT_CHOICES = ( ('rst', 'reStructuredText'), @@ -7,11 +8,11 @@ FORMAT_CHOICES = ( ) class BlogEntry(models.Model): - title = models.CharField(maxlength=150) + title = models.CharField(max_length=150) islive = models.BooleanField() sections = models.ManyToManyField('BlogSection') - format = models.CharField(maxlength=10, choices=FORMAT_CHOICES) - slug = models.SlugField(prepopulate_from=("title",)) + format = models.CharField(max_length=10, choices=FORMAT_CHOICES) + slug = models.SlugField() publish_date = models.DateTimeField() content = models.TextField() @@ -27,12 +28,9 @@ class BlogEntry(models.Model): class Meta: ordering = ['-publish_date'] - class Admin: - pass - class BlogSection(models.Model): - title = models.CharField(maxlength=150) - slug = models.SlugField(prepopulate_from=("title",)) + title = models.CharField(max_length=150) + slug = models.SlugField() def __str__(self): return self.__unicode__() @@ -42,6 +40,3 @@ class BlogSection(models.Model): def get_absolute_url(self): return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug) - - class Admin: - pass diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index d5da81b..b01bec8 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -1,7 +1,7 @@ from blog.models import BlogEntry, BlogSection from django.http import Http404, HttpResponse from django.template import RequestContext, loader -from django.core.paginator import ObjectPaginator +from django.core.paginator import Paginator from django.conf import settings def blog_index(request, section=None): @@ -11,23 +11,24 @@ def blog_index(request, section=None): entries = entries.order_by('-publish_date') if entries: paginate_by=20 - paginator = ObjectPaginator(entries, paginate_by) - page = int(request.GET.get('page', 0)) - if page > 0: - page = page - 1 - paginated_entries = paginator.get_page(page) - pages = [i for i in range(1, paginator.pages + 1)] + paginator = Paginator(entries, paginate_by) + try: + page = int(request.GET.get('page', 1)) + except ValueError: + page = 1 + paginated_entries = paginator.page(page) + pages = paginator.page_range t = loader.get_template("blog/blog_index.html") c = RequestContext(request, { - "entries": paginated_entries, + "entries": paginated_entries.object_list, "title": settings.BLOG_TITLE, - "page": page + 1, + "page": page, "pages": pages, "paginated": 1, - "has_next": paginator.has_next_page(page), - "has_prev": paginator.has_next_page(page), - "next": page + 2, + "has_next": paginated_entries.has_next(), + "has_prev": paginated_entries.has_previous(), + "next": page + 1, "prev": page - 1 }) return HttpResponse(t.render(c)) diff --git a/sommitrealweird/bpcms/admin.py b/sommitrealweird/bpcms/admin.py new file mode 100644 index 0000000..2c4c86d --- /dev/null +++ b/sommitrealweird/bpcms/admin.py @@ -0,0 +1,12 @@ +from models import Document, Folder +from django.contrib import admin + +class DocumentAdmin(admin.ModelAdmin): + prepopulated_fields = { "slug": ("title",) } + +admin.site.register(Document, DocumentAdmin) + +class FolderAdmin(admin.ModelAdmin): + prepopulated_fields = { "slug": ("title",) } + +admin.site.register(Folder, FolderAdmin) diff --git a/sommitrealweird/bpcms/models.py b/sommitrealweird/bpcms/models.py index ad88e4a..bf2b93b 100644 --- a/sommitrealweird/bpcms/models.py +++ b/sommitrealweird/bpcms/models.py @@ -1,6 +1,6 @@ from django.db import models -from bpcms.content_val import is_allowed_name from django.conf import settings +from django.contrib import admin FORMAT_CHOICES = ( ('rst', 'reStructuredText'), @@ -8,11 +8,11 @@ FORMAT_CHOICES = ( ) class Document(models.Model): - title = models.CharField(maxlength=150) + title = models.CharField(max_length=150) islive = models.BooleanField() folder = models.ForeignKey('Folder', null=True, blank=True) - format = models.CharField(maxlength=10, choices=FORMAT_CHOICES) - slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_allowed_name,]) + format = models.CharField(max_length=10, choices=FORMAT_CHOICES) + slug = models.SlugField() content = models.TextField() def __str__(self): @@ -47,21 +47,18 @@ class Document(models.Model): return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug) - class Admin: - pass - class Folder(models.Model): - title = models.CharField(maxlength=150) - slug = models.SlugField(prepopulate_from=("title",), validator_list=[is_allowed_name,]) + title = models.CharField(max_length=150) + slug = models.SlugField() parent = models.ForeignKey('self', null=True, blank=True) def __str__(self): return self.__unicode__() def __unicode__(self): - return u'%s' %(self.title) + return u'%s - %s' %(self.get_path(), self.title) - def get_basic_url(self): + def get_path(self): folders = [] curfolder = self while curfolder != None: @@ -73,7 +70,7 @@ class Folder(models.Model): if folderstring != u'': folderstring = "%s/" %(folderstring,) - return "%s%s" %(settings.BPCMS_ROOT, folderstring) - - class Admin: - pass + return folderstring + + def get_basic_url(self): + return "%s%s" %(settings.BPCMS_ROOT, self.get_path()) diff --git a/sommitrealweird/bpcms/templates/bpcms/html.html b/sommitrealweird/bpcms/templates/bpcms/html.html index 910429a..b6466bb 100644 --- a/sommitrealweird/bpcms/templates/bpcms/html.html +++ b/sommitrealweird/bpcms/templates/bpcms/html.html @@ -3,5 +3,5 @@ {% block content %}

{{ title }}

-{{ content }} +{{ content|safe }} {% endblock %} diff --git a/sommitrealweird/bpcms/templates/bpcms/rst.html b/sommitrealweird/bpcms/templates/bpcms/rst.html index 2b474b8..5257b78 100644 --- a/sommitrealweird/bpcms/templates/bpcms/rst.html +++ b/sommitrealweird/bpcms/templates/bpcms/rst.html @@ -3,5 +3,5 @@ {% block content %}

{{ title }}

-{{ content|restructuredtext }} +{{ content|restructuredtext|safe }} {% endblock %} diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py new file mode 100644 index 0000000..9143a67 --- /dev/null +++ b/sommitrealweird/bpcms/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('', + (r'^$', 'bpcms.views.document_view', {'slug': 'index'}), + (r'^(?P[^/]+)/$', 'bpcms.views.document_view'), + (r'^(?P.*)/(?P[^/]+)/$', 'bpcms.views.document_view'), +) + diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index b709acc..8415b54 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -1,6 +1,7 @@ from django.conf.urls.defaults import * from settings import MEDIA_ROOT, MEDIA_URL from blog.feeds import LatestBlogEntries +from django.contrib import admin handler404 = 'generic.views.render_404' @@ -8,6 +9,8 @@ feeds_dict = { 'blog': LatestBlogEntries, } +#admin.autodiscover() + urlpatterns = patterns('', # Example: # (r'^sommitrealweird/', include('sommitrealweird.foo.urls')), @@ -15,9 +18,8 @@ urlpatterns = patterns('', # Uncomment this for admin: (r'^$', 'bpcms.views.document_view', {'slug': 'index'}), (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}), - (r'^admin/', include('django.contrib.admin.urls')), + (r'^admin/(.*)$', admin.site.root), (r'^blog/', include('blog.urls')), (r'^feeds/(?P.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds_dict}), - (r'^(?:content/|)(?P[^/]+)/$', 'bpcms.views.document_view'), - (r'^(?:content/|)(?P.*)/(?P[^/]+)/$', 'bpcms.views.document_view'), + (r'^(?:content/|)', include('bpcms.urls')) )