Cms - Content Management System Utilities for Django

3,668 views

Published on

I used these slides for a presentation at the Barcelona Python Meetup in April 2008.

https://tracpub.yaco.es/cmsutils/

Cmsutils for Django is a bundle of models and templates for Django projects in need of some Content Management System features.

Published in: Business, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,668
On SlideShare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
Downloads
92
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Cms - Content Management System Utilities for Django

  1. 1. Cmsutils Content Management System Utilities for Django Maik Röder Yaco Sistemas Python Meetup Barcelona 3.4.2008
  2. 2. Cmsutils <ul><li>GPL License </li></ul><ul><li>https://tracpub.yaco.es/cmsutils/ </li></ul><ul><li>Yaco Sistemas </li></ul><ul><li>http://www.yaco.es </li></ul><ul><li>BTW: We hire Python developers! </li></ul><ul><li>Features </li></ul><ul><li>Generic parameters from database </li></ul><ul><li>Generic reusable forms based on newforms </li></ul><ul><li>Generic views and templates for things like deleting objects </li></ul><ul><li>Breadcrumb templatetag </li></ul><ul><li>Messagebox </li></ul><ul><li>Merging and compressing JS and CSS </li></ul><ul><li>LDAP authentication </li></ul>
  3. 3. Cmsutils <ul><li>Parameter model for customer specific parameters </li></ul><ul><ul><li>administrator email </li></ul></ul><ul><ul><li>contact information </li></ul></ul><ul><ul><li>copyright </li></ul></ul><ul><li>Useful in Templates </li></ul><ul><li>{% load parameter %} </li></ul><ul><li><strong>Information successfully sended to {{ param &quot;default_email&quot; }}</strong> </li></ul><ul><li>Useful in your Django models: </li></ul><ul><li>def fooview(request): </li></ul><ul><li>default_email = Parameter.objects.get_value(&quot;default_email&quot;, settings.DEFAULT_FROM_EMAIL) </li></ul>
  4. 4. Cmsutils <ul><li>Generic reusable forms based on newforms. </li></ul><ul><ul><li>GenericForm </li></ul></ul><ul><ul><li>GenericAddForm </li></ul></ul><ul><ul><li>GenericEditForm </li></ul></ul><ul><li>EditForm Example </li></ul><ul><li>class AuthorEditForm(GenericAddForm): </li></ul><ul><li>template = 'authors/edit.html' </li></ul><ul><li>class Meta: </li></ul><ul><li>model = Author </li></ul><ul><li>fields = ('name', 'description',) </li></ul><ul><li>def edit(request, author_id): </li></ul><ul><li>author = get_object_or_404(Author, pk=author_id) </li></ul><ul><li>form = AuthorEditForm(request, author) </li></ul><ul><li>return form.run() </li></ul>
  5. 5. Cmsutils <ul><li>Generic views and templates for things like deleting objects </li></ul><ul><li>confirm_delete.html </li></ul><ul><li>delete_link.html </li></ul><ul><li>edit_object.html </li></ul><ul><li>def confirm_delete_object(request): </li></ul><ul><li>content_type_id = request.GET.get('content_type_id', None) </li></ul><ul><li>object_id = request.GET.get('object_id', None) </li></ul><ul><li>if content_type_id is None or object_id is None: </li></ul><ul><li>raise Http404 </li></ul><ul><li>return render_to_response('cmsutils/confirm_delete.html', </li></ul><ul><li>{'content_type_id': content_type_id, </li></ul><ul><li>'object_id': object_id}, </li></ul><ul><li>context_instance=RequestContext(request)) </li></ul>
  6. 6. Cmsutils <ul><li>Breadcrumb templatetag </li></ul><ul><li>{% load breadcrumbs %} </li></ul><ul><li><body> </li></ul><ul><li>{% breadcrumbs News:/news/ object %} </li></ul><ul><li>... </li></ul><ul><li></body> </li></ul><ul><li>HTML Output: </li></ul><ul><li><div class=&quot;breadcrumbs&quot;> </li></ul><ul><li><li class=&quot;previous&quot;><a href=&quot;/&quot;>Home</a> | </li> </li></ul><ul><li><li class=&quot;previous&quot;><a href=&quot;/news/&quot;>News</a> | </li> </li></ul><ul><li><li><a href=&quot;/news/1/&quot;>Foo news item</a></li> </li></ul><ul><li></div> </li></ul>
  7. 7. Cmsutils <ul><li>Messagebox </li></ul><ul><li>{% autoescape off %} </li></ul><ul><li>{% if portal_messages %} </li></ul><ul><li><ul id=&quot;info-list&quot;> </li></ul><ul><li>{% for message in portal_messages %} </li></ul><ul><li><li>{{ message }}</li> </li></ul><ul><li>{% endfor %} </li></ul><ul><li></ul> </li></ul><ul><li>{% endif %} </li></ul><ul><li>{% endautoescape %} </li></ul>
  8. 8. Cmsutils <ul><li>Merging and compressing JS and CSS </li></ul><ul><li>This will merge css/javascript files in only one compressed css/javascript. </li></ul><ul><li>Usage: </li></ul><ul><li>{% load [js|css]merge %} </li></ul><ul><li>{% [js|css]merge name [file1] [file2] .. %} </li></ul><ul><li>Example: </li></ul><ul><li>{% load jsmerge %} </li></ul><ul><li>{% jsmerge jsmergefile js/file1.js js/file2.js js/file3.js %} </li></ul><ul><li>This will create (if not exists) a /media/jsmergefile.js with three </li></ul><ul><li>files merged. The HTML output for this will be: </li></ul><ul><li><script type=&quot;text/javascript&quot; src=&quot;/media/jsmergefile.js&quot;></script> </li></ul>
  9. 9. Cmsutils <ul><li>LDAP authentication </li></ul><ul><li>AUTHENTICATION_BACKENDS = ( </li></ul><ul><li>'cmsutils.auth.backends.LDAPBackend', </li></ul><ul><li>'django.contrib.auth.backends.ModelBackend', </li></ul><ul><li>) </li></ul><ul><li>AUTH_LDAP_SERVER = 'ldap.foo.com' </li></ul><ul><li>AUTH_LDAP_BIND_USERNAME = 'cn=admin,dc=ldap,dc=foo,dc=com' </li></ul><ul><li>AUTH_LDAP_BIND_PASSWORD = 'foopasswd' </li></ul><ul><li>AUTH_LDAP_SUBTREE = 'ou=People,dc=ldap,dc=foo,dc=com' </li></ul><ul><li>AUTH_LDAP_FILTER = '(&(objectclass=person) (uid=%s))' </li></ul><ul><li>AUTH_LDAP_MAP = {'login': 'uid', 'name': 'cn', 'surname': 'sn', 'mail': 'mail'} </li></ul>
  10. 10. Cmsutils Check it out! <ul><li>https://tracpub.yaco.es/cmsutils </li></ul><ul><li>svn checkout http://svnpub.yaco.es/cmsutils/trunk cmsutils </li></ul>

×