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 save():
    data = dict(request.form)
    data['image'] = request.files.getlist('image')
    v = Validator(data)
    v.fields('id').integer(nullable=True)
    v.field('name').required()
    v.field('private').boolean()
    v.field('description').required()
    v.field('image').image()
    user = auth.service.get_user()

    if not user.is_authorized():
        abort(403)
    if not v.is_valid():
        return jsonify({
            'status': 'fail',
            'errors': v.errors
        })

    data = v.valid_data
    community = Community.get(data.id)

    if community:
        community.type = Community.TYPE.PRIVATE if data.private else Community.TYPE.PUBLIC
        community.name = data.name
        community.description = data.description
    else:
        community = Community()
        community.type = Community.TYPE.PRIVATE if data.private else Community.TYPE.PUBLIC
        community.name = data.name
        community.description = data.description
        community.owner = user

    db.session.add(community)
    db.session.flush()
    image = data.image
    if image:
        img = community.image = community.image or File.create(name='image.png', module='community', entity=community)
        img.makedir()
        img.update_hash()
        utils.image.thumbnail(image, width=200, height=200, fill=utils.image.COVER).save(img.get_path())
    db.session.commit()
    return jsonify({'status': 'ok',
                    'community': community.as_dict()})
Example #6
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
Example #7
0
 def files(self):
     if self.__files:
         return self.__files
     return File.get(module='comments', entity=self)
Example #8
0
 def files(self):
     if self.__files:
         return self.__files
     return File.get(module='comments', entity=self)