def post(self): id = int(self.request.get('_id')) item = db.get(db.Key.from_path('Picture', id)) parameters = formutils.getBasicParameters(self) if not parameters["admin"]: self.error(403) return form = tourismforms.PictureForm(data=self.request.POST, instance=item) if form.is_valid(): entity = form.save(commit=False) try: image = self.request.get("pictureImage") entity.image = db.Blob(image) except: entity.image = item.image entity.put() url = r'/' SessionHandler.setSessionAttribute('addmsg', 'Imagem alterada com sucesso!') if SessionHandler.getSessionAttribute('new_home'): url = SessionHandler.removeSessionAttribute('new_home') self.redirect(url) else: parameters["content"] = formutils.getFormContentForUpdate(form, id, 'frmRegistration', r'/updatePicture') path = os.path.join(os.getcwd(), 'templates/index.html') self.response.out.write(template.render(path, parameters))
def getBasicParameters(request): links = entities.MenuLink.all() links.order('position') parameters = { "loggedin": SessionHandler.isUserLoggedIn(), "loginmsg": SessionHandler.removeSessionAttribute('loginmsg'), "addmsg": SessionHandler.removeSessionAttribute('addmsg'), "admin": SessionHandler.isAdmin(), "links": links } return parameters
def get(self): query = db.GqlQuery("SELECT * FROM MenuLink ORDER BY position") s = u"<a href='/addMenuLink'>Registrar novo link no menu...</a><br><br>Menus já cadastrados:<br>" for item in query: s = s + "<a href='/updateMenuLink?key=" + str(item.key()) + "'>" + item.title + "</a><br>" SessionHandler.setSessionAttribute('new_home', '/menuLink') parameters = formutils.getBasicParameters(self) parameters["content"] = s path = os.path.join(os.getcwd(), 'templates/index.html') self.response.out.write(template.render(path, parameters))
def get(self): query = db.GqlQuery("SELECT * FROM StaticContent ORDER BY shortname") s = u"<a href='/addStaticContent'>Registrar novo conteudo estático...</a><br><br>Conteudos estaticos existentes:<br>" for item in query: s = s + "<a href='/updateStaticContent?key=" + str(item.key()) + "'>" + item.shortname + "</a><br>" SessionHandler.setSessionAttribute('new_home', '/staticContent') parameters = formutils.getBasicParameters(self) parameters["content"] = s path = os.path.join(os.getcwd(), 'templates/index.html') self.response.out.write(template.render(path, parameters))
def get(self): query = db.GqlQuery("SELECT * FROM Picture ORDER BY name") s = u"<a href='/addPicture'>Registrar nova Imagem...</a><br><br>Imagens já cadastradas:<br>" for item in query: s = s + "<a href='/updatePicture?key=" + str(item.key()) + "'>" + item.name + "</a><br>" SessionHandler.setSessionAttribute('new_home', '/picture') parameters = formutils.getBasicParameters(self) parameters["content"] = s path = os.path.join(os.getcwd(), 'templates/index.html') self.response.out.write(template.render(path, parameters))
def doBasicPostFormProcessingAndReturn(req=None, form=None, frmId=None, frmAction=None, verifyAdmin=False, messageType=None, message=None): parameters = getBasicParameters(req) if verifyAdmin and not parameters["admin"]: req.error(403) return parameters["content"] = getFormContent(form, frmId, frmAction) if form.is_valid(): entity = form.save(commit=False) entity.put() url = r'/' if messageType: SessionHandler.setSessionAttribute(messageType, message) return entity else: parameters["content"] = getFormContent(form, frmId, frmAction) path = os.path.join(os.getcwd(), 'templates/index.html') req.response.out.write(template.render(path, parameters))
def get(self): id = None if (self.request.get('_id')): id = int(self.request.get('_id')) else: sessionUser = SessionHandler.getCurrentUser() id = sessionUser.key().id() item = entities.User.get(db.Key.from_path('User', id)) formutils.doUpdateGetByForm(self, item.key().id(), UpdateUserForm(instance=item), 'frmRegistration', r'/profile', False)
def doBasicPostFormProcessingForUpdate(req, form, itemId, frmId, frmAction, verifyAdmin=False, messageType=None, message=None): parameters = getBasicParameters(req) if verifyAdmin and not parameters["admin"]: req.error(403) return if form.is_valid(): entity = form.save(commit=False) entity.put() url = r'/' if messageType: SessionHandler.setSessionAttribute(messageType, message) if SessionHandler.getSessionAttribute('new_home'): url = SessionHandler.removeSessionAttribute('new_home') req.redirect(url) else: parameters["content"] = getFormContentForUpdate(form, itemId, frmId, frmAction) path = os.path.join(os.getcwd(), 'templates/index.html') req.response.out.write(template.render(path, parameters))
def post(self): sender_address = "*****@*****.**" name = self.request.get('name') email = self.request.get('email') if name == "" or self.request.get('body') == "" or email == "": SessionHandler.setSessionAttribute('addmsg', u'Você necessita informar seu nome, email e comentários!') self.redirect("/?content=contato") return subject = u"[Handyama] Nova mensagem enviada!" body = 'Mensagem de: ' + name body = body + 'Email: <a href="mailto:' + email body = self.request.get('body') mail.send_mail(sender_address, sender_address, subject.encode('utf-8'), body.encode('utf-8')) SessionHandler.setSessionAttribute('addmsg', 'Mensagem enviada com sucesso!') url = "/" self.redirect(url)
def post(self): from google.appengine.api import mail newuser = formutils.doBasicPostFormProcessingAndReturn(self, InsertUserForm(data=self.request.POST), 'frmRegistration', '/register', False, 'addmsg', 'Seu cadastro foi efetuado, porém você necessita\\naguardar que um de nossos agentes finalize seu cadastro.\\nVocê receberá um email com esta informação.\\nCaso não receba nenhum email, entre em contato!') if not newuser: return user_address = newuser.email sender_address = "*****@*****.**" subject = u"[Handyama] Novo usuario registrado" body = u"Foi registrado um novo usuario no site: " + newuser.name mail.send_mail(sender_address, sender_address, subject, body) subject = u"[Handyama] Registro no sistema aguardando aprovação" body = u"Olá " + newuser.name + u", \nVocê foi registrado em nosso sistema, contudo seu cadastro aguarda aprovação de nossos agentes.\nCaso você não receba nenhum email nosso em 72 horas, favor entrar em contato!" mail.send_mail(sender_address, newuser.email, subject.encode('utf-8'), body.encode('utf-8')) url = "/" if SessionHandler.getSessionAttribute('new_home'): url = SessionHandler.removeSessionAttribute('new_home') self.redirect(url)