Esempio n. 1
0
def send(parent_id):
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(
        urllib.parse.unquote(uploaded_file.filename).replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'),
        parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename, 'description': '', 'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(
                                 chunk_size=int(data.get('chunkSize')),
                                 chunk_number=int(data.get('chunkNumber')),
                                 total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name,
                    data,
                    parent.id,
                    root,
                    content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = utils.db.query_filter(Company, journalist_folder_file_id=root).one()
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(company_id=company.id) is not True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace(
        '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'), parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': uploaded_file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name, data, parent.id, root, company, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}, 'error': True if file == 'error' else False, 'file_id': file})
def cut(json):
    file = File.get(json['params']['id'])
    if not file or not File.if_action_allowed(
            'upload',
            get_company_from_folder(json['params']['id']).id):
        return False
    return file.move_to(json['params']['folder_id'])
Esempio n. 4
0
def send(parent_id):
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace('"','_').replace('*','_').replace('/','_').replace('\\','_'), data.get('ftype'), parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name, data, parent.id, root, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
def remove(json, file_id):
    file = File.get(file_id)
    if not file:
        return False
    ancestors = File.ancestors(file.parent_id)
    return file.remove(
        db(Company, journalist_folder_file_id=ancestors[0]).first().id)
Esempio n. 6
0
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = db(Company, journalist_folder_file_id=root).one()
    if FilemanagerRights(company=company).action_is_allowed(FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(urllib.parse.unquote(uploaded_file.filename).replace(
        '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'), parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': uploaded_file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name, data, parent.id, root, company, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}, 'error': True if file == 'error' else False, 'file_id': file})
def send(parent_id):
    """ YOU SHOULD SEND PROPERTY NAME, DESCRIPTION, ROOT_FOLDER AND FOLDER.
    NOW THIS VALUES GET FROM DB. HARDCODE!!! """
    file = request.files['file']
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(uploaded_file.filename, data.get('ftype'), parent.id)
    company = db(Company, journalist_folder_file_id=root).one()
    if re.match('^video/.*', data.get('ftype')):
        body = {'title': file.filename,
                'description': '',
                'status': 'public'}
        youtube = YoutubeApi(body_dict=body,
                             video_file=file.stream.read(-1),
                             chunk_info=dict(chunk_size=int(data.get('chunkSize')),
                                             chunk_number=int(data.get('chunkNumber')),
                                             total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        youtube.upload()
    else:
        File.upload(name, data, parent.id, root, content=uploaded_file.stream.read(-1))
    return jsonify({'result': {'size': 0}})
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=utils.db.query_filter(Company, journalist_folder_file_id=ancestors[0]).first().id) is not True:
        return False
    return file.remove()
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
            g.db.add(thumbnail)
            g.db.commit()
            thumbnail_content.content = bytes_file.getvalue()
            thumbnail_content.id = thumbnail.id
            g.db.add(thumbnail_content)
            g.db.commit()
            image_id = thumbnail.id
            return redirect(url_for('image_editor.cropped',
                                    id=image_id))

        else:
            g.db.rollback()
            raise BadCoordinates
    file = db(File, id=image_id).one()

    return render_template('image_editor.html',
                           ratio=ratio,
                           img_id=img_id,
                           image=file.url()
                           )
def createdir(json):
    if not File.if_action_allowed(
            'upload',
            get_company_from_folder(json['params']['root_id']).id):
        return False
    return File.createdir(name=json['params']['name'],
                          root_folder_id=json['params']['root_id'],
                          parent_id=json['params']['folder_id'])
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=get_company_from_folder(json['params']['root_id']).id) is not True:
        return False
    return File.set_properties(file, json['params']['add_all'], name=json['params']['name'],
                               copyright_author_name=json['params']['author_name'],
                               description=json['params']['description'])
Esempio n. 12
0
def set_properties(json):
    file = File.get(request.json['params']['id'], )
    return File.set_properties(
        file,
        request.json['params']['add_all'],
        name=request.json['params']['name'],
        copyright_author_name=request.json['params']['author_name'],
        description=request.json['params']['description'])
Esempio n. 13
0
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or FilemanagerRights(
            company=db(Company, journalist_folder_file_id=ancestors[0]).first()).action_is_allowed(
        FilemanagerRights.ACTIONS['REMOVE'], file) != True:
        return False
    return file.remove()
Esempio n. 14
0
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or FilemanagerRights(company=get_company_from_folder(json['params']['id'])).action_is_allowed(
            FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return False
    return File.set_properties(file, json['params']['add_all'], name=json['params']['name'],
                               copyright_author_name=json['params']['author_name'],
                               description=json['params']['description'])
def search_list(json):
    if json['params']['search_text'] != '':
        list = File.list(json['params']['folder'], json['params']['file_manager_called_for'],json['params']['search_text'])
        ancestors = File.ancestors(json['params']['folder'])
    else:
        list = []
        ancestors = File.ancestors(json['params']['folder'])
    return {'list': list, 'ancestors': ancestors}
Esempio n. 16
0
def list(json):
    ancestors = File.ancestors(json['params']['folder_id'])
    company = db(Company, journalist_folder_file_id=ancestors[0]).first()
    if json['params'].get('search_text'):
        list = File.list(json['params']['folder_id'], json['params']['file_manager_called_for'],
                         json['params']['search_text'], company_id=company.id)
    else:
        list = File.list(json['params']['folder_id'], json['params']['file_manager_called_for'],company_id=company.id)
    return {'list': list, 'ancestors': ancestors, 'can_upload': File.if_action_allowed('upload', company.id)}
Esempio n. 17
0
def filemanager():
    from collections import OrderedDict

    last_visit_root_name = ''
    if 'last_root' in request.cookies:
        last_root_id = request.cookies['last_root']
    else:
        last_root_id = ''

    filemanager_company_list = OrderedDict()

    for user_company in g.user.employments:
        if user_company.has_rights(UserCompany.RIGHT_AT_COMPANY.FILES_BROWSE) == True:
            filemanager_company_list[user_company.company_id] = File.folder_dict(user_company.company,
                                                                                 {'can_upload': FilemanagerRights(
                                                                                     company=user_company.company_id).action_is_allowed(
                                                                                     FilemanagerRights.ACTIONS[
                                                                                         'UPLOAD'])})
    for user_company in g.user.employments:
        if user_company.company.own_portal:
            company_membership_in_portal = db(MemberCompanyPortal, portal_id=user_company.company.own_portal.id). \
                filter(
                MemberCompanyPortal.company_id != user_company.company.id and MemberCompanyPortal.status == 'ACTIVE') \
                .join(Company).filter(Company.status == 'ACTIVE').all()

            for company_membership in company_membership_in_portal:
                if company_membership.company_id not in filemanager_company_list:
                    filemanager_company_list[company_membership.company_id] = File.folder_dict(
                        company_membership.company,
                        {
                            'can_upload': FilemanagerRights(
                                company=company_membership.company_id).action_is_allowed(
                                FilemanagerRights.ACTIONS[
                                    'UPLOAD'])})
    # filemanager_company_list.sort(key=lambda k: k['name'])
    file_manager_called_for = request.args[
        'file_manager_called_for'] if 'file_manager_called_for' in request.args else ''
    file_manager_on_action = jsonmodule.loads(
        request.args['file_manager_on_action']) if 'file_manager_on_action' in request.args else {}
    file_manager_default_action = request.args[
        'file_manager_default_action'] if 'file_manager_default_action' in request.args else 'download'
    get_root = request.args[
        'get_root'] if 'get_root' in request.args else None
    if get_root:
        root = Company.get(get_root)
        last_visit_root_name = (root.name) if root else ''
        last_root_id = root.journalist_folder_file_id if root else ''
    err = True if len(filemanager_company_list) == 0 else False
    return render_template('filemanager.html',
                           filemanager_company_list=json.dumps([v for k, v in filemanager_company_list.items()]),
                           err=err,
                           last_visit_root=last_visit_root_name.replace(
                               '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_').replace('\'', '_'),
                           last_root_id=last_root_id,
                           file_manager_called_for=file_manager_called_for,
                           file_manager_on_action=file_manager_on_action,
                           file_manager_default_action=file_manager_default_action)
Esempio n. 18
0
def list(json):
    ancestors = File.ancestors(json['params']['folder_id'])
    company = db(Company, journalist_folder_file_id=ancestors[0]).first()
    if len(json['params'].get('search_text')) > 0:
        list = File.list(json['params']['folder_id'], json['params']['file_manager_called_for'],
                         json['params']['search_text'], company_id=company.id)
    else:
        list = File.list(json['params']['folder_id'], json['params']['file_manager_called_for'], company_id=company.id)
    return {'list': list, 'ancestors': ancestors}
Esempio n. 19
0
def search_list(json):
    if json['params']['search_text'] != '':
        list = File.list(json['params']['folder'],
                         json['params']['file_manager_called_for'],
                         json['params']['search_text'])
        ancestors = File.ancestors(json['params']['folder'])
    else:
        list = []
        ancestors = File.ancestors(json['params']['folder'])
    return {'list': list, 'ancestors': ancestors}
def remove(json, file_id):
    file = File.get(file_id)
    ancestors = File.ancestors(file.parent_id)
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=utils.db.query_filter(
                    Company, journalist_folder_file_id=ancestors[0]).first(
                    ).id) is not True:
        return False
    return file.remove()
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or not File.if_action_allowed(
            'upload',
            get_company_from_folder(json['params']['id']).id):
        return False
    return File.set_properties(
        file,
        json['params']['add_all'],
        name=json['params']['name'],
        copyright_author_name=json['params']['author_name'],
        description=json['params']['description'])
def set_properties(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=get_company_from_folder(
                    json['params']['root_id']).id) is not True:
        return False
    return File.set_properties(
        file,
        json['params']['add_all'],
        name=json['params']['name'],
        copyright_author_name=json['params']['author_name'],
        description=json['params']['description'])
def list(json):
    ancestors = File.ancestors(json['params']['folder_id'])
    company = db(Company, journalist_folder_file_id=ancestors[0]).first()
    if len(json['params'].get('search_text')) > 0:
        list = File.list(json['params']['folder_id'],
                         json['params']['file_manager_called_for'],
                         json['params']['search_text'],
                         company_id=company.id)
    else:
        list = File.list(json['params']['folder_id'],
                         json['params']['file_manager_called_for'],
                         company_id=company.id)
    return {'list': list, 'ancestors': ancestors}
def createdir(json):
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD). \
            check(company_id=get_company_from_folder(json['params']['root_id']).id) is not True:
        return False
    return File.createdir(name=json['params']['name'],
                          root_folder_id=json['params']['root_id'],
                          parent_id=json['params']['folder_id'])
def createdir(json):
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD). \
            check(company_id=get_company_from_folder(json['params']['root_id']).id) is not True:
        return False
    return File.createdir(name=json['params']['name'],
                          root_folder_id=json['params']['root_id'],
                          parent_id=json['params']['folder_id'])
Esempio n. 26
0
def createdir(json):
    if FilemanagerRights(company=get_company_from_folder(json['params']['root_id'])).action_is_allowed(
            FilemanagerRights.ACTIONS['CREATE_FOLDER']) != True:
        return False
    return File.createdir(name=json['params']['name'],
                          root_folder_id=json['params']['root_id'],
                          parent_id=json['params']['folder_id'])
def send(parent_id):
    parent = File.get(parent_id)
    root = parent.root_folder_id
    if parent.mime == 'root':
        root = parent.id
    company = utils.db.query_filter(Company,
                                    journalist_folder_file_id=root).one()
    if EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
            company_id=company.id) is not True:
        return jsonify({'error': True})
    data = request.form
    uploaded_file = request.files['file']
    name = File.get_unique_name(
        urllib.parse.unquote(uploaded_file.filename).replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_'), data.get('ftype'),
        parent.id)
    data.get('ftype')
    if re.match('^video/.*', data.get('ftype')):
        body = {
            'title': uploaded_file.filename,
            'description': '',
            'status': 'public'
        }
        youtube = YoutubeApi(body_dict=body,
                             video_file=uploaded_file.stream.read(-1),
                             chunk_info=dict(
                                 chunk_size=int(data.get('chunkSize')),
                                 chunk_number=int(data.get('chunkNumber')),
                                 total_size=int(data.get('totalSize'))),
                             company_id=company.id,
                             root_folder_id=company.journalist_folder_file_id,
                             parent_folder_id=parent_id)
        file = youtube.upload()
    else:
        file = File.upload(name,
                           data,
                           parent.id,
                           root,
                           company,
                           content=uploaded_file.stream.read(-1))
    return jsonify({
        'result': {
            'size': 0
        },
        'error': True if file == 'error' else False,
        'file_id': file
    })
