Django 整合DWZJs富客户端框架 一

 项目目录结构:

Django 整合DWZJs富客户端框架 一_第1张图片

cms APP urls.py:

#!/usr/bin/env python
# encoding=utf-8 
from django.conf.urls.defaults import patterns, include, url
from django.conf import settings

urlpatterns = patterns('',
    url(r'^$', 'cms.views.index',name="index"),
    url(r'^list/$', 'cms.views.list', name="list"),
    url(r'^index/$', 'cms.views.index', name="index"),
    url(r'^add/$', 'cms.views.add', name="add"),
    url(r'^edit/(?P<id>\d+)/$', 'cms.views.edit', name="edit"),
    url(r'^search/$', 'cms.views.search', name="search"),
    url(r'^show_meta/$', 'cms.views.show_meta', name="show_meta"),
)

cms APP models.py:

 

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length = 60)
    
    def __unicode(self):
        return self.name

class Article(models.Model):
    title        = models.CharField(max_length = 120)
    keywords     = models.CharField(max_length = 100)
    description  = models.CharField(max_length = 300)
    content      = models.TextField()
    publish_date  = models.DateTimeField(auto_now=True)
    author       = models.ForeignKey(Author)
    
    def __unicode__(self):
        return self.title

 

cms APP views.py:

 

#!/usr/bin/env python
# encoding=utf-8 
from django.shortcuts import render_to_response,get_object_or_404
from django.http import HttpResponse
from django.utils import  simplejson 
from models import Author,Article
def index(request):
    return render_to_response('cms/index.html')
def list(request):
    articles = Article.objects.order_by('id')
    return render_to_response('cms/list.html',{'articles':articles})

def add(request):
    if request.POST:
        title = request.POST.get('title','')
        keywords = request.POST.get('keywords','')
        description = request.POST.get('description','')
        content = request.POST.get('content','')
        author = Author.objects.get(id=1)
        article = Article(title=title, keywords=keywords, description=description,content=content,author=author)
        article.save()
        return HttpResponse(simplejson.dumps({"status":1, "statusCode":1,"navTabId":request.POST.get('navTabId',None),"callbackType":request.POST.get('callbackType',None),"forwardUrl":request.POST.get('forwardUrl',None),"message":u'添加成功呢',"data":u'添加成功呢'}), mimetype="application/json") 
    else:
        return render_to_response('cms/add.html')

def edit(request,id):
    article = get_object_or_404(Article, pk=int(id))
    if request.POST:
        article.title = request.POST.get('title','')
        article.keywords = request.POST.get('keywords','')
        article.description = request.POST.get('description','')
        article.content = request.POST.get('content','')
        article.author = Author.objects.get(id=1)
        article.save()
        return HttpResponse(simplejson.dumps({"status":1, "statusCode":1,"navTabId":request.POST.get('navTabId',None),"callbackType":request.POST.get('callbackType',None),"forwardUrl":request.POST.get('forwardUrl',None),"message":u'编辑成功呢',"data":u'编辑成功呢'}), mimetype="application/json") 
    return render_to_response('cms/edit.html',{'article':article})

def delete(request, id):
    
    if id:
        article = get_object_or_404(Article, pk=int(id))
        article.delete()
    return HttpResponse(simplejson.dumps({"status":1, "statusCode":1,"navTabId":request.POST.get('navTabId',None),"callbackType":request.POST.get('callbackType',None),"forwardUrl":request.POST.get('forwardUrl',None),"message":u'删除成功呢',"data":u'删除成功呢'}), mimetype="application/json")
def search(request):
    if 'q' in request.GET and request.GET['q']:
        q = request.GET['q']
        articles = Article.objects.filter(title_icontains = q)
        return render_to_response('cms/search.html', {'articles': articles, 'query': q})
    else:
        return render_to_response('cms/search.html', {'error': True})

def show_meta(request):
    values = request.META.items()
    values.sort()
    return render_to_response('cms/show_meta.html',{'values':values})

剩下的就是模版文件啦!需要项目源码的留言。。。

Django 整合DWZJs富客户端框架 一_第2张图片

Django 整合DWZJs富客户端框架 一_第3张图片

Django 整合DWZJs富客户端框架 一_第4张图片

你可能感兴趣的:(Django 整合DWZJs富客户端框架 一)