def register(self): with db.auto_commit(): user = User(name=self.name.data, password=self.password.data, class_name=self.class_name.data, email=self.email.data) db.session.add(user)
def save_or_cancel(self): with db.auto_commit(): if self.type.data == 1: info = Subscribe(owner_id=g.user.id, book_id=self.bid.data) db.session.add(info) else: sub = Subscribe.query.filter_by( owner_id=g.user.id, book_id=self.bid.data).first_or_404() db.session.delete(sub)
def validate_old_password(self, value): user = User.query.filter_by(id=g.user.id).first_or_404() if user.check_pwd(value.data): with db.auto_commit(): user.password = self.new_password.data else: if 'new_password' not in self.errors.keys( ) and 're_password' not in self.errors.keys(): raise ValidationError(message='原密码错误')
def _save_image(user, filename, file, public, replace=True): url = get_file_url('HEAD_IMAGE_URL') makedir(url) title, tail = spilt_point(filename) if user.photo_url != current_app.config['DEFAULT_IMAGE'] and replace: os.remove(url + user.photo_url) new_url = uuid.uuid1().hex + '.' + tail file_url = url + new_url file.save(file_url) with db.auto_commit(): user.photo_url = new_url
def _save_file(user, filename, file, public): title, tail = spilt_point(filename) url = get_file_url('USER_FILE_URL') + str(user.id) + '/' + tail + '/' makedir(url) url = url + uuid.uuid1().hex + '.' + tail file.save(url) with db.auto_commit(): new_file = File(title=title, format=tail, owner_id=user.id, all_could=public, url=url.replace(get_file_url('USER_FILE_URL'), '')) db.session.add(new_file)
def recover_file(self): file = File.query.filter_by( id=self.file_id.data, status=StatusEnum.DELETE.value).first_or_404() with db.auto_commit(): file.status = StatusEnum.NORMAL.value
def delete_file(self): file = File.query.filter_by(id=self.file_id.data).first_or_404() with db.auto_commit(): file.del_time = datetime.now() file.status = StatusEnum.DELETE.value
def update_title(self): file = File.query.filter_by(id=self.file_id.data).first_or_404() with db.auto_commit(): file.title = self.title.data
def add_md(self): path = save_md(self.md.data) with db.auto_commit(): blog = Blog(title=self.title.data, watched=0, md_path=path) db.session.add(blog)
def update_email(self): with db.auto_commit(): user = User.query.filter_by(id=g.user.id).first_or_404() user.email = self.email.data
def update_auth(self): with db.auto_commit(): self.user.auth = self.type.data return True if self.type.data == 1 else False
def update_password(self): user = User.query.get(g.user.id) with db.auto_commit(): user.password = self.new_password.data