def cut(json):
    file = File.get(json['params']['id'])
    if not file or EmployeeHasRightAtCompany(
            RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                company_id=get_company_from_folder(
                    json['params']['folder_id']).id) is not True:
        return False
    return file.move_to(json['params']['folder_id'])
def filemanager():
    from collections import OrderedDict
    from profapp.models.company import UserCompany

    last_visit_root_name = ''
    if 'last_root' in request.cookies:
        last_root_id = request.cookies['last_root']
    else:
        last_root_id = ''

    filemanager_company_list = OrderedDict()
    file_manager_called_for = request.args.get('file_manager_called_for', '')

    for company in g.user.companies_employer_active:

        if UserCompany.get_by_user_and_company_ids(
                company_id=company.id).has_rights(
                    RIGHT_AT_COMPANY.FILES_BROWSE):
            filemanager_company_list[company.id] = File.folder_dict(
                company, {
                    'can_upload':
                    EmployeeHasRightAtCompany(
                        RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                            company_id=company.id)
                })

    file_manager_on_action = jsonmodule.loads(
        request.args['file_manager_on_action']
    ) if 'file_manager_on_action' in request.args else {}
    file_manager_default_action = request.args[
        'file_manager_default_action'] if 'file_manager_default_action' in request.args else 'download'
    get_root = request.args['get_root'] if 'get_root' in request.args else None
    if get_root:
        root = Company.get(get_root)
        last_visit_root_name = (root.name) if root else ''
        last_root_id = root.journalist_folder_file_id if root else ''
    err = True if len(filemanager_company_list) == 0 else False
    return render_template(
        'filemanager.html',
        filemanager_company_list=json.dumps(
            [v for k, v in filemanager_company_list.items()]),
        err=err,
        last_visit_root=last_visit_root_name.replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_').replace('\'', '_'),
        last_root_id=last_root_id,
        file_manager_called_for=file_manager_called_for,
        file_manager_on_action=file_manager_on_action,
        file_manager_default_action=file_manager_default_action)
