def index(request,template_name='index.html'): if request.method == 'POST': #handle the poste form = CardModelForm(request.POST) if form.is_valid(): #handle the form, insert stuff new_object = form.save() if new_object.to_name != "": new_object.get_tracks() new_object.get_track_urls() return HttpResponseRedirect('/choose/%s/'%new_object.id) else: form = CardModelForm() context = {'form':form} return render_to_response(template_name, context,context_instance=RequestContext(request))
class CardHandler(BaseHandler): allowed_methods = ('POST', 'GET', 'DELETE',) # def create(self, request): # import pdb; pdb.set_trace() # f = CardModelForm(request.POST) # if f.is_valid(): # new_object = f.save() # return new_object # else: # import pdb; pdb.set_trace() # return rc.BAD_REQUEST def create(self, request): if request.content_type: data = request.data em = self.model(from_name=data['from_name'], to_name=data['to_name'], interests=data['interests']) em.save() # for comment in data['comments']: # Comment(parent=em, content=comment['content']).save() return rc.CREATED else: print "Problem creating record." # else: # super(ExpressiveTestModel, self).create(request) f = CardModelForm(request.POST) if f.is_valid(): new_object = f.save() if new_object.to_name != "": new_object.get_tracks() new_object.get_track_urls() return new_object return rc.BAD_REQUEST
def create(self, request): f = CardModelForm(request.POST) if f.is_valid(): new_object = f.save() return new_object return rc.BAD_REQUEST