def post(self, siteid): item = self.get_modal_obj().query.filter_by(siteid=siteid).first() if not item: item = self.get_modal_obj() item.siteid = siteid itemform = self.get_form_obj() itemform.populate() if itemform.validate_on_submit(): try: item.populate_from_form(itemform) item.save() item.populate_from_dict(self.get_extrafields_modal()) except SQLAlchemyError as exception: db.session.rollback() logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while updating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully updated %(name)s'\ ,name=self.get_name())}) else: logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({ 'status': 0, 'data': {}, 'msg': get_form_errors(itemform) })
def post(self): itemform = self.get_form_obj() itemform.populate() if itemform.validate_on_submit(): try: item = self.get_modal_obj() item.populate_from_form(itemform) item.save() item.populate_from_dict(self.get_extrafields_modal()) except IntegrityError as exception: logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Duplicate exists for the given values of %(name)s'\ ,name=self.get_name())}) except SQLAlchemyError as exception: logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while creating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully added %(name)s'\ ,name=self.get_name())}) else: logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({ 'status': 0, 'data': {}, 'msg': get_form_errors(itemform) })
def post(self): ''' Need custom post here to handle wifisite creation with limited parameters ''' itemform = get_wifisite_form(baseform=True) itemform.populate() if itemform.validate_on_submit(): try: item = self.get_modal_obj()() item.site_from_baseform(itemform) item.populate_from_dict(self.get_extrafields_modal()) item.save() #create a landing page along with site landingpage = Landingpage() landingpage.siteid = item.id landingpage.save() except SQLAlchemyError as exception: db.session.rollback() logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while creating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully added %(name)s'\ ,name=self.get_name())}) else: logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({ 'status': 0, 'data': {}, 'msg': get_form_errors(itemform) })
def put(self,id): ''' Need custom post here to handle to configure sitekey etc ''' item = self.get_modal_obj().query.get(id) if item: itemform = self.get_form_obj() itemform.populate(item) if itemform.validate_on_submit(): try: item.populate_from_form(itemform) item.save() item.populate_from_dict(self.get_extrafields_modal()) except SQLAlchemyError as exception: current_app.logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while updating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully updated %(name)s'\ ,name=self.get_name())}) else: current_app.logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({'status':0,'data':{}, 'msg':get_form_errors(itemform)}) else: current_app.logger.debug('UserID:%s trying to update unknown ID:%s of :%s'\ %(current_user.id,id,self.get_name())) return jsonify({'status':0,'data':{}, 'msg':_('Unknown :%(name)s ID \ specified',name=self.get_name())})
def post(self,siteid): itemform = self.get_form_obj() itemform.populate() if itemform.validate_on_submit(): try: cnt = 0 while cnt < int(itemform.number.data): try: item = self.get_modal_obj()() item.populate_from_form(itemform) #create voucher item.voucher = '%s%s'%(itemform.batchid.data, self.create_voucher()) #always assign siteid while creation item.siteid = siteid item.populate_from_dict(self.get_extrafields_modal()) db.session.add(item) db.session.commit() except IntegrityError: #check for unique voucherID db.session.rollback() else: cnt = cnt + 1 except SQLAlchemyError as exception: current_app.logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while creating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully added %(name)s'\ ,name=self.get_name())}) else: current_app.logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({'status':0,'data':{}, 'msg':get_form_errors(itemform)})
def put(self, siteid, id): item = self.get_modal_obj()().query.get(id) if item: itemform = self.get_form_obj() itemform.populate() if itemform.validate_on_submit(): try: item.populate_from_form(itemform) item.save() item.populate_from_dict(self.get_extrafields_modal()) except IntegrityError as exception: logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Duplicate exists for the given values of %(name)s'\ ,name=self.get_name())}) except SQLAlchemyError as exception: logger.exception('UserID:%s submited form caused exception'\ %(current_user.id)) return jsonify({'status':0,'data':{}, 'msg':_('Error while updating %(name)s'\ ,name=self.get_name())}) return jsonify({'status':1,'data':{}, 'msg':_('Successfully updated %(name)s'\ ,name=self.get_name())}) else: logger.debug('UserID:%s submited form with errors:%s'\ %(current_user.id,get_form_errors(itemform))) return jsonify({ 'status': 0, 'data': {}, 'msg': get_form_errors(itemform) }) else: logger.debug('UserID:%s trying to update unknown ID:%s of :%s'\ %(current_user.id,id,self.get_name())) return jsonify({ 'status': 0, 'data': {}, 'msg': _l('Unknown :%(name)s ID \ specified', name=self.get_name()) })
def post(self): testemailform = TestEmailForm() if testemailform.validate_on_submit(): try: send_email("TEST EMAIL", body='Spotipo Test', html=None, recipients=[testemailform.sendto.data]) except: current_app.logger.exception("Exception while sending test email") return jsonify({'status':0,'data':{}, 'msg':_('Error while trying to send test email')}) else: return jsonify({'status':1,'data':{}, 'msg':_('Test mail send successfully')}) else: return jsonify({'status':0,'data':{}, 'msg':get_form_errors(testemailform)})