def filemanager():
    from collections import OrderedDict
    from profapp.models.company import UserCompany

    last_visit_root_name = ''
    if 'last_root' in request.cookies:
        last_root_id = request.cookies['last_root']
    else:
        last_root_id = ''

    filemanager_company_list = OrderedDict()
    file_manager_called_for = request.args.get('file_manager_called_for', '')

    for company in g.user.companies_employer_active:

        if UserCompany.get_by_user_and_company_ids(company_id=company.id).has_rights(RIGHT_AT_COMPANY.FILES_BROWSE):
            filemanager_company_list[company.id] = File.folder_dict(
                company, {'can_upload': EmployeeHasRightAtCompany(RIGHT_AT_COMPANY.FILES_UPLOAD).check(
                    company_id=company.id)})

    file_manager_on_action = jsonmodule.loads(
        request.args['file_manager_on_action']) if 'file_manager_on_action' in request.args else {}
    file_manager_default_action = request.args[
        'file_manager_default_action'] if 'file_manager_default_action' in request.args else 'download'
    get_root = request.args[
        'get_root'] if 'get_root' in request.args else None
    if get_root:
        root = Company.get(get_root)
        last_visit_root_name = (root.name) if root else ''
        last_root_id = root.journalist_folder_file_id if root else ''
    err = True if len(filemanager_company_list) == 0 else False
    return render_template('filemanager.html',
                           filemanager_company_list=json.dumps([v for k, v in filemanager_company_list.items()]),
                           err=err,
                           last_visit_root=last_visit_root_name.replace(
                               '"', '_').replace('*', '_').replace('/', '_').replace('\\', '_').replace('\'', '_'),
                           last_root_id=last_root_id,
                           file_manager_called_for=file_manager_called_for,
                           file_manager_on_action=file_manager_on_action,
                           file_manager_default_action=file_manager_default_action)
