Example #1
0
    def edit_user(cls, uid, full_name=full_name,
                            position=position,
                            mobile_phone=mobile_phone,
                            inner_phone=inner_phone,
                            email=email,
                            birth_date=birth_date,
                            skype=skype,
                            photo=photo):
        u = cls.query.filter_by(id=uid).first()
        if u:
            u.full_name = full_name
            u.position = position
            u.mobile_phone = mobile_phone
            u.inner_phone = inner_phone
            u.email = email
            if birth_date:
                u.birth_date = birth_date
            else:
                u.birth_date = None
            u.skype = skype

            db.session.add(u)
            if photo:
                p = u.photo = u.photo or File.create(name='photo.png', module='users', entity=u)
                p.makedir()
                p.update_hash()
                image.thumbnail(photo, width = 100, height = 100, fill = image.COVER).save(p.get_path(sufix="thumbnail"))
                image.resize(photo).save(p.get_path())
        return u
Example #2
0
    def edit_user(cls,
                  uid,
                  full_name=full_name,
                  position=position,
                  mobile_phone=mobile_phone,
                  inner_phone=inner_phone,
                  email=email,
                  birth_date=birth_date,
                  skype=skype,
                  photo=photo):
        u = cls.query.filter_by(id=uid).first()
        if u:
            u.full_name = full_name
            u.position = position
            u.mobile_phone = mobile_phone
            u.inner_phone = inner_phone
            u.email = email
            if birth_date:
                u.birth_date = birth_date
            else:
                u.birth_date = None
            u.skype = skype

            db.session.add(u)
            if photo:
                p = u.photo = u.photo or File.create(
                    name='photo.png', module='users', entity=u)
                p.makedir()
                p.update_hash()
                image.thumbnail(photo, width=100, height=100,
                                fill=image.COVER).save(
                                    p.get_path(sufix="thumbnail"))
                image.resize(photo).save(p.get_path())
        return u
Example #3
0
def save_files(data, comment):
    ids = data.list('file.id')
    statuses = data.list('file.status')
    types = data.list('file.type')
    uploads = data.list('upload')
    urls = data.list('url')

    files = {f.id: f for f in comment.files}
    for id, status, type, url in zip(ids, statuses, types, urls):
        if id:
            file = files.get(id)
            if file and status == 'deleted':
                db.session.delete(file)
        else:
            file = File.create(name='image.png',
                               module='comments',
                               entity=comment,
                               external_link=url or None)

            if file.is_local():
                file.makedir()
                img = uploads.pop(0)
                _img = Image.open(img)
                width, height = _img.size

                if width / 700 < height / 400:
                    image.resize(img, max_width=700).save(file.get_path())
                else:
                    image.resize(img, max_height=400).save(file.get_path())
                image.resize(img).save(file.get_path(sufix='origin'))
Example #4
0
def save_files(data, comment):
    ids = data.list('file.id')
    statuses = data.list('file.status')
    types = data.list('file.type')
    uploads = data.list('upload')
    urls = data.list('url')

    files = {f.id: f for f in comment.files}
    for id, status, type, url in zip(ids, statuses, types, urls):
        if id:
            file = files.get(id)
            if file and status == 'deleted':
                db.session.delete(file)
        else:
            file = File.create(name='image.png', module='comments', entity=comment, external_link=url or None)

            if file.is_local():
                file.makedir()
                img = uploads.pop(0)
                _img = Image.open(img)
                width, height = _img.size

                if width/700 < height/400:
                    image.resize(img, max_width=700).save(file.get_path())
                else:
                    image.resize(img, max_height=400).save(file.get_path())
                image.resize(img).save(file.get_path(sufix='origin'))
Example #5
0
def _add_user_to_local_db(login, name, surname, email, department, photo,
                          mobile_phone, inner_phone, birth_date, skype):
    try:
        user = User()
        user.login = login
        user.full_name = "{0} {1}".format(name, surname)
        user.mobile_phone = mobile_phone
        user.inner_phone = inner_phone
        user.email = email
        user.department = Department.get_by_name(department)
        user.birth_date = birth_date
        user.skype = skype

        db.session.add(user)
        db.session.flush()

        p = user.photo = File.create(name='photo.png', module='users', entity=user)
        p.makedir()
        p.update_hash()
        image.thumbnail(photo, width=100, height=100, fill=image.COVER).save(p.get_path(sufix="thumbnail"))
        image.resize(photo).save(p.get_path())
        return True
    except:
        return False