コード例 #1
0
ファイル: main.py プロジェクト: dansamara/avto-lux161
	def get(self, *args):

		lang = config('LOCALIZATION')['LANG']
		localization = get_json_localization('ADMIN')[lang]
		kwrgs = {
			'page_title': localization['page_title'],
			'lang': lang,
			'local': localization,
			'is_auth': (
				lambda: 1 if self.get_current_user() else 0)(),
			'is_debug': (
				lambda: 1 \
					if self.application.settings.get('debug') \
					else 0)()
		}
		return self.render('admin/layout.jade', **kwrgs)
コード例 #2
0
ファイル: main.py プロジェクト: dansamara/avto-lux161
    def get(self, *args):

        lang = config('LOCALIZATION')['LANG']
        localization = get_json_localization('ADMIN')[lang]
        kwrgs = {
         'page_title': localization['page_title'],
         'lang': lang,
         'local': localization,
         'is_auth': (
          lambda: 1 if self.get_current_user() else 0)(),
         'is_debug': (
          lambda: 1 \
           if self.application.settings.get('debug') \
           else 0)()
        }
        return self.render('admin/layout.jade', **kwrgs)
コード例 #3
0
	def post(self):
		is_ajax = False
		lang = config('LOCALIZATION')['LANG']
		localization = get_json_localization('CLIENT')[lang]['forms']
		actions = {
			'call' : {
				'fn': self.save_call,
			},
			'order' : {
				'fn': self.save_order,
			}
		}
		
		try:
			is_ajax = self.get_argument('ajax')
		except MissingArgumentError:
			pass
		
		args = dict([ x.split('=') for x
			in str(self.request.body).split('&')
				if 'action' not in x ])
		for key in args:
			args[key] = self.get_argument(key)
		
		action = self.get_argument('action')
		
		if action not in actions.keys():
			if is_ajax:
				self.set_status(400)
				return self.json_response({'status': 'unknown_form'})
			return self.write("Lol, request isn't correct")
		
		p_title = localization['response_page'][action]
		fn = actions[action]['fn']
		
		errors = self.validate_fields(args)
		if len(errors) == 0:
			try:
				fn(args)
			except Exception as e:
				print('FormsHandler.post(): post form data error:\n',\
					e, file=sys.stderr)
				self.set_status(500)
				return self.json_response({'status': 'system_fail'})\
					if is_ajax\
					else self.write('Internal server Error')
			
			if is_ajax:
				return self.json_response({'status': 'success'})
			
			kwrgs = self.set_kwargs(
				success_msg_list=['success'], # TODO :: messages!
				title=p_title)
			return self.render('client/content-page.jade', **kwargs)
		
		else:
			if is_ajax:
				self.set_status(400)
				self.json_response({
					'status': 'error',
					'error_fields': { x: 'required' for x in errors }
				})
			else:
				err_list = [localization['err']['required_page'].format(localization['fields'][x]) \
					for x in errors ]
				kwrgs = self.set_kwargs(
					error_msg_list=err_list,
					title=p_title)
				self.render('client/content-page.jade', **kwrgs)
コード例 #4
0
ファイル: main.py プロジェクト: dansamara/avto-lux161
	def post(self):
		is_ajax = False
		lang = config('LOCALIZATION')['LANG']
		localization = get_json_localization('CLIENT')[lang]['forms']
		actions = {
			'call' : {
				'fn': self.save_call,
			},
			'order' : {
				'fn': self.save_order,
			}
		}

		try:
			is_ajax = self.get_argument('ajax')
		except MissingArgumentError:
			pass

		args = dict([ x.split('=') for x
			in str(self.request.body).split('&')
				if 'action' not in x ])
		for key in args:
			args[key] = self.get_argument(key)

		action = self.get_argument('action')

		if action not in actions.keys():
			if is_ajax:
				self.set_status(400)
				return self.json_response({'status': 'unknown_form'})
			return self.write("Lol, request isn't correct")

		p_title = localization['response_page'][action]
		fn = actions[action]['fn']

		errors = self.validate_fields(args)
		if len(errors) == 0:
			try:
				fn(args)
			except Exception as e:
				print('FormsHandler.post(): post form data error:\n',\
					e, file=sys.stderr)
				self.set_status(500)
				return self.json_response({'status': 'system_fail'})\
					if is_ajax\
					else self.write('Internal server Error')

			if is_ajax:
				return self.json_response({'status': 'success'})

			kwrgs = self.set_kwargs(
				success_msg_list=['success'], # TODO :: messages!
				title=p_title)
			return self.render('client/content-page.jade', **kwargs)

		else:
			if is_ajax:
				self.set_status(400)
				self.json_response({
					'status': 'error',
					'error_fields': { x: 'required' for x in errors }
				})
			else:
				err_list = [localization['err']['required_page'].format(localization['fields'][x]) \
					for x in errors ]
				kwrgs = self.set_kwargs(
					error_msg_list=err_list,
					title=p_title)
				self.render('client/content-page.jade', **kwrgs)