Esempio n. 31
0
def cut(json):
    file = File.get(request.json['params']['id'])
    return File.move_to(file, request.json['params']['folder_id'])
Esempio n. 32
0
def get_company_from_folder(file_id):
    ancestors = File.ancestors(file_id)
    return db(Company, journalist_folder_file_id=ancestors[0]).first()
Esempio n. 33
0
def auto_remove(json):
    return File.auto_remove(json.get('list'))
Esempio n. 34
0
def cut(json):
    file = File.get(json['params']['id'])
    if not file or FilemanagerRights(company=get_company_from_folder(json['params']['id'])).action_is_allowed(
            FilemanagerRights.ACTIONS['UPLOAD']) != True:
        return False
    return file.move_to(json['params']['folder_id'])
Esempio n. 35
0
def remove(file_id):
    return File.remove(file_id)
Esempio n. 36
0
def rename(json):
    file = File.get(request.json['params']['id'], )
    return File.rename(file, request.json['params']['name'])
Esempio n. 37
0
def copy(json):
    file = File.get(request.json['params']['id'])
    file.copy_file(request.json['params']['folder_id'])
    return file.id
def get_company_from_folder(file_id):
    ancestors = File.ancestors(file_id)
    return db(Company, journalist_folder_file_id=ancestors[0]).first()
