A pro-Django presentation: Brandon W. King SoCal Piggies - May 2007.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
CS125 Honors Project Illini TIX Austin Kramer Peter Kowalczyk Rohan Kapoor Jay Bensal.
Rapid Web Development with Python/Django Julian Hill.
건전지로 달리는 쟝고 세미나. 정재성 Django Web Framework CGI.
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Extending JIRA Rachel Wright July 15, 2014 See slide “Notes” section for commentary and talking points.
Introducing new web content management tools for Priority...
Jonathan Voigt University of Michigan Soar Workshop 25
Web Page Behavior IS 373—Web Standards Todd Will.
1 of 5 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
Drupal Workshop Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology, Drupal technology, directories.
Web frameworks design comparison draft - please help me improve it.
Web Development Methodologies Yuan Wang(yw2326). Basic Concepts Browser/Server (B/S) Structure Keywords: Browser, Server Examples: Websites Client/Server.
 >> django-admin.py startproject mysite /mysite __init__.py manage.py settings.py urls.py.
Web Frameworks: Django Department of Biomedical Informatics University of Pittsburgh School of Medicine
Django Web Framework 김형용, 이정민 Framework 2.1. Django High-level Python Web Framework Develop fast Automate the repetitive stuff Follow best practices.
Dataface API Essentials Steve Hannah Web Lite Solutions Corp.
Dj(T)ango with Python Ritika Virmani. What is Django? It’s not a Hawaiian dance Developed by Adrian Holovaty and Simon Willison Rapid Web Development.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
UVa cs1120 David Evans Lecture 34: Djustifying Django.
Mr. Rouda’s CSCI 101 sections. What does a web page consist of? Code HTML, CSS, XHTML, XML, etc. Images Gif, jpg, png, etc. Plugins Swf, flv, etc. JavaScript.
건전지로 달리는 쟝고 세미나. 파트2 Last time MVC Views and URLconfs.
CPSC 203 Introduction to Computers T59 & T64 By Jie (Jeff) Gao.
CMS I – BASIC WEB EDITING INTRODUCTION TO THE CMS Presented By: Rodneikka Scott, MS – Implementation Project Manager Lila Elliott, MA – Manager Client.
Web Technologies Website Development Trade & Industrial Education
Creating Effective School and PTA Websites Sam Farnsworth Utah PTA Technology Specialist
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
Updating the School Website St George’s C of E (V.A.) Primary School.
Programming in HTML.  Programming Language  Used to design/create web pages  Hyper Text Markup Language  Markup Language  Series of Markup tags 
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Presenter- Deborah Coker  Advantages of having a site  Features you may want to have on your site  Menus, Tabs, and Ribbons  Creating.
HTML Hyper Text Markup Language A simple introduction.
Chapter 3 – Part 1 Word Processing Writer for Linux CMPF 112 : COMPUTING SKILLS.
Presented by Graduate Design Group 2 Meredith, Jennifer, Cammay and Diane.
Introduction to Web AppBuilder for ArcGIS: JavaScript Apps Made Easy
Seattle Drupal Clinic Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology.
Google App Engine Using Templates Jim Eng Thanks to Chuck Severance
Django 101 By: Jason Sumner. Django Overview Django was started in 2003, released under BSD in 2005, and the Django Software Foundation was established.
Google App Engine Data Store ae-10-datastore
Courselist Project Automated Graduate Student Information System Final project for CS 3354.
Drupal for client Maria Sherskova skype: sherskova.
CD Web XMS Training How to use the Xeno Media web site content management system.
Facebook is a social utility that connects you with the people around you. Use Facebook to…  Keep up with friends and family  Share photos and videos.
Drupal Recipe: Before and After Gallery Lisa Forgan and Chris Neglia, using notes from Drupal Camp Colorado Copyright 2009, Page 1 Solutions LLC.
CPSC 203 Introduction to Computers T97 By Jie (Jeff) Gao.
HTML Hyper Text Markup Language. The Basics u HTML documents contain “tags” which instruct the Browser software on how to present the information within.
Develop Your Web Presence Using WEEBLY TECHNO DRAGON PD | WEEBLY.
What is ? ●It is a Halton District School Board term ●It is HDSB use of Google Apps for education. It includes: ■ Google Docs ■ Google Drive ■ Google Applications.
What Is Firefox? __________ is a Web ___________ that you use to search for and view Web pages, save pages for use in the future, and maintain a list.
The Django Web Application Framework zhixiong.hong
HTML Hyper Text Markup Language. Agenda Basics Tools Important tags Tables & databases Forms Publishing at Stern.
Joomla Awdhesh Kumar Singsys Pte Ltd. What is Joomla? Joomla is an award-winning content management system (CMS), which enables you to build Web sites.
How to use Drupal Awdhesh Kumar (Team Leader) Presentation Topic.
How to use.
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Content Management System
Basic Web Scraping with Python
Django in the real world
How to Maintain Your ARS Websites
Download from Zotero Home Page
Dongwhan Kim Annie Zhao Steven Lawrance
A02 Creating my website NAME ______________.
Lecture 21 More On Django.
Query Interface using Django
Presentation transcript:

