예제 #1
0
    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)
예제 #2
0
    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
예제 #3
0
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))
예제 #4
0
파일: files.py 프로젝트: promko/profireader
 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
예제 #5
0
파일: files.py 프로젝트: promko/profireader
 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
예제 #6
0
    def apply_request(comp_id, user_id, bool):

        if bool == "True":
            stat = statuses.ACTIVE()

        else:
            stat = statuses.REJECT()
        db(UserCompanyRole, status=statuses.NONACTIVE(), company_id=comp_id, user_id=user_id).update(
            {"status": stat, "right_id": "comment", "user_rights": db(User, id=user_id)}
        )
        db_session.commit()
예제 #7
0
    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
예제 #8
0
    def apply_request(comp_id, user_id, bool):

        status = STATUS()
        r = Right()
        if bool == "True":
            stat = status.ACTIVE()
            r.add_rights(user_id, comp_id, Config.BASE_RIGHT_IN_COMPANY)
        else:
            stat = status.REJECT()
        db(UserCompany, company_id=comp_id, user_id=user_id, status=status.NONACTIVE()).update({"status": stat})
        db_session.commit()
예제 #9
0
파일: users.py 프로젝트: promko/profireader
 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
예제 #10
0
파일: users.py 프로젝트: promko/profireader
 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
예제 #11
0
    def add_rights(user_id, comp_id, rights):

        ucr = []
        user = db(User, id=user_id).one()
        for right in rights:
            ucr.append(UserCompanyRight(company_right_id=right))
        user_right = db(UserCompany, user_id=user_id, company_id=comp_id).one()
        user_right.user = user
        user_right.company = db(Company, id=comp_id).one()
        user.companies.append(user_right.company)
        user_right.right = ucr
        db_session.commit()
예제 #12
0
    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
예제 #13
0
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)
                           )
예제 #14
0
    def update_comp(company_id, data, file):

        comp = db(Company, id=company_id)
        for x, y in zip(data.keys(), data.values()):
            comp.update({x: y})
        if file.filename:
            comp.update(
                {
                    "logo_file": File.upload(
                        file=file,
                        company_id=company_id,
                        parent_id=comp.corporate_folder_file_id,
                        author=g.user_dict["name"],
                        author_user_id=g.user_dict["id"],
                    )
                }
            )
        db_session.commit()
예제 #15
0
파일: files.py 프로젝트: promko/profireader
 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
예제 #16
0
 def save(self):
     db_session.add(self)
     db_session.commit()
     return self
예제 #17
0
파일: users.py 프로젝트: promko/profireader
 def ping(self):
     self.last_seen = datetime.datetime.utcnow()
     db_session.add(self)
     db_session.commit()
예제 #18
0
    def remove_rights(user_id, comp_id, rights):

        user_right = db(UserCompany, user_id=user_id, company_id=comp_id).one()
        for right in rights:
            user_right.right.remove(UserCompanyRight(company_right_id=right))
            db_session.commit()