示例#1
0
def create_dua(text, user_id, name=None, source=None, **kwargs):

	user = User.query.get(user_id)

	if not user:
		raise Exception('User not found')

	dua = Dua.query.filter(or_(Dua.name==name, Dua.text==text)).first()

	logger.info(dua)

	if dua:
		return dua

	dua = Dua(name=name, text=text, source=source, user_id=user.id)

	logger.info(dua)

	db.session.add(dua)

	try:
		db.session.commit()
		return dua
	except:
		db.session.rollback()
示例#2
0
文件: base.py 项目: stikks/moshalashi
	def save(self, attrs, files):

		hadith = mosque.create_hadith(**attrs)

		logger.info(hadith)

		if hadith:
			return hadith
		else:
			return abort(405, message='Hadith not created')
示例#3
0
def upload_countries():

	filepath = os.path.join(DEFAULT_DIR, 'countries.json')

	logger.info(filepath)

	_file = open(filepath)

	data = json.loads(_file.read().encode("UTF-8"))

	for item in data:

		country = Country(name=item.get('name'), code=item.get('code'))
		db.session.add(country)
		try:
			db.session.commit()
			logger.info(country)
		except:
			db.session.rollback()
示例#4
0
def upload_states(name):

	country = Country.query.filter(func.lower(Country.name)==name.lower()).first()

	filepath = os.path.join(DEFAULT_DIR, 'states/%s.json'%country.name.lower())

	logger.info(filepath)

	_file = open(filepath)

	data = json.loads(_file.read().encode("UTF-8"))

	for key, value in data.items():

		state = State(name=value, code=key, country_id=country.id)

		db.session.add(state)
		try:
			db.session.commit()
		except:
			db.session.rollback()
示例#5
0
文件: base.py 项目: stikks/moshalashi
	def post(self):
		logger.info(attrs)