示例#1
0
def previous_sessions_view():
    sorting = request.args.get('sorting', default='recent')
    if sorting != 'recent' and sorting != 'old':
        sorting = 'recent'
    print(sorting)
    sessions = []
    if sorting == "recent":
        sessions = SessionModel.find_all_sessions().order_by(
            desc(SessionModel.dateCreated))
    elif sorting == "old":
        sessions = SessionModel.find_all_sessions().order_by(
            asc(SessionModel.dateCreated))
    return render_template('previous_sessions.html',
                           sessions=sessions,
                           sorting=sorting)
 def get_dates_for_session(self, sessionNumber):
     actual_session_id = SessionModel.find_by_sessionNumber(sessionNumber)
     datesForSession = [
         date for date in self.sessionDates
         if date.session_id == actual_session_id.id
     ]
     return datesForSession
示例#3
0
def fetch_active_session_assets():
    session = SessionModel.find_active_session()
    if session:
        dates = get_full_session(session)
        return jsonify({"assets": [date.json() for date in dates]})
    else:
        return dumps([])
示例#4
0
def continue_session():
    # Make sure a session is already active. If not then create a new one
    session = SessionModel.find_active_session()
    if session == None:
        flash("No active session. A new session was created", "warning")
        return redirect('/new_session')
    return render_template('enter_session.html', mode="continue")
示例#5
0
def new_session():
    # Check if the active session has any assets in it
    # If it has no assets then don't create a new session
    session = SessionModel.find_active_session()
    if session == None or len(session.assets) > 0:
        new_session = SessionModel()
        new_session.save_to_db()
        return render_template('enter_session.html', mode="new")
    else:
        session.remove_from_db()
        new_session = SessionModel()
        new_session.save_to_db()
        return render_template('enter_session.html', mode="empty")
示例#6
0
def createDateList(id):
    session = SessionModel.find_by_sessionNumber(id)
    if session != None:
        custom_session = copy.deepcopy(session)
        dates = get_full_session(session)
        setattr(custom_session, "dates", [date.json() for date in dates])
        return custom_session
    return None
示例#7
0
def inject_active_session():
    if current_user.is_authenticated:
        active = SessionModel.find_active_session()
        if active:
            return dict(active=active)
        else:
            return dict(active=None)
    else:
        return dict(active=None)
示例#8
0
def session_page_assets(id=None):
    if id != None:
        session = SessionModel.find_by_sessionNumber(id)
        if session != None:
            custom_session = copy.deepcopy(session)
            dates = get_full_session(session)
            return jsonify([date.json() for date in dates])
        else:
            return abort(404,
                         "The session you're looking for was not found"), 404
    return None
示例#9
0
def session_delete(id=None):
    if id is not None:
        # Delete the session with number <id> from db
        session = SessionModel.find_by_sessionNumber(id)
        # Need to delete all asset entries in the date model where the session id == the session to delete
        session.remove_from_db()
        return json.dumps({'success': True}), 200, {
            'ContentType': 'application/json'
        }
    return json.dumps({'success': False}), 400, {
        'ContentType': 'application/json'
    }
示例#10
0
def removeAssetFromSession(id=None):
    if id != None:
        session = SessionModel.find_by_sessionNumber(id)
        if session:
            index = json.loads(request.form.get('index'))
            dates = get_full_session(session)
            dates[index].remove_from_db()
            return json.dumps({"success": True}), 200, {
                'ContentType': "application/json"
            }
        else:
            return abort(404,
                         "The session you're looking for was not found"), 404
    return None
示例#11
0
def session_page_info(id=None):
    if id != None:
        session = SessionModel.find_by_sessionNumber(id)
        if session != None:
            info = {
                'sessionName':
                session.sessionName,
                'sessionAuthor':
                current_user.firstname + " " + current_user.lastname
            }
            return jsonify(info)
        else:
            return abort(404,
                         "The session you're looking for was not found"), 404
    return None
示例#12
0
def presenter_view():
    session = SessionModel.find_active_session()
    if session == None:
        return redirect('/new_session')
    bckgrnd = current_user.backgroundColour
    if current_user.activeSession:
        activeSession = get_full_session(current_user.activeSession)
        lastAsset = {}
        if (len(activeSession)):
            lastAsset = json.dumps(activeSession[len(activeSession) -
                                                 1].asset.json())
    return render_template('presenter.html',
                           background_color=bckgrnd,
                           background_colorRGB=bckgrnd.rgb,
                           lastAsset=lastAsset)
示例#13
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")
示例#14
0
def session_update(id=None):
    if id != None:
        session = SessionModel.find_by_sessionNumber(id)
        if session != None:
            if request.method == 'POST':
                form = FormSession(request.form)
                if form.validate():
                    session.update_name(form.sessionname.data)
                    return redirect(url_for('session_page', id=id))
                else:
                    custom_session = copy.deepcopy(session)
                    dates = get_full_session(session)
                    setattr(custom_session, "dates",
                            [date.json() for date in dates])
                    return render_template('session.html',
                                           session=custom_session,
                                           form=form)
            else:
                return redirect(url_for('session_page', id=id))
        else:
            return abort(404,
                         "The session you're looking for was not found"), 404
    return redirect('/sessions')
示例#15
0
def controller_view():
    session = SessionModel.find_active_session()
    if session:
        return render_template('controller.html')
    else:
        return redirect('/new_session')