Esempio n. 39
0
def list(json):
    list = File.list(json['params']['folder_id'],
                     json['params']['file_manager_called_for'])
    ancestors = File.ancestors(json['params']['folder_id'])
    return {'list': list, 'ancestors': ancestors}
Esempio n. 40
0
def auto_remove(json):
    return File.auto_remove(json.get('name'), json.get('folder_id'))
Esempio n. 41
0
def copy(json):
    file = File.get(request.json['params']['id'])
    file.copy_file(request.json['params']['folder_id'])
    return file.id
Esempio n. 42
0
def createdir(json, parent_id=None):
    return File.createdir(name=request.json['params']['name'],
                          root_folder_id=request.json['params']['root_id'],
                          parent_id=request.json['params']['folder_id'])
def get_company_from_folder(file_id):
    ancestors = File.ancestors(file_id)
    return utils.db.query_filter(
        Company, journalist_folder_file_id=ancestors[0]).first()
def filemanager():
    last_visit_root_name = ''
    if 'last_root' in request.cookies:
        last_root_id = request.cookies['last_root']
    else:
        last_root_id = ''

    library = []
    members, main_companies = Company.get_members_for_company()
    uniq = set()
    for n, user_company in enumerate(g.user.employer_assoc):
        if user_company.has_rights(UserCompany.RIGHT_AT_COMPANY.FILES_BROWSE):
            library.insert(
                n,
                File.folder_dict(
                    user_company.employer, {
                        'can_upload':
                        File.if_action_allowed(File.ACTIONS['upload'],
                                               user_company.company_id)
                    }))
            uniq.update({user_company.employer.name})
            if user_company.employer.journalist_folder_file_id == last_root_id:
                last_visit_root_name = user_company.employer.name + " files"
            if user_company.employer.name in members:
                for member in members[user_company.employer.name]:
                    if member.company.name not in uniq and member.company.name not in main_companies:
                        library.append(
                            File.folder_dict(
                                member.company, {
                                    'can_upload':
                                    File.if_action_allowed(
                                        File.ACTIONS['upload'],
                                        member.company.id)
                                }))
                        uniq.update({member.company.name})
                        if member.company.journalist_folder_file_id == last_root_id:
                            last_visit_root_name = member.company.name + " files"
    # library.sort(key=lambda k: k['name'])
    file_manager_called_for = request.args[
        'file_manager_called_for'] if 'file_manager_called_for' in request.args else ''
    file_manager_on_action = jsonmodule.loads(
        request.args['file_manager_on_action']
    ) if 'file_manager_on_action' in request.args else {}
    file_manager_default_action = request.args[
        'file_manager_default_action'] if 'file_manager_default_action' in request.args else 'download'
    get_root = request.args['get_root'] if 'get_root' in request.args else None
    if get_root:
        root = Company.get(get_root)
        last_visit_root_name = (root.name + " files") if root else ''
        last_root_id = root.journalist_folder_file_id if root else ''
    err = True if len(library) == 0 else False
    return render_template(
        'filemanager.html',
        library=json.dumps(library),
        err=err,
        last_visit_root=last_visit_root_name.replace('"', '_').replace(
            '*', '_').replace('/', '_').replace('\\', '_').replace('\'', '_'),
        last_root_id=last_root_id,
        file_manager_called_for=file_manager_called_for,
        file_manager_on_action=file_manager_on_action,
        file_manager_default_action=file_manager_default_action)
