def add_without_commit(model, obj_dict): try: instance = model() obj_dict["created_at"] = OHHODatetime.get_utc_now() obj_dict["changed_at"] = OHHODatetime.get_utc_now() if not obj_dict.get("timestamp", None): obj_dict["timestamp"] = OHHODatetime.get_current_timestamp() for key, value in obj_dict.items(): Operation.set_attribute(instance, key, value) session.add(instance) return instance except Exception as ex: OHHOLog.print_log(ex) return None
def post(self): instance = User() the_post = Post() country_code = the_post.get_cellphone_country_code(self) username = the_post.get_username(self) password = the_post.get_password(self) if not username or not password or not country_code: message = "username or password or country_code is empty" return self.redirect("/backstage/login/?data=%s" % message) else: success, the_username = instance.check_user4backstage( username, password, country_code) if success: OHHOLog.print_log("login success") user_instance = instance.get_by_username(the_username) if user_instance: instance.token.add(user_instance.id) update_success = instance.update_user( user_instance, {"last_login": OHHODatetime.get_utc_now()}) OHHOLog.print_log(update_success) else: OHHOLog.print_log("no such user") self.set_secure_cookie("username", the_username) return self.redirect("/backstage/home/") if the_username: message = "password is incorrect" else: message = "user does not exist" return self.redirect("/backstage/login/?data=%s" % message)
def get_applies_by_time_delta(self, time_delta=-24): now = OHHODatetime.get_utc_now() the_datetime = OHHODatetime.get_some_hour_after(now, time_delta) query = self.apply.get_query() return self.apply.get_great_than_equal_created_at(query, the_datetime)