A pro-Django presentation: Brandon W. King SoCal Piggies - May 2007

Non-wiki wiki?  A website that looks like a website, but behaves like a wiki.  Mediawiki, MoinMoin, look like wikis.  Websites tend to have navigation menus.  Wikis tend to have navigation within the wiki page.

Why?  I wanted a web site for the lab that: Looked like a website. Had a menu manager. And could be edited by biologists in the lab.

Requirements  Has to be written faster than Diane can learn Zope.  Allowing edits from command-line.  Revision control of pages

The How: Oswd.org Django PySVN FCKEditor

Initialize Django  Django-admin.py startproject woldcms  woldcms/ __init__.py manage.py settings.py urls.py

Manage.py is your friend  cd woldcms/  python manage.py startapp pages  woldcms/pages/ __init__.py models.py views.py

Update woldcms/settings.py  Update database settings: DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'. DATABASE_NAME = '/home/king/proj/woldlab-2.0/woldlabwww.db' # Or path to database file if using sqlite3. DATABASE_USER = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.  Update installed apps: INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'woldcms.page' )

Time to create the Models  Django uses a custimized sqlalchemy for DB layer.  On to the models…(After documentation detour)

Add the models  Page MenuSet ○ Horizontal Menu (ref to “Menu”) ○ Vertical Menu (ref to “Menu”)  Menu Menu Item (Many-to-many) ○ Menu Sub Item (Many-to-many)

Page Model from django.db import models class MenuSubItem(models.Model): class Admin: pass # Internal name (i.e. mussa_download) id_name = models.CharField(maxlength=100) # Name to display on page display_name = models.CharField(maxlength=100) # Priority priority = models.PositiveSmallIntegerField(default=50) # Internal internal = models.BooleanField(default=False) # Link to internal page page_name = models.SlugField(maxlength=50, blank=True) # Link to url url = models.URLField(blank=True) def __str__(self): return '(%s) %s' % (self.id_name, self.display_name)

Menu Model class Menu(models.Model): class Admin: pass name = models.CharField(maxlength=100) menu_items = models.ManyToManyField(MenuItem) def __str__(self): return self.name

Menu Item Model class MenuItem(models.Model): class Admin: pass # Internal name (i.e. mussa_download) id_name = models.CharField(maxlength=100) # Name to display on page display_name = models.CharField(maxlength=100) # Priority priority = models.PositiveSmallIntegerField(default=50) # Internal internal = models.BooleanField(default=False) # Link to internal page page_name = models.SlugField(maxlength=50, blank=True) # Link to url url = models.URLField(blank=True) # Any sub-menu items (optional) sub_menu_items = models.ManyToManyField(MenuSubItem, blank=True) def __str__(self): return '(%s) %s' % (self.id_name, self.display_name)

