Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Commit

Permalink
initial commit of version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanfoulis committed Aug 18, 2010
0 parents commit 691dcb0
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.pyc
*.pyo
.installed.cfg
bin
develop-eggs
dist
downloads
eggs
parts
build
*.egg-info
.DS_Store
.project
.pydevproject
*~
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include metadata.py
include README
recursive-include contentblock/locale *
15 changes: 15 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A simple app that allows using Multilingual contentblock using Placeholders from django-cms

Installation:
pip install django-contentblock
dependencies: django-cms, django-multilingual-ng

Setup:
add 'contentblock' to INSTALLED_APPS

Usage:
In Admin create a Content block and give it a codename, e.g 'myprettyblock'

In your template:
{% load contentblock_tags %}
{% contentblock 'myprettyblock' %}
1 change: 1 addition & 0 deletions contentblock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.0'
8 changes: 8 additions & 0 deletions contentblock/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from contentblock.models import ContentBlock
from multilingual.admin import MultilingualModelAdmin, MultilingualInlineAdmin
from cms.admin.placeholderadmin import PlaceholderAdmin

class ContentBlockAdmin(MultilingualModelAdmin, PlaceholderAdmin):
list_display = ('code','name',)
admin.site.register(ContentBlock, ContentBlockAdmin)
64 changes: 64 additions & 0 deletions contentblock/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

class Migration(SchemaMigration):

def forwards(self, orm):

# Adding model 'ContentBlockTranslation'
db.create_table('contentblock_contentblock_translation', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('text', self.gf('django.db.models.fields.related.ForeignKey')(related_name='contentblock_texts', null=True, to=orm['cms.Placeholder'])),
('language_code', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=15, blank=True)),
('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', to=orm['contentblock.ContentBlock'])),
))
db.send_create_signal('contentblock', ['ContentBlockTranslation'])

# Adding unique constraint on 'ContentBlockTranslation', fields ['language_code', 'master']
db.create_unique('contentblock_contentblock_translation', ['language_code', 'master_id'])

# Adding model 'ContentBlock'
db.create_table('contentblock_contentblock', (
('code', self.gf('django.db.models.fields.CharField')(unique=True, max_length=16, primary_key=True, db_index=True)),
('name', self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True)),
))
db.send_create_signal('contentblock', ['ContentBlock'])


def backwards(self, orm):

# Removing unique constraint on 'ContentBlockTranslation', fields ['language_code', 'master']
db.delete_unique('contentblock_contentblock_translation', ['language_code', 'master_id'])

# Deleting model 'ContentBlockTranslation'
db.delete_table('contentblock_contentblock_translation')

# Deleting model 'ContentBlock'
db.delete_table('contentblock_contentblock')


models = {
'cms.placeholder': {
'Meta': {'object_name': 'Placeholder'},
'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
},
'contentblock.contentblock': {
'Meta': {'object_name': 'ContentBlock'},
'code': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16', 'primary_key': 'True', 'db_index': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
},
'contentblock.contentblocktranslation': {
'Meta': {'ordering': "('language_code',)", 'unique_together': "(('language_code', 'master'),)", 'object_name': 'ContentBlockTranslation', 'db_table': "'contentblock_contentblock_translation'"},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language_code': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '15', 'blank': 'True'}),
'master': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'translations'", 'to': "orm['contentblock.ContentBlock']"}),
'text': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'contentblock_texts'", 'null': 'True', 'to': "orm['cms.Placeholder']"})
}
}

complete_apps = ['contentblock']
Empty file.
15 changes: 15 additions & 0 deletions contentblock/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.db import models
from multilingual.translation import TranslationModel
from cms.models.fields import PlaceholderField
from cms.utils import placeholder
from django.utils.translation import ugettext_lazy as _

class ContentBlock(models.Model):
code = models.CharField(max_length=16, unique=True, db_index=True, primary_key=True)
name = models.CharField(max_length=255, blank=True, default='')
class Translation(TranslationModel):
text = PlaceholderField(slotname='contentblock_text',
verbose_name=_('text'),
actions=placeholder.MLNGPlaceholderActions,
related_name='contentblock_texts')
noml = models.Manager()
Empty file.
49 changes: 49 additions & 0 deletions contentblock/templatetags/contentblock_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django import template
import re
from django.utils.safestring import mark_safe
from contentblock import models as contentblock_models

register = template.Library()

class ContentblockNode(template.Node):
def __init__(self, code, var_name):
self.code = code
self.var_name = var_name
def render(self, context):
try:
cb = contentblock_models.ContentBlock.objects.get(code=self.code)
except contentblock_models.ContentBlock.DoesNotExist:
return ''
if not cb.text:
return ''
placeholder = cb.text
rendered_placeholder = mark_safe(placeholder.render(context, None))
if self.var_name:
context[self.var_name] = rendered_placeholder
return ''
return rendered_placeholder

def do_contentblock(parser, token):
'''
parses the parameters of the templatetag
{% contentblock 'my_block_name' %}
{% contentblock 'my_block_name' as my_varname %}
'''
try:
# Splitting by None == splitting by spaces.
tag_name, arg = token.contents.split(None, 1)
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires arguments" % token.contents.split()[0]
m = re.search(r'(.*?) as (\w+)$', arg)
m2 = re.search(r'(.*?)$', arg)
if m:
code_string, var_name = m.groups()
elif m2 and len(m2.groups())==1:
code_string = m2.groups()[0]
var_name = None
else:
raise template.TemplateSyntaxError, "%r tag had invalid arguments" % tag_name
if not (code_string[0] == code_string[-1] and code_string[0] in ('"', "'")):
raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
return ContentblockNode(code_string[1:-1], var_name)
register.tag('contentblock', do_contentblock)
8 changes: 8 additions & 0 deletions metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package_name = 'contentblock'
name = 'django-contentblock'
author = 'Divio GmbH'
author_email = 'developers@divio.ch'
description = "A simple app that allows using Multilingual contentblock using Placeholders from django-cms"
version = __import__(package_name).__version__
project_url = 'http://github.com/divio/%s' % name
license = 'BSD'
59 changes: 59 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'''
setup.py version 0.0.1
current version: https://gist.github.com/8668de36c00ca78df172
This is a standard re-usable setup.py file for django apps.
This file should stay untouched. Instead create a file called metadata.py.
metadata.py example:
package_name = 'gsa'
name = 'django-gsa'
author = 'Divio GmbH'
author_email = 'developers@divio.ch'
description = "A thin wrapper for using a Google Search Appliance (GSA) for searches in django.s."
version = '0.1.0'
project_url = 'http://github.com/divio/%s' % name
license = 'BSD'
If you have data files you want to include, please create a MANIFEST.in file.
setup.py is called with include_package_data=True, so packade data will be
automatically read and included based on MANIFEST.in (or from svn if you
happen to use it)
'''

# do not change anything in here
# edit metadata.py and MANIFEST.in instead
import metadata as m

from setuptools import setup, find_packages

install_requires = [
'setuptools',
]

setup(
name = m.name,
version = m.version,
url = m.project_url,
license = m.license,
platforms=['OS Independent'],
description = m.description,
author = m.author,
author_email = m.author_email,
packages=find_packages(),
install_requires = install_requires,
include_package_data = True, #Accept all data files and directories matched by MANIFEST.in or found in source control.
package_dir = {
m.package_name:m.package_name,
},
zip_safe=False,
classifiers = [
'Development Status :: 4 - Beta',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP',
]
)

0 comments on commit 691dcb0

Please sign in to comment.