def edit_profile(user_id): user = db_session.query(User).\ filter(User.id == user_id).first() if not user: abort(404) if current_user != user: abort(403) #form = EditProfileForm() #if form.validate_on_submit(): # pass #pass if request.method == 'GET': return render_template('user_edit_profile.html') user.profireader_name = request.form['name'] user.profireader_first_name = request.form['first_name'] user.profireader_last_name = request.form['last_name'] user.profireader_gender = request.form['gender'] user.profireader_link = request.form['link'] user.profireader_phone = request.form['phone'] user.location = request.form['location'] user.about_me = request.form['about_me'] db_session.add(user) db_session.commit() flash('You have successfully updated you profile.') return redirect(url_for('user.profile', user_id=user_id))
def subscribe_to_company(id): if not db(UserCompanyRole, user_id=g.user_dict["id"], company_id=id).first(): db_session.add(UserCompanyRole(user_id=g.user_dict["id"], company_id=id, status=statuses.NONACTIVE())) db_session.commit() else: raise StatusNonActivate
def create_company(self, data, file): comp_dict = {"author_user_id": g.user_dict["id"]} status = STATUS() for x, y in zip(data.keys(), data.values()): comp_dict[x] = y company = Company(**comp_dict) db_session.add(company) db_session.commit() user_rbac = UserCompany(user_id=company.author_user_id, company_id=company.id, status=status.ACTIVE()) db(Company, id=company.id).update( { "logo_file": File.upload( file=file, company_id=company.id, parent_id=company.corporate_folder_file_id, author=g.user_dict["name"], author_user_id=g.user_dict["id"], ) } ) db_session.add(user_rbac) db_session.commit() r = Right() r.add_rights(company.author_user_id, company.id, COMPANY_OWNER)
def upload(parent_id=None, file=None, company_id=None, author_user_id=None, copyright='', author=''): f = File(parent_id=parent_id, author_user_id=author_user_id, name=file.filename, size=0, company_id=company_id, copyright=copyright, author=author, mime=file.content_type) db_session.add(f) db_session.commit() FileContent(file_content=f, content=file.stream.read(-1)) db_session.commit() return f.id
def create_company_dir(company=None, name=None): f = File(parent_id=None, author_user_id=company.author_user_id, name=name, size=0, company_id=company.id, mime='directory') db_session.add(f) company.company_folder.append(f) db_session.commit() for x in company.company_folder: return x.id
def subscribe_to_company(company_id): status = STATUS() if not db(UserCompany, user_id=g.user_dict["id"], company_id=company_id).first(): user_rbac = UserCompany(user_id=g.user_dict["id"], company_id=company_id, status=status.NONACTIVE()) user_rbac.user = db(User, id=g.user_dict["id"]).one() db_session.add(user_rbac) db_session.commit() else: raise StatusNonActivate
def reset_password(self, token, new_password): s = Serializer(current_app.config["SECRET_KEY"]) try: data = s.loads(token) except: return False if data.get("reset") != self.id: return False self.password = new_password db_session.add(self) db_session.commit() return True
def confirm(self, token): s = Serializer(current_app.config["SECRET_KEY"]) try: data = s.loads(token) except: return False if data.get("confirm") != self.id: return False self.confirmed = True db_session.add(self) db_session.commit() return True
def add_rights(user_id, comp_id, right): user_right = UserCompanyRole( user_id=user_id, company_id=comp_id, status=statuses.ACTIVE(), right_id=right ).first() # right = Right # right.user_role.append(db(UserCompanyRole, user_id=user_id).first()) db_session.add(user_right) db_session.commit() user = User() user.user_rights.append(user_right) return user_right
def image_editor(img_id): ratio = Config.IMAGE_EDITOR_RATIO height = Config.HEIGHT_IMAGE thumbnail = File() thumbnail_content = FileContent() size = (int(ratio*height), height) image_id = img_id data = request.form if request.method != 'GET': image_query = file_query(image_id, File) image_content = file_query(image_id, FileContent) image = Image.open(BytesIO(image_content.content)) #area = [int(y) for x, y in sorted(zip(request.form.keys(), request.form.values())) # if int(y) in range(0, max(image.size)) and x != "5rotate" and x != "6name"] area = [int(a) for a in (data['1x'], data['2y'], data['3width'], data['4height']) if int(a) in range(0, max(image.size))] if not data['6name']: raise EmptyFieldName elif area: angle = int(data["5rotate"])*-1 area[2] = (area[0]+area[2]) area[3] = (area[1]+area[3]) rotated = image.rotate(angle) cropped = rotated.crop(area).resize(size) bytes_file = BytesIO() cropped.save(bytes_file, image_query.mime.split('/')[-1].upper()) thumbnail.md_tm = strftime("%Y-%m-%d %H:%M:%S", gmtime()) thumbnail.size = sys.getsizeof(bytes_file.getvalue()) thumbnail.name = data['6name']+'.'+image_query.name.split('.')[-1] thumbnail.mime = image_query.mime db_session.add(thumbnail) db_session.commit() thumbnail_content.content = bytes_file.getvalue() thumbnail_content.id = thumbnail.id db_session.add(thumbnail_content) db_session.commit() image_id = thumbnail.id return redirect(url_for('image_editor.cropped', id=image_id)) else: db_session.rollback() raise BadCoordinates return render_template('image_editor.html', ratio=ratio, img_id=img_id, image=url_for('filemanager.get', id=image_id) )
def createdir(parent_id=None, name=None, author_user_id=None, company_id=None, copyright='', author=''): f = File(parent_id=parent_id, author_user_id=author_user_id, name=name, size=0, company_id=company_id, copyright=copyright, author=author, mime='directory') db_session.add(f) db_session.commit() return f.id
def save(self): db_session.add(self) db_session.commit() return self
def ping(self): self.last_seen = datetime.datetime.utcnow() db_session.add(self) db_session.commit()