示例#1
0
	def create(self, **kwargs):
		section = kwargs['section']
		del kwargs['section']
		
		for item in (x for x
			in kwargs.keys()
				if x.startswith('is_')
					or x.startswith('has_')):
			kwargs[item] = True
		
		section_map = {
			'pages': StaticPageModel,
			'redirect': UrlMapping,
			'catalog_section': CatalogSectionModel,
			'catalog_element': CatalogItemModel,
			'data': NonRelationData
		}
		
		session = Session()
		
		page = section_map[section](**kwargs)
		
		try:
			session.add(page)
		except Exception as e:
			session.close()
			print('adm/AdminMainHandler.create(): '+\
				'cannot create page by "%s" section:\n' % str(section),\
				e, file=sys.stderr)
			raise e
		
		if section == 'redirect':
			permanent = (lambda: True if kwargs['status'] == '301' else False)()
			from app.app import application
			
			application.handlers[0][1][:0] = [
				URLSpec(
					kwargs['old_url'] + '$',
					RedirectHandler,
					kwargs={
						'url': kwargs['new_url'],
						'permanent': permanent
						},
					name=None)
			]
		
		try:
			session.commit()
		except Exception as e:
			session.close()
			print('adm/AdminMainHandler.create(): '+\
				'cannot commit create page by "%s" section:\n' % str(section),\
				e, file=sys.stderr)
			raise e
			
		session.close()
		
		return self.json_response({'status': 'success'})
示例#2
0
	def create(self, **kwargs):
		section = kwargs['section']
		del kwargs['section']

		for item in (x for x
			in kwargs.keys()
				if x.startswith('is_')
					or x.startswith('has_')):
			kwargs[item] = True

		section_map = {
			'pages': StaticPageModel,
			'redirect': UrlMapping,
			'catalog_section': CatalogSectionModel,
			'catalog_element': CatalogItemModel,
			'data': NonRelationData
		}

		session = Session()

		page = section_map[section](**kwargs)

		try:
			session.add(page)
		except Exception as e:
			session.close()
			print('adm/AdminMainHandler.create(): '+\
				'cannot create page by "%s" section:\n' % str(section),\
				e, file=sys.stderr)
			raise e

		if section == 'redirect':
			permanent = (lambda: True if kwargs['status'] == '301' else False)()
			from app.app import application

			application.handlers[0][1][:0] = [
				URLSpec(
					kwargs['old_url'] + '$',
					RedirectHandler,
					kwargs={
						'url': kwargs['new_url'],
						'permanent': permanent
						},
					name=None)
			]

		try:
			session.commit()
		except Exception as e:
			session.close()
			print('adm/AdminMainHandler.create(): '+\
				'cannot commit create page by "%s" section:\n' % str(section),\
				e, file=sys.stderr)
			raise e

		session.close()

		return self.json_response({'status': 'success'})
示例#3
0
	def post(self):
		session = Session()
		login = self.get_argument('login')
		passwd = self.get_argument('password')
		is_active = True

		try:
			olds = [x[0] for x in session.query(User.login).all()]
		except Exception as e:
			session.close()
			print('adm/CreateUser.post(): cannot get users logins:\n',\
				e, file=sys.stderr)
			raise e

		if login == '':
			return self.json_response({
				'status': 'error',
				'error_code': 'unique_key_exist'
			})
		elif login in olds:
			return self.json_response({
				'status': 'error',
				'error_code': 'incorrect_data'
			})
		try:
			self.get_argument('is_active')
		except:
			is_active = False

		usr = User(
			login=login,
			password=self.create_password(passwd),
			last_login=datetime.datetime.utcnow(),
			is_active=is_active
		)

		try:
			session.add(usr)
			session.commit()
		except Exception as e:
			session.close()
			print('adm/CreateUser.post(): cannot add user:\n',\
				e, file=sys.stderr)
			raise e

		session.close()
		return self.json_response({'status': 'success'})
示例#4
0
    def post(self):
        session = Session()
        login = self.get_argument('login')
        passwd = self.get_argument('password')
        is_active = True

        try:
            olds = [x[0] for x in session.query(User.login).all()]
        except Exception as e:
            session.close()
            print('adm/CreateUser.post(): cannot get users logins:\n',\
             e, file=sys.stderr)
            raise e

        if login == '':
            return self.json_response({
                'status': 'error',
                'error_code': 'unique_key_exist'
            })
        elif login in olds:
            return self.json_response({
                'status': 'error',
                'error_code': 'incorrect_data'
            })
        try:
            self.get_argument('is_active')
        except:
            is_active = False

        usr = User(login=login,
                   password=self.create_password(passwd),
                   last_login=datetime.datetime.utcnow(),
                   is_active=is_active)

        try:
            session.add(usr)
            session.commit()
        except Exception as e:
            session.close()
            print('adm/CreateUser.post(): cannot add user:\n',\
             e, file=sys.stderr)
            raise e

        session.close()
        return self.json_response({'status': 'success'})
