Beispiel #1
0
def newstory(request):
	if request.POST['title'] and request.POST['content']:
		p=Story(title=request.POST['title'], content=request.POST['content'])
		p.save()
		return HttpResponseRedirect(reverse('index'))
	else:
		return render(request,'storys/index.html',{
		'story_list': Story.objects.all(),
    	'error_message':"Please write somthing and try again.",})	
Beispiel #2
0
    def create(self, request):
        '''
        create a story
        Sample: POST /api/storys/
        {
            title: 'xxx',
            author: 'houks',
            text: 'aaaaaaaa',
            img_url: 'www.a.com/a.png', //optional
            img_horizontal: 'l',        //optional
            img_veritcal: 't'           //optional
            }
        }
        '''

        GET = self.flatten_dict(request.GET)
        POST = self.flatten_dict(request.POST)
        #pdb.set_trace();

        if ('title' not in POST) or \
                ('author' not in POST) or \
                ('text' not in POST):
            return rc.BAD_REQUEST

        title = POST['title']
        author = POST['author']
        text = POST['text']

        #print 'now time' + datetime.datetime.now()

        new_story = Story(title=title, author=author, text=text)

        if 'img_url' in POST:
            new_story.img_url = POST['img_url']
            if 'img_vertical' in POST:
                new_story.img_horizontal = POST['img_veritcal']
            if 'img_horizontal' in POST:
                new_story.img_horizontal = POST['img_horizontal']

        new_story.save()

        return [new_story]