コード例 #1
0
 def post(self, **kwargs):
     """To process a form, we validate it, authenticate the User 
     and pass the form instance to the template.
     """
     #http://flask.pocoo.org/snippets/60/     
            
     if self.request.form.has_key('registre') and\
        self.request.args.has_key('key'):
         
         key =  self.request.args.get('key')
         obj = SiteMonitor.getByID(key)
         
         # Validate the form.
         if self.form.validate():
         
             obj.name = self.form.name.data
             obj.link = self.form.link.data
             obj.textCheck = self.form.textCheck.data
             obj.date_creation = datetime.now()
             obj.flagAtivo = self.form.flagAtivo.data
           
             obj.put()
             return redirect('/sites') 
     
     if self.request.form.has_key('registre'):    
         self.context['form'] = self.form #SiteMonitorForm()
         self.context['errors_loginform_add'] = ''
         
         # Validate the form.
         if self.form.validate():
             # Form is valid. Use the form data and redirect the user to the
             # final destination.
             
             record = SiteMonitor(name = self.form.name.data,
                                  link = self.form.link.data,
                                  textCheck = self.form.textCheck.data,
                                  date_creation = datetime.now(),
                                  flagAtivo = self.form.flagAtivo.data)
         
             record.put()
             return redirect('/sites')
         
         # Since the form didn't validate, render it again using self.get().
         return self.render_response('views/manage_sites.html', **self.context)