Esempio n. 45
0
from flask import g
from profapp import create_app, prepare_connections
import argparse, os

if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='send greetings message')
    parser.add_argument("--file_id")
    parser.add_argument("--file_name")
    parser.add_argument("--parent_id")
    parser.add_argument("--mime")
    parser.add_argument("--file")
    args = parser.parse_args()

    app = create_app(apptype='profi', config='config.CommandLineConfig')
    with app.app_context():
        prepare_connections(app)(echo=True)

        f = open(args.file, 'rb')
        file = File(parent_id=args.parent_id,
                    root_folder_id=args.parent_id,
                    name=args.file_name,
                    company_id=None,
                    mime=args.mime,
                    size=os.path.getsize(args.file)).save()
        file_cont = FileContent(file=file, content=f.read())

        file.save()
        file.id = args.file_id
        g.db.commit()
def get_company_from_folder(file_id):
    ancestors = File.ancestors(file_id)
    return utils.db.query_filter(Company, journalist_folder_file_id=ancestors[0]).first()
Esempio n. 47
0
def rename(json):
    file = File.get(request.json['params']['id'], )
    return File.rename(file, request.json['params']['name'])
def test():
    file = File.get('5644d72e-a269-4001-a5de-8c3194039273')
    name = File.set_properties(file,False,name='None', copyright_author_name='',description='')
    return render_template('tmp-test.html', file=name)
Esempio n. 49
0
def cut(json):
    file = File.get(request.json['params']['id'])
    return File.move_to(file, request.json['params']['folder_id'])
Esempio n. 50
0
def auto_remove(json):
    return File.auto_remove(json.get('name'), json.get('folder_id'))
Esempio n. 51
0
def remove(file_id):
    return File.remove(file_id)
def auto_remove(json):
    return File.auto_remove(json.get('list'))
Esempio n. 53
0
def list(json):
    list = File.list(json['params']['folder_id'], json['params']['file_manager_called_for'])
    ancestors = File.ancestors(json['params']['folder_id'])
    return {'list': list, 'ancestors': ancestors}
def cropped(id):
    return render_template('cropped_image.html',
                           image=File.get(id).url()
                           )
Esempio n. 55
0
def set_properties(json):
    file = File.get(request.json['params']['id'], )
    return File.set_properties(file, request.json['params']['add_all'], name=request.json['params']['name'],
                               copyright_author_name=request.json['params']['author_name'],
                               description=request.json['params']['description'])
Esempio n. 56
0
def createdir(json, parent_id=None):
    return File.createdir(name=request.json['params']['name'],
                          root_folder_id=request.json['params']['root_id'],
                          parent_id=request.json['params']['folder_id'])