Пример #1
0
 def post(self, registry_id):
     # Validar acesso
     if eh_acesso_invalido(self, registry_id): return
     
     user = self.get_current_user()
             
     id = int( self.get_argument("id","") )
     
     noticias = Noticias(registry_id)
     noticia  = Noticia(registry_id, id)
     
     noticia.id            = id
     noticia.titulo        = self.get_argument("titulo","Sem titulo")
     noticia.resumo        = self.get_argument("resumo", "")
     noticia.texto         = self.get_argument("texto","")
     noticia.dt_publicacao = str(datetime.now())
     noticia.url           = self.get_argument("url", "")
     noticia.dt_validade   = self.get_argument("dt_validade", "")
     noticia.fonte         = self.get_argument("fonte", "")
     noticia.popup         = self.get_argument("popup", "")
     
     if noticia.dt_validade != "":
         try:
             f = lambda n: ("00"+n)[-2:]
             x = noticia.dt_validade.split("/")
             x.reverse()
             x[1] = f(x[1])
             x[2] = f(x[2])
             x = "-".join(x)
             d = time.strptime(x, "%Y-%m-%d")
             noticia.dt_validade   = x
         except:
             self.render("modules/noticia/noticia-new.html", NOMEPAG=u'Notícias', \
                         REGISTRY_ID=registry_id, MSG="Data inválida", \
                         NOTICIA=noticia)
             return
     
     noticias.insert_noticia(noticia)
     
     log.model.log(user, u'criou ou alterou uma notícia em', objeto=registry_id, tipo="noticia")
     
     self.redirect("/noticia/"+registry_id)
     return