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()
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')
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()
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()
def post(self): logger.info(attrs)