示例#5
0
	def save_order(self, d):
		dt = d['date'].split('.')
		session = Session()
		try:
			item = session.query(CatalogItemModel).filter_by(id=d['id']).one()
		except Exception as e:
			session.close()
			print('FormsHandler.save_order(): cannot get catalog item by id\n',\
				e, file=sys.stderr)
			raise e
		session.close()
		full_date = datetime.combine(
				date(int(dt[2]), int(dt[1]), int(dt[0])),
				time(int(d['hours']), int(d['minutes']))),
		order = OrderModel(
			name=d['name'],
			callback=d['callback'],
			date=full_date,
			item_id=item.id
		)
		
		session = Session()
		try:
			session.add(order)
			session.commit()
		except Exception as e:
			session.close()
			print('FormsHandler.save_order(): cannot save order to DB\n',\
				e, file=sys.stderr)
			raise e
		session.close()
		send_mail(
			msg='<h1>Заказ "%s"</h1>' % item.title +
				'<dl><dt>Имя:</dt><dd>%s</dd>' % d['name'] +
				'<dt>Контакты:</dt><dd>%s</dd>' % d['callback'] +
				'<dt>Дата заказа:</dt><dd>%s</dd></dl>' % (
					full_date[0].strftime('%d.%m.%Y %H:%M')),
			theme='АвтоЛюкс: заказ "%s"' % item.title
		)
示例#6
0
	def save_order(self, d):
		dt = d['date'].split('.')
		session = Session()
		try:
			item = session.query(CatalogItemModel).filter_by(id=d['id']).one()
		except Exception as e:
			session.close()
			print('FormsHandler.save_order(): cannot get catalog item by id\n',\
				e, file=sys.stderr)
			raise e
		session.close()
		full_date = datetime.combine(
				date(int(dt[2]), int(dt[1]), int(dt[0])),
				time(int(d['hours']), int(d['minutes']))),
		order = OrderModel(
			name=d['name'],
			callback=d['callback'],
			date=full_date,
			item_id=item.id
		)

		session = Session()
		try:
			session.add(order)
			session.commit()
		except Exception as e:
			session.close()
			print('FormsHandler.save_order(): cannot save order to DB\n',\
				e, file=sys.stderr)
			raise e
		session.close()
		send_mail(
			msg='<h1>Заказ "%s"</h1>' % item.title +
				'<dl><dt>Имя:</dt><dd>%s</dd>' % d['name'] +
				'<dt>Контакты:</dt><dd>%s</dd>' % d['callback'] +
				'<dt>Дата заказа:</dt><dd>%s</dd></dl>' % (
					full_date[0].strftime('%d.%m.%Y %H:%M')),
			theme='АвтоЛюкс: заказ "%s"' % item.title
		)
示例#7
0
	def save_call(self, d):
		call = CallModel(
			name = d['name'],
			phone = d['phone'],
			date = datetime.utcnow()
		)
		session = Session()
		try:
			session.add(call)
			session.commit()
		except Exception as e:
			session.close()
			print('FormsHandler.save_call(): cannot save call to DB\n',\
				e, file=sys.stderr)
			raise e
		session.close()
		
		send_mail(
			msg='<h1>Заказ звонка</h1>' +
				'<dl><dt>Имя:</dt><dd>%s</dd>' % d['name'] +
				'<dt>Телефон:</dt><dd>%s</dd></dl>' % d['phone'],
			theme='АвтоЛюкс: заказ звонка'
		)
示例#8
0
	def save_call(self, d):
		call = CallModel(
			name = d['name'],
			phone = d['phone'],
			date = datetime.utcnow()
		)
		session = Session()
		try:
			session.add(call)
			session.commit()
		except Exception as e:
			session.close()
			print('FormsHandler.save_call(): cannot save call to DB\n',\
				e, file=sys.stderr)
			raise e
		session.close()

		send_mail(
			msg='<h1>Заказ звонка</h1>' +
				'<dl><dt>Имя:</dt><dd>%s</dd>' % d['name'] +
				'<dt>Телефон:</dt><dd>%s</dd></dl>' % d['phone'],
			theme='АвтоЛюкс: заказ звонка'
		)