From 44d6c1a48e2c759ece5ca3b25afe9181754b5496 Mon Sep 17 00:00:00 2001 From: zhijiasun Date: Thu, 29 May 2014 21:37:38 +0800 Subject: [PATCH] add rest-framework app --- db.sqlite3 | Bin 40960 -> 103424 bytes epm/__init__.py | 0 epm/admin.py | 3 +++ epm/models.py | 42 ++++++++++++++++++++++++++++++++++++++ epm/tests.py | 3 +++ epm/views.py | 3 +++ polls/admin.py | 2 ++ post.py | 7 +++++++ rest/__init__.py | 0 rest/admin.py | 3 +++ rest/models.py | 3 +++ rest/serializers.py | 13 ++++++++++++ rest/tests.py | 3 +++ rest/urls.py | 7 +++++++ rest/views.py | 47 +++++++++++++++++++++++++++++++++++++++++++ tutorial/settings.py | 16 +++++++++++++++ tutorial/urls.py | 3 +++ 17 files changed, 155 insertions(+) create mode 100644 epm/__init__.py create mode 100644 epm/admin.py create mode 100644 epm/models.py create mode 100644 epm/tests.py create mode 100644 epm/views.py create mode 100644 post.py create mode 100644 rest/__init__.py create mode 100644 rest/admin.py create mode 100644 rest/models.py create mode 100644 rest/serializers.py create mode 100644 rest/tests.py create mode 100644 rest/urls.py create mode 100644 rest/views.py diff --git a/db.sqlite3 b/db.sqlite3 index 6cf6c8182cfda45af617b3c35f089340bb39e100..d7d32026c29584c80aff1f3792fff1042c943e2f 100644 GIT binary patch literal 103424 zcmeHQdvF{{d7qiy)oNu+vMtMNS(ZIoNw(Lrq@8_g<+FXVt@FvY9!XJkP&_M;q^P7WP{0*;Tpa-lLP7W=0g3{Wz~Q@t6puhENAajs z`Z+r@JG+u%pDoM1Ubkkx{<^=ffBl%=?r*+6d-`O$tjei;F&it(e!(V)qVS+B3xe<< z{IA0Q>~jcS*w_vHE9$Q6T|Oubz38#S*mm$4#FGHO2d{!(fuDg_z>DDDz<0sFf^UMa zfiHs>z_WyUY$J(gA)f~a3l%$z{>hi0dU{Mw7GtThbmVd@H=`!yQaM&EM+>v@Oga%Or}H^E zmP^WNE~%#t`$Q_j*=iEu8w&=9!y$jzZx(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v`pmy%+>7z+5J7cQ8DBAEsFl&{2zPqQWFWegFAT~=_y1A@!=BYugW;JY}DDLjJv za0_}-LZH9WJM;#frHrO&oF1ZkXfyTDGI$0L<}w#ys!V`dFh-*B=xDUJZy*`#i#k=T zZy=oL&tndg0F_`2Mx8go5NPA%&N!Nyq5<9%baj0qc#LmgY zL~M7XFYM`jIT?GctJ^<0IpJ^K8EW0pGZ+|ejGQ=mxO?z$XQ*p@Z*tr}(6Z}5YxlNB zpFdFV^Vc`}-F|<2lfOOC))4gh+FDu%!y`#{vsdywuhQ7u?h7>dT3Uj^Ho3h4pAdY) zJAMhB29%64EwPSoh@^|~-z*)Yvv@s|31#1Z@i^*s73-u|n%LblHsRt%T~$qs8g7>fkSq5?8%Fbggx{M+c8`%fAG ztpu&8o6G!7gMaaKR-SY}6+2EJ2@Q-ze7-~?J`nN6PPDb1IN2C(iN^-VkEeq1V-tZC zyV-fk-B|AntT}>!ug%w7fIsp2&J&!+c^>7*==ER+{GU0>1Mp-r?sIXSA$L3=OTZQ@5mfEONK~CCR8?6ZWoCcDtCkvZrO-({mU<`q57O1jbm2l*Q@=CHl?YpLQ#Zn}@|Lg12K=CT!eRY+e(<~nFI7PAmqCJQ4(S;xVSb-!hl+ zV2OwTMyIkml$C`SJF_5^Ed{{Is&YZ7(quh*F=t@Yxf)o{KFaL{566#Q3-CJW?h(9)3;Yy5Mc9@JIo#zK R0`&^}uMwjKSuj1re*je*QDFc8 diff --git a/epm/__init__.py b/epm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/epm/admin.py b/epm/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/epm/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/epm/models.py b/epm/models.py new file mode 100644 index 0000000..0595d79 --- /dev/null +++ b/epm/models.py @@ -0,0 +1,42 @@ +from django.db import models + +# Create your models here. + +class enterprise(models.Model): + + STATE_OWNED_ENTER = 1 + COOPERATIVE_ENTER = 2 + JOIN_VENTURE = 3 + NATURE_CHOICES = ( + (STATE_OWNED_ENTER,u'国有企业'), + (COOPERATIVE_ENTER,'合作企业'), + (JOIN_VENTURE,u'合资企业'), + ) + enter_id = models.AutoField(primary_key=True,auto_created=True) + enter_name = models.CharField(u'企业名称',max_length=50) + register_time = models.DateField(u'注册时间') + enter_address = models.CharField(u'注册地址',max_length=50) + enter_nature = models.IntegerField(u'企业性质',default=STATE_OWNED_ENTER,choices=NATURE_CHOICES) + + class Meta: + verbose_name = u'企业信息' + verbose_name_plural = u'企业信息' + + + def __unicode__(self): + return self.enter_name + + +class party(models.Model): + party_id = models.AutoField(primary_key=True,auto_created=True) + party_name = models.CharField(u'党支部名称',max_length=100) + member_number = models.IntegerField(u'党员人数') + contact_info = models.CharField(u'联系方式',max_length=300) + + class Meta: + verbose_name = u'党支部信息' + verbose_name_plural = u'党支部信息' + + + def __unicode__(self): + return self.party_name \ No newline at end of file diff --git a/epm/tests.py b/epm/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/epm/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/epm/views.py b/epm/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/epm/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/polls/admin.py b/polls/admin.py index ec50db8..400c000 100644 --- a/polls/admin.py +++ b/polls/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin +from models import * # Register your models here. +admin.site.register(Poll) diff --git a/post.py b/post.py new file mode 100644 index 0000000..29df7e2 --- /dev/null +++ b/post.py @@ -0,0 +1,7 @@ +import requests +import httplib +import json +data = {"username":"afadfa","password":"123456","email":"adfa2@cenling.com"} +headers = {"Content-Type":"application/json","Accept":"text/plain"} +conn = httplib.HTTPConnection('127.0.0.1:8000') +conn.request("POST","/rest/register/user/",json.dumps(data),headers) diff --git a/rest/__init__.py b/rest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rest/admin.py b/rest/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/rest/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/rest/models.py b/rest/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/rest/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/rest/serializers.py b/rest/serializers.py new file mode 100644 index 0000000..78e7208 --- /dev/null +++ b/rest/serializers.py @@ -0,0 +1,13 @@ +from rest_framework import serializers +from django.contrib.auth.models import User +from polls.models import Poll + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ('id','username','email') + + +class PollSerializer(serializers.ModelSerializer): + class Meta: + model = Poll diff --git a/rest/tests.py b/rest/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/rest/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/rest/urls.py b/rest/urls.py new file mode 100644 index 0000000..66d2ce8 --- /dev/null +++ b/rest/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls import url,patterns +from rest import views + +urlpatterns = patterns('', + url(r'^register/user/$',views.register_user), + url(r'^list/polls/$',views.operate_poll) +) diff --git a/rest/views.py b/rest/views.py new file mode 100644 index 0000000..f64b9fa --- /dev/null +++ b/rest/views.py @@ -0,0 +1,47 @@ +from django.shortcuts import render +from rest_framework.decorators import api_view +from rest_framework import status +from rest_framework.response import Response +from rest_framework.parsers import JSONParser +from serializers import * +from django.views.decorators.csrf import csrf_exempt +from polls.models import Poll +import pdb + +# Create your views here. + +@csrf_exempt +@api_view(['POST']) +def register_user(request): + print 'aaaa' + print request.method + print request.DATA + print 'ddd' + user = UserSerializer(data=request.DATA) + if user.is_valid(): + print 'valid' + pdb.set_trace() + u = User.objects.create_user(username=user.init_data['username'],email=user.init_data['email'],password=user.init_data['password']) + u.save() + return Response(user.data,status = status.HTTP_201_CREATED) + else: + pdb.set_trace() + return Response(uesr.errors,status = status.HTTP_400_BAD_REQUEST) + +@api_view(['GET','POST']) +def operate_poll(request): + print 'aaaabbb' + if request.method == 'GET': + polls = Poll.objects.all() + pserializered = PollSerializer(polls,many=True) + return Response(pserializered.data) + if request.method == 'POST': + print 'method is:%s'%request.method + print request.DATA + p = PollSerializer(data=request.DATA) + if p.is_valid(): + p.save() + return Response(p.data,status=status.HTTP_201_CREATED) + else: + return Response(p.errors,status = status.HTTP_400_BAD_REQUEST) + diff --git a/tutorial/settings.py b/tutorial/settings.py index f82817f..c92a73a 100644 --- a/tutorial/settings.py +++ b/tutorial/settings.py @@ -36,11 +36,17 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django.contrib.sites', + 'django.contrib.comments', 'rest_framework', 'snippets', 'testuser', 'formtest', 'polls', + 'tagging', + 'mptt', + 'zinnia', + 'rest', ) MIDDLEWARE_CLASSES = ( @@ -85,3 +91,13 @@ # https://docs.djangoproject.com/en/1.6/howto/static-files/ STATIC_URL = '/static/' + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.core.context_processors.i18n', + 'django.core.context_processors.request', + 'zinnia.context_processors.version', # Optional +) + + +SITE_ID=1 diff --git a/tutorial/urls.py b/tutorial/urls.py index 448d53c..65ea2a8 100644 --- a/tutorial/urls.py +++ b/tutorial/urls.py @@ -13,4 +13,7 @@ url(r'^',include('testuser.urls')), url(r'^',include('formtest.urls')), url(r'^polls/',include('polls.urls')), + url(r'^',include('rest.urls')), + url(r'^weblog/',include('zinnia.urls')), + url(r'^comments/',include('django.contrib.comments.urls')), )