]> git.sommitrealweird.co.uk Git - sommitrealweird.git/commitdiff
Update to 1.0 compatibility
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 22 Mar 2009 16:28:59 +0000 (16:28 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 22 Mar 2009 16:28:59 +0000 (16:28 +0000)
* 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

.gitignore
sommitrealweird/blog/admin.py [new file with mode: 0644]
sommitrealweird/blog/models.py
sommitrealweird/blog/views.py
sommitrealweird/bpcms/admin.py [new file with mode: 0644]
sommitrealweird/bpcms/models.py
sommitrealweird/bpcms/templates/bpcms/html.html
sommitrealweird/bpcms/templates/bpcms/rst.html
sommitrealweird/bpcms/urls.py [new file with mode: 0644]
sommitrealweird/urls.py

index 686a99c07e661b3a33ee82de998fb88544e49530..f1fb70f45d06fa4c59f7b17d6b46ca952aa7e161 100644 (file)
@@ -1,2 +1,4 @@
 *.py[oc]
 /sommitrealweird.db
 *.py[oc]
 /sommitrealweird.db
+/sommitrealweird/localsettings.py
+/tmp
diff --git a/sommitrealweird/blog/admin.py b/sommitrealweird/blog/admin.py
new file mode 100644 (file)
index 0000000..8b3dcf9
--- /dev/null
@@ -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)
+
index 757367423f49ed207a033785c9367152a81e6b72..16347546e110e58a1f93fec0b4a5db79b9da82be 100644 (file)
@@ -1,5 +1,6 @@
 from django.db import models
 from django.conf import settings
 from django.db import models
 from django.conf import settings
+from django.contrib import admin
 
 FORMAT_CHOICES = (
     ('rst', 'reStructuredText'),
 
 FORMAT_CHOICES = (
     ('rst', 'reStructuredText'),
@@ -7,11 +8,11 @@ FORMAT_CHOICES = (
 )
 
 class BlogEntry(models.Model):
 )
 
 class BlogEntry(models.Model):
-    title = models.CharField(maxlength=150)
+    title = models.CharField(max_length=150)
     islive = models.BooleanField()
     sections = models.ManyToManyField('BlogSection')
     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()
 
     publish_date = models.DateTimeField()
     content = models.TextField()
 
@@ -27,12 +28,9 @@ class BlogEntry(models.Model):
     class Meta:
         ordering = ['-publish_date']
 
     class Meta:
         ordering = ['-publish_date']
 
-    class Admin:
-        pass
-
 class BlogSection(models.Model):
 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__()
 
     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)
 
     def get_absolute_url(self):
         return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)
-
-    class Admin:
-        pass
index d5da81b09fac29b559b1a8044ac3bd2720682446..b01bec8dcbffaf5bf3de08e7450a0869df19458d 100644 (file)
@@ -1,7 +1,7 @@
 from blog.models import BlogEntry, BlogSection
 from django.http import Http404, HttpResponse
 from django.template import RequestContext, loader
 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):
 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
     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,
             {
         t = loader.get_template("blog/blog_index.html")
         c = RequestContext(request,
             {
-                "entries": paginated_entries,
+                "entries": paginated_entries.object_list,
                 "title": settings.BLOG_TITLE,
                 "title": settings.BLOG_TITLE,
-                "page": page + 1,
+                "page": page,
                 "pages": pages,
                 "paginated": 1,
                 "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))
                 "prev": page - 1
             })
         return HttpResponse(t.render(c))
diff --git a/sommitrealweird/bpcms/admin.py b/sommitrealweird/bpcms/admin.py
new file mode 100644 (file)
index 0000000..2c4c86d
--- /dev/null
@@ -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)
index ad88e4ab14d2de1654db30c83b1540035f7fd73e..bf2b93b019086fc551e1df331b0664a7568c86c7 100644 (file)
@@ -1,6 +1,6 @@
 from django.db import models
 from django.db import models
-from bpcms.content_val import is_allowed_name
 from django.conf import settings
 from django.conf import settings
+from django.contrib import admin
 
 FORMAT_CHOICES = (
         ('rst', 'reStructuredText'),
 
 FORMAT_CHOICES = (
         ('rst', 'reStructuredText'),
@@ -8,11 +8,11 @@ FORMAT_CHOICES = (
     )
 
 class Document(models.Model):
     )
 
 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)
     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):
     content = models.TextField()
 
     def __str__(self):
@@ -47,21 +47,18 @@ class Document(models.Model):
 
         return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
 
 
         return "%s%s%s/" %(settings.BPCMS_ROOT, folderstring, self.slug)
 
-    class Admin:
-        pass
-
 class Folder(models.Model):
 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):
     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:
         folders = []
         curfolder = self
         while curfolder != None:
@@ -73,7 +70,7 @@ class Folder(models.Model):
         if folderstring != u'':
             folderstring = "%s/" %(folderstring,)
 
         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())
index 910429a8f51f6a30e55a6c2d3438eaf279640029..b6466bbdcf094567a36e019d473f3a41b22b72ac 100644 (file)
@@ -3,5 +3,5 @@
 
 {% block content %}
 <h1>{{ title }}</h1>
 
 {% block content %}
 <h1>{{ title }}</h1>
-{{ content }}
+{{ content|safe }}
 {% endblock %}
 {% endblock %}
index 2b474b80588c59405256f2e55cf8cefb4f87fe93..5257b78e523c0d24198e272808879b608c4e12b6 100644 (file)
@@ -3,5 +3,5 @@
 
 {% block content %}
 <h1>{{ title }}</h1>
 
 {% block content %}
 <h1>{{ title }}</h1>
-{{ content|restructuredtext }}
+{{ content|restructuredtext|safe }}
 {% endblock %}
 {% endblock %}
diff --git a/sommitrealweird/bpcms/urls.py b/sommitrealweird/bpcms/urls.py
new file mode 100644 (file)
index 0000000..9143a67
--- /dev/null
@@ -0,0 +1,8 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+    (r'^$', 'bpcms.views.document_view', {'slug': 'index'}),
+    (r'^(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
+    (r'^(?P<folders>.*)/(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
+)
+
index b709acced792c93e27330fea820be3f1576d06d8..8415b54f82cb15f224421e187a4d37e13e62a32e 100644 (file)
@@ -1,6 +1,7 @@
 from django.conf.urls.defaults import *
 from settings import MEDIA_ROOT, MEDIA_URL
 from blog.feeds import LatestBlogEntries
 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'
 
 
 handler404 = 'generic.views.render_404'
 
@@ -8,6 +9,8 @@ feeds_dict = {
     'blog': LatestBlogEntries,
     }
 
     'blog': LatestBlogEntries,
     }
 
+#admin.autodiscover()
+
 urlpatterns = patterns('',
     # Example:
     # (r'^sommitrealweird/', include('sommitrealweird.foo.urls')),
 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<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT, 'show_indexes': True}),
     # Uncomment this for admin:
     (r'^$', 'bpcms.views.document_view', {'slug': 'index'}),
     (r'^media/(?P<path>.*)$', '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<url>.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds_dict}),
     (r'^blog/', include('blog.urls')),
     (r'^feeds/(?P<url>.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds_dict}),
-    (r'^(?:content/|)(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
-    (r'^(?:content/|)(?P<folders>.*)/(?P<slug>[^/]+)/$', 'bpcms.views.document_view'),
+    (r'^(?:content/|)', include('bpcms.urls'))
 )
 )