Example #1
0
def enable_automation():
    redis_conn.set("automation_enabled", "true")

    # Create automation set for automation to log to
    automation_set = DJSet(1)
    db.session.add(automation_set)
    db.session.commit()
    app.logger.info("Automation enabled with DJSet.id = {}".format(automation_set.id))
    redis_conn.set("automation_set", str(automation_set.id))
Example #2
0
def disable_automation():
    automation_enabled = redis_conn.get("automation_enabled")
    # Make sure automation is actually enabled before changing the end time
    if automation_enabled is not None and automation_enabled == "true":
        redis_conn.set("automation_enabled", "false")
        automation_set_id = redis_conn.get("automation_set")
        app.logger.info("Automation disabled with DJSet.id = {}".format(automation_set_id))
        if automation_set_id is not None:
            automation_set = DJSet.query.get(int(automation_set_id))
            automation_set.dtend = datetime.utcnow()
            db.session.commit()
Example #3
0
    def dj_wrapper(*args, **kwargs):
        # Call in the function first incase it changes the timeout
        ret = f(*args, **kwargs)

        redis_conn.set('dj_active', 'true')
        # logout/login must delete this dj_timeout
        expire = redis_conn.get('dj_timeout')
        if redis_conn.get('dj_timeout') is None:
            expire = app.config['DJ_TIMEOUT']

        redis_conn.expire('dj_active', int(expire))

        return ret
Example #4
0
def change_autologout():
    if request.method == 'GET':
        dj_timeout = redis_conn.get('dj_timeout')
        if dj_timeout is None:
            return jsonify(success=True, autologout=True)
        else:
            return jsonify(success=True, autologout=False)
    elif request.method == 'POST':
        if 'autologout' not in request.form:
            return jsonify(success=False, error='No autologout field given in POST')
        if request.form['autologout'] == 'enable':
            redis_conn.delete('dj_timeout')
            # This needs to be reexpired now since dj_timeout changed after dj_interact
            return jsonify(success=True, autologout=True)
        else:
            redis_conn.set('dj_timeout', app.config['EXTENDED_DJ_TIMEOUT'])
            return jsonify(success=True, autologout=False)
Example #5
0
def logout(setid):
    djset = DJSet.query.get_or_404(setid)
    if djset.dtend is None:
        djset.dtend = datetime.datetime.utcnow()
    else:
        # This has already been logged out
        return redirect(url_for('trackman.login'))
    db.session.commit()

    # Reset the dj activity timeout period
    redis_conn.delete('dj_timeout')

    # Set dj_active expiration to NO_DJ_TIMEOUT to reduce automation start time
    redis_conn.set('dj_active', 'false')
    redis_conn.expire('dj_active', int(app.config['NO_DJ_TIMEOUT']))

    # email playlist
    if 'email_playlist' in request.form and request.form.get('email_playlist') == 'true':
        email_playlist(djset)

    return redirect(url_for('trackman.login'))
Example #6
0
def donation_index():
    if not app.config['DONATE_ENABLE']:
        abort(404)

    if request.method == 'POST':
        if 'reset_stats' in request.form:
            redis_conn.set('donation_stats_start',
                           datetime.datetime.utcnow().isoformat())
        return redirect(url_for('.donation_index'))

    stats = Order.query.with_entities(
        db.func.sum(Order.amount).label('total_paid'),
        db.func.max(Order.amount).label('max_paid'))

    donation_stats_start = redis_conn.get('donation_stats_start')
    if donation_stats_start is not None:
        last_stats_reset = dateutil.parser.parse(donation_stats_start)
        stats = stats.filter(Order.placed_date > last_stats_reset)
    else:
        last_stats_reset = None

    stats = stats.all()

    total = stats[0][0]
    if total is None:
        total = 0

    max_donation = stats[0][1]
    if max_donation is None:
        max_donation = 0

    donations = Order.query.all()

    return render_template('admin/donation_index.html',
                           donations=donations,
                           total=total,
                           max=max_donation,
                           last_stats_reset=last_stats_reset)