Model Field Types  AutoField AutoField  BooleanField BooleanField  CharField CharField  CommaSeparatedIntegerField CommaSeparatedIntegerField  DateField DateField  DateTimeField DateTimeField  DecimalField DecimalField  Field Field  FileField FileField  FilePathField FilePathField  FloatField FloatField  ImageField ImageField  IntegerField IntegerField  IPAddressField IPAddressField  NullBooleanField NullBooleanField  PhoneNumberField PhoneNumberField  PositiveIntegerField PositiveIntegerField  PositiveSmallIntegerField PositiveSmallIntegerField  SlugField SlugField  SmallIntegerField SmallIntegerField  TextField TextField  TimeField TimeField  URLField URLField  USStateField USStateField  XMLField XMLField

Model Field Options  null null  blank blank  choices choices  core core  db_column db_column  db_index db_index  default default  editable editable  help_text help_text  primary_key primary_key  radio_admin radio_admin  unique unique  unique_for_date unique_for_date  unique_for_month unique_for_month  unique_for_year unique_for_year  validator_list validator_list

Create db, tables, and syncdb  In woldcms/ python manage.py sqlall pages #creates new db (if d.n.e.), tables, indexes, etc. python manage.py syncdb #Sets up authentication, admin, etc.

Fireup some Django goodness  cd woldcms/ python manage.py runserver #now on localhost:8000  now at:

Mmm… data… Got Views?  We can now input the data we need through the admin interface.

