Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
include =
publish/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*.pyc
*.swp
*.db
.idea
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: python

python:
- 2.7

env:
- DJANGO_VERSION=1.4.8
- DJANGO_VERSION=1.5.1

install:
- make setup
- pip install django==$DJANGO_VERSION

script: make test

after_success:
- coveralls
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
help:
@grep '^[^#[:space:]].*:' Makefile | awk -F ":" '{print $$1}'

clean:
@find . -name "*.pyc" -delete

deps:
@pip install -r requirements.txt
@pip install -r requirements_test.txt

setup: deps

test: clean deps
@nosetests -s -v --with-coverage
19 changes: 18 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Django Publish
==============

.. image:: https://travis-ci.org/petry/django-publish.png?branch=master
:target: https://travis-ci.org/petry/django-publish
:alt: CI status on Travis CI

.. image:: https://codeq.io/github/petry/django-publish/badges/master.png
:target: https://codeq.io/github/petry/django-publish/branches/master
:alt: Quality score on Codeq

.. image:: https://coveralls.io/repos/petry/django-publish/badge.png?branch=master
:target: https://coveralls.io/r/petry/django-publish
:alt: Coverage Status


Handy mixin/abstract class for providing a "publisher workflow" to arbitrary Django_ models.

Overview
Expand Down Expand Up @@ -187,7 +200,11 @@ To run the tests for this app use the script:

::

tests/run_tests.sh
$ make test


or simply ``$ nosetests`` on *publish* folder



.. _Django: http://www.djangoproject.com/
Expand Down
1 change: 1 addition & 0 deletions examplecms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'petry'
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 113 additions & 0 deletions examplecms/examplecms/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'example.db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}

ALLOWED_HOSTS = []

TIME_ZONE = 'America/Chicago'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')

MEDIA_URL = '/media/'

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (
)

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

SECRET_KEY = '6ec5dt14-0cxe!hha)um#y10$9o#r&p&mf&h%y9oj8dc@_el-j'

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

ROOT_URLCONF = 'examplecms.urls'

WSGI_APPLICATION = 'examplecms.wsgi.application'

TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.admin',

'publish',
'pubcms',
)

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
24 changes: 24 additions & 0 deletions examplecms/examplecms/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.conf import settings
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns(
'',
# Examples:
# url(r'^$', 'examplecms.views.home', name='home'),
# url(r'^examplecms/', include('examplecms.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT,
'show_indexes': True}),

url(r'^admin/', include(admin.site.urls)),
('^', include('pubcms.urls')),
)
32 changes: 32 additions & 0 deletions examplecms/examplecms/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
WSGI config for examplecms project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "examplecms.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "examplecms.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
10 changes: 10 additions & 0 deletions examplecms/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "examplecms.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
5 changes: 4 additions & 1 deletion examplecms/pubcms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
from publish.admin import PublishableAdmin, PublishableStackedInline
from pubcms.models import Page, PageBlock, Category, Image


class PageBlockInlineAdmin(PublishableStackedInline):
model = PageBlock
extra = 1


class PageAdmin(PublishableAdmin):
inlines = [PageBlockInlineAdmin]
prepopulated_fields = {"slug": ("title",)}
list_filter = ['publish_state', 'categories']


class CategoryAdmin(PublishableAdmin):
prepopulated_fields = {"slug": ("name",)}


admin.site.register(Page, PageAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Image, PublishableAdmin)

12 changes: 8 additions & 4 deletions examplecms/pubcms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
from django.core.urlresolvers import reverse as reverse_url
from publish.models import Publishable


class Page(Publishable):
title = models.CharField(max_length=200)
slug = models.CharField(max_length=100, db_index=True)
slug = models.CharField(max_length=100, db_index=True)

parent = models.ForeignKey('self', blank=True, null=True)

categories = models.ManyToManyField('Category', blank=True)

class PublishMeta(Publishable.PublishMeta):
publish_reverse_fields=['pageblock_set']
publish_reverse_fields = ['pageblock_set']

def __unicode__(self):
return self.title
Expand All @@ -30,18 +31,21 @@ def get_absolute_url(self):
else:
return reverse_url('draft_page_detail', args=[url])


class PageBlock(Publishable):
page = models.ForeignKey(Page)
content = models.TextField(blank=True)
image = models.ForeignKey('Image', blank=True, null=True)


class Image(Publishable):
title = models.CharField(max_length=100)
image = models.ImageField(upload_to='images/')

def __unicode__(self):
return self.title


class Category(Publishable):
name = models.CharField(max_length=200)
slug = models.CharField(max_length=100, db_index=True)
Expand Down
18 changes: 11 additions & 7 deletions examplecms/pubcms/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.conf.urls.defaults import *
from django.conf import settings
from django.conf.urls import patterns, url

from views import page_detail
from models import Page
from pubcms.views import page_detail
from pubcms.models import Page

urlpatterns = patterns('',
url('^(?P<page_url>.*)\*$', page_detail, { 'queryset': Page.objects.draft() }, name='draft_page_detail'),
url('^(?P<page_url>.*)$', page_detail, { 'queryset': Page.objects.published() }, name='public_page_detail'),
urlpatterns = patterns(
'',
url('^(?P<page_url>.*)\*$', page_detail,
{'queryset': Page.objects.draft()},
name='draft_page_detail'),
url('^(?P<page_url>.*)$', page_detail,
{'queryset': Page.objects.published()},
name='public_page_detail'),
)
7 changes: 3 additions & 4 deletions examplecms/pubcms/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.shortcuts import render_to_response, get_object_or_404

from models import Page

def page_detail(request, page_url, queryset):
parts = page_url.split('/')
Expand All @@ -10,6 +9,6 @@ def page_detail(request, page_url, queryset):
for slug in parts:
filter_params[field] = slug
field = 'parent__%s' % field
page = get_object_or_404(queryset,**filter_params)
return render_to_response("pubcms/page_detail.html", { 'page': page })
page = get_object_or_404(queryset, **filter_params)

return render_to_response("pubcms/page_detail.html", {'page': page})
3 changes: 0 additions & 3 deletions examplecms/runserver.sh

This file was deleted.

Loading