コード例 #1
0
def addAsset():
    form = FormAsset()
    if request.method == "POST" and form.validate():
        asset = AssetModel(form.assetname.data, current_user.get_id(),
                           form.assettype.data)
        tags = form.tagname.data.split(",")
        for tag in tags:
            # Remove extra white space
            tag = " ".join(tag.split())
            if len(tag) > 0:
                tag_obj = TagModel.find_by_tagName(tag)
                if tag_obj is None:  #then tag currently does not exist and needs to be added
                    tag_obj = TagModel(tag, current_user.get_id())
                    tag_obj.save_to_db()
                asset.tags.append(tag_obj)
        asset.assetLink = form.assetLink.data
        try:
            print(f'asset resource in addAsset is {form.assetResource.data}')
            upload(asset, form.assetResource.data,
                   form.assetAutomaticThumbnail.data)
        except Exception as e:
            print(e)
            flash("Error uploading file", "danger")
            return render_template("asset_form.html", form=form)
        try:
            #if the files related to the asset have successfully been saved to file system, update the asset in the db now that it has those file locations
            asset.save_to_db()
        except:
            flash("Error while saving asset to db")
            return render_template("asset_form.html", form=form)
        flash("Successfully added asset", "success")
        return redirect('/assets/new')
    else:
        return render_template("asset_form.html", form=form)
コード例 #2
0
def assets_bulk_delete():
    idList = json.loads(request.form.get('idList'))
    deleted = []
    if idList is not None:
        for id in idList:
            # Delete the asset with id from db
            AssetModel.delete_by_assetId(id)
            deleted.append(id)
    return json.dumps(deleted)
コード例 #3
0
def asset_delete(id=None):
    if id is not None:
        # Delete the asset with id from db
        asset = AssetModel.find_by_assetId(id)
        # If the tag only belongs to the asset being deleted, remove the tag
        for tag in asset.tags:
            if len(tag.assets) <= 1:
                TagModel.remove_tag(tag.tagname)
        AssetModel.delete_by_assetId(id)
        return json.dumps({'success': True}), 200, {
            'ContentType': 'application/json'
        }
    return json.dumps({'success': False}), 400, {
        'ContentType': 'application/json'
    }
コード例 #4
0
def asset_update(id=None):

    if id is not None:
        form = FormUpdateAsset(request.form)
        asset = AssetModel.find_by_assetId(id)

        if form.validate():
            tag_array = form.tagArrayString.data
            tag_array = tag_array.split(',')
            tag_array = [x.lower() for x in tag_array]
            existing_tags = [item.tagname.lower() for item in asset.tags]
            for tag in tag_array:
                if len(tag) > 0:
                    if not tag in existing_tags:  # if the tag does not exist in the asset add it
                        new_tag = TagModel.add_tag(tag)
                        asset.tags.append(new_tag)
                        asset.save_to_db()
                # if tag already exists in the asset, do nothing

            for existing_tag in existing_tags:
                if not existing_tag in tag_array:  #if existing tag is not in the new tag_array, delete it
                    tag_to_delete = TagModel.add_tag(existing_tag)
                    asset.tags.remove(tag_to_delete)
                    asset.save_to_db()
                #if existing tag is present in the new tag_array keep it
            if form.assetname.data:
                asset.assetname = form.assetname.data
                asset.save_to_db()
            if form.assetAutomaticThumbnail.data:
                upload(asset, None, form.assetAutomaticThumbnail.data)
                asset.save_to_db()

    return redirect(url_for('asset', id=id))
コード例 #5
0
def fetch_asset():
    id = int(request.args.get('id'))
    asset = {}
    if id is not None:
        asset = AssetModel.find_by_assetId(id).json()
        return dumps(asset, default=json_serial)
    return None
コード例 #6
0
def handleMessage(data):
    session = SessionModel.find_active_session()
    #print(session.active)
    fromTabs = data['fromTabs']
    asset_id = data['id']
    tab = int(data['tab'])
    print("ID: " + asset_id + " Tab: " + str(tab))
    asset = {}
    if asset_id is not None:
        asset = AssetModel.find_by_assetId(asset_id).json()
        asset.pop('date-created')
        socketio.emit('presenter', asset, room=str(current_user.get_id()))

    if (not fromTabs):
        asset = AssetModel.find_by_assetId(asset_id)
        if (session):
            session.add_asset(asset, tab)
        else:
            print("No active session")
コード例 #7
0
def asset(id=None):
    form = FormUpdateAsset()
    if id is not None:
        asset = AssetModel.find_by_assetId(id)
        if asset:
            return render_template('asset_page.html', asset=asset, form=form)
        else:
            return abort(404,
                         "The asset you're looking for was not found"), 404
    return render_template('asset_page.html', asset=None, form=form)