A simple view from django.template import Context, loader from django.http import HttpResponse, HttpResponseRedirect def index(request): return HttpResponse(“ Look a non- wiki! ”) def punish_user(request): return HttpRequestRedirect(‘

The ONLY down side to Django…  Now to hook up the view to a url. {% cue documentation %}

 woldcms/urls.py: from django.conf.urls.defaults import * from woldcms import settings urlpatterns = patterns('', # Uncomment this for admin: (r'^admin/', include('django.contrib.admin.urls')), (r'^html/', include('woldcms.page.urls')), #(r'^accounts/login/', 'django.contrib.auth.views.login'), (r'^login/', 'woldcms.page.views.login'), (r'^logout/', 'woldcms.page.views.logout'), (r'^img/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), )  woldcms/pages/urls.py: from django.conf.urls.defaults import * urlpatterns = patterns('', (r'(?P [a-zA-Z0-9_]+)/edit/$', 'woldcms.page.views.edit'), (r'(?P [a-zA-Z0-9_]+)/log/$', 'woldcms.page.views.revision_log'), (r'(?P [a-zA-Z0-9_]+)/(?P \d+)/$', 'woldcms.page.views.display'), (r'(?P [a-zA-Z0-9_]+)/$', 'woldcms.page.views.display'), (r'', 'woldcms.page.views.index'), )

def display(request, page_name, revision=None): """ Display a particular page or offer a chance to create a new page. ""“ try: p = Page.objects.get(page_name=page_name) except: msg = """ Click here to create the %s page """ % (page_name, page_name) return HttpResponse("Sorry, %s does not exist. %s" % (page_name,msg)) if p.internal and not request.user.is_authenticated(): return HttpResponseRedirect('/login/?next=%s' % (request.path)) v_menu_item_iter = p.menu_set.menu_vertical.menu_items.iterator() h_menu_item_iter = p.menu_set.menu_horizonal.menu_items.iterator() content = wiki_file.loadPage(p.page_name, revision) if request.user.is_authenticated(): content += """ Edit | Log | Page Settings """ % (p.page_name, p.page_name, p.id) t = loader.get_template('woldlab.html') c = Context({ 'page': p, 'v_menu_item_iter': v_menu_item_iter, 'h_menu_item_iter': h_menu_item_iter, 'user': request.user, 'content': content, 'request': request, 'settings': settings }) return HttpResponse(t.render(c))

Have view… now for some web 2.0, err, web 2.0esk looking pages.  Enter “Django Templates” {% cue template %}

Warning: Ugly code ahead

{% block v_menu %} Menu {% if v_menu_item_iter %} {% for menu_item in v_menu_item_iter %} {% if menu_item.internal and not request.user.is_authenticated %} {% else %} <a class="nav {% if menu_item.page_name %} {% ifequal page.page_name menu_item.page_name %} active {% endifequal %} " href="/html/{{ menu_item.page_name }}" {% else %} " href="{{ menu_item.url }}" {% endif %} >{{ menu_item.display_name }} | {% endif %} {% if menu_item.sub_menu_items.iterator %} {% for sub_item in menu_item.sub_menu_items.iterator %} {% if sub_item.internal and not request.user.is_authenticated %} {% else %} {% if sub_item.page_name %} {{ sub_item.display_name }} | {% else %} {{ sub_item.display_name }} | {% endif %} {% endfor %} {% endif %} {% endfor %} {% endif %} {% endblock %}

{% extends "woldlab.html" %} {% load i18n %} {% block title %} {% trans 'Page not found' %} {% endblock %} {% block h_menu %} Home {% endblock %} {% block v_menu %} Menu Home | {% endblock %} {% block content %} {% trans 'Page not found' %} {% trans "We're sorry, but the requested page could not be found." %} {% endblock %}

Feature Request!  Diane’s attempt to slow me down so she could learn Zope before I wrote my non- wiki wiki.  Diane now mysteriously volunteers to talk about Zope 3. =o)  Brandon quickly runs out of the room.

PySVN  Diane requested for a way to edit non- wiki wiki pages from the file system and allow for editing from the browser.  Enter PySVN.

woldcms.pages.wiki_file def savePage(page_name, content, user="Unknown"): """ saves content to page_name """ _validate(page_name) file_path = os.path.join(settings.WCMS_PAGES_DIR, page_name) if os.path.exists(file_path): _updateFile(page_name, content, file_path, user) else: _newFile(page_name, content, file_path)

woldcms.pages.wiki_file import pysvn from pysvn import wc_status_kind as wc_status def _newFile(page_name, content, file_path): f = open(file_path, 'w') f.write(content) f.close() client = pysvn.Client() client.add(file_path) client.checkin([file_path], "Inital version of page: %s" % (page_name))

woldcms.pages.wiki_file def _updateFile(page_name, content, file_path, user="Unknown"): client = pysvn.Client() status = client.status(file_path) assert len(status) == 1 status = status.pop() if status['text_status'] == wc_status.unversioned: client.add(file_path) client.checkin(file_path, "Found unversioned page: %s" % (page_name)) elif status['text_status'] == wc_status.normal: pass else: msg = "Don't know how to handle status: %s" % (status['text_status']) raise pysvn.ClientError(msg) f = open(file_path, 'w') f.write(content) f.close()

def _updateFile() continued status = client.status(file_path) assert len(status) == 1 status = status.pop() if status['text_status'] == wc_status.modified: client.checkin([file_path], "Updating %s page from wiki. User: %s" % (page_name, user)) elif status['text_status'] == wc_status.normal: pass else: msg = "Don't know how to handle status: %s" % (status['text_status']) raise pysvn.ClientError(msg)

FCKEditor   Live demo in lab… everyone has a Mac but me… Why does it have to break in Safari? Safari Compatibility Effort  GPL, LGPL and MPL licenses GPLLGPLMPL

Thickbox 2; I mean 3.  Was meant as a demo of jquery Javascript library. MIT License

Oops  Svn update on every view; ok for one user; bad for live demo with 10+ users.  Safari FCKEditor blunder. (I need a Mac.)

Useful Django def edit(request, page_name): """ Request to edit a page """

Django new style forms from django import newforms as forms class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms. Field() cc_myself = forms.BooleanField() >>> data = {'subject': 'hello',... 'message': 'Hi there',... 'sender': 'cc_myself': True} >>> f = ContactForm(data) >>> f.is_valid() True

Sort menus… easy.  Added priority field (integer; default 50)  Added a meta class; I mean class named meta. Is this class a meta class? To be answered next SoCal Piggies meeting.

Menu Item Model class MenuItem(models.Model): class Admin: pass class Meta: ordering = ['priority', 'display_name'] # Internal name (i.e. mussa_download) id_name = models.CharField(maxlength=100) # Name to display on page display_name = models.CharField(maxlength=100) # Priority priority = models.PositiveSmallIntegerField(default=50)

Advice: skim ALL the documentation  Django has a LOT of useful features  Many are easy to use.  If you skim ALL the docs after the basic tutorial, you will have an idea of where to look when you need an additional feature.