Beispiel #1
0
def help_latest(location=None, category=None):
    """automatically selects next inquiry"""
    if not category or category == 'all':
        inquiry = Inquiry.latest(location=location)
    else:
        inquiry = Inquiry.latest(location=location, category=category)
    delayed_id, delayed = request.args.get('delayed_id', None), None
    if not inquiry:
        return redirect(url_for('admin.home', notification=NOTIF_HELP_DONE))
    if g.queue.setting('inquiry_types').enabled and not category and g.queue.setting('inquiry_type_selection').enabled:
        categories = [(cat, Inquiry.query.filter_by(
            category=cat,
            status='unresolved',
            location=location,
            queue_id=g.queue.id).count())
            for cat in g.queue.setting('inquiry_types').value.split(',')]
        categories = [c for c in categories if c[1]]
        if len(categories) > 1:
            return render_admin('categories.html',
                title='Request Type',
                location=location,
                categories=categories)
    if delayed_id:
        delayed = Inquiry.query.get(delayed_id)
        delayed.unlock()
    inquiry.lock()
    inquiry.link(current_user())
    return redirect(url_for('admin.help_inquiry',
        id=inquiry.id, location=location))
Beispiel #2
0
def clear() -> str:
    """Clear all inquiries, period."""
    context = {'action': 'Admin Home', 'url': url_for('admin.home')}
    if request.method == 'POST':
        Inquiry.clear_all_inquiries()
        context['message'] = 'All Cleared'
        return render_admin('admin_confirm.html', **context)
    context['message'] = 'Are you sure? This will clear all resolving and'
    'unresolved.<form method="POST"><input type="submit" value="clear"></form>'
    return render_admin('admin_confirm.html', **context)
Beispiel #3
0
def home() -> str:
    """The queue administration home page."""
    return render_admin(
        'home.html',
        num_inquiries=Inquiry.get_num_unresolved(),
        latest_inquiry=Inquiry.get_current_or_latest(),
        current_inquiry=Inquiry.get_current(),
        ttr=g.queue.ttr(),
        earliest_request=Inquiry.get_earliest(),
        locations=Inquiry.get_unresolved(
            str2lst(g.queue.setting('locations').value), 'location'))
Beispiel #4
0
def help_inquiry(id: str, location: str=None) -> str:
    """automatically selects next inquiry or reloads inquiry."""
    inquiry = Inquiry.query.get(id).maybe_lock()
    if request.method == 'POST':
        delayed_id = None
        inquiry.resolution.close()
        emitQueuePositions(inquiry)
        emitQueueInfo(inquiry.queue)
        if request.form['status'] == 'resolved':
            inquiry.resolved()
        elif request.form['status'] == 'unresolved':
            delayed_id = id
        if request.form['load_next'] != 'y':
            if request.form['status'] == 'unresolved':
                inquiry.unlock()
            return redirect(url_for('admin.home'))
        return redirect(
            url_for(
                'admin.help_latest',
                location=location,
                delayed_id=delayed_id))
    return render_admin(
        'help_inquiry.html',
        inquiry=inquiry,
        inquiries=Inquiry.get_current_user_inquiries(),
        hide_event_nav=True,
        group=inquiry.get_similar_inquiries(),
        wait_time=inquiry.get_wait_time('%h:%m:%s'))
Beispiel #5
0
def home() -> str:
    """List all unresolved inquiries for the homepage."""
    if current_user().can('help'):
        return redirect(url_for('admin.home'))
    return render_queue(
        'landing.html',
        num_inquiries=Inquiry.get_num_unresolved(),
        ttr=g.queue.ttr())
Beispiel #6
0
def inquiry() -> str:
    """Place a new request.

    This request which may be authored by either a system user or an anonymous
    user.
    """
    user = current_user()
    if not user.is_authenticated and \
            g.queue.setting(name='require_login').enabled:
        return render_queue(
            'confirm.html',
            title='Login Required',
            message='Login to add an inquiry, and start using this queue.')
    form = InquiryForm(request.form, obj=user)
    n = int(g.queue.setting(name='max_requests').value)
    if User.get_num_current_requests(request.form.get('name', None)) >= n:
        if not current_user().is_authenticated:
            message = 'If you haven\'t submitted a request, try'
            ' logging in and re-requesting.'
        else:
            message = 'Would you like to cancel your oldest request?'
        return render_queue(
            'confirm.html',
            title='Oops',
            message='Looks like you\'ve reached the maximum number of times '
            'you can add yourself to the queue at once (<code>%d</code>). '
            '%s' % (n, message),
            action='Cancel Oldest Request',
            url=url_for('queue.cancel'))
    form.location.choices = choicify(g.queue.setting('locations').value)
    form.category.choices = choicify(g.queue.setting('inquiry_types').value)
    if request.method == 'POST' and form.validate() and \
            g.queue.is_valid_assignment(request, form):
        inquiry = Inquiry(**request.form).update(queue_id=g.queue.id)
        if current_user().is_authenticated:
            inquiry.owner_id = current_user().id
        inquiry.save()
        emitQueueInfo(g.queue)
        return redirect(url_for('queue.waiting', inquiry_id=inquiry.id))
    return render_queue(
        'form.html',
        form=form,
        title='Request Help',
        submit='Request Help')
Beispiel #7
0
def home():
    """admin homepage"""
    if not g.queue.setting('location_selection').enabled:
        return render_admin('home.html',
            num_inquiries=Inquiry.query.filter_by(status='unresolved', queue_id=g.queue.id).count(),
            latest_inquiry=Inquiry.latest(),
            current_inquiry=Inquiry.current(),
            ttr=g.queue.ttr())
    locations = [(l,
        Inquiry.query.filter_by(
            location=l, status='unresolved', queue_id=g.queue.id).count())
        for l in g.queue.setting('locations').value.split(',')]
    return render_admin('home.html',
        num_inquiries=Inquiry.query.filter_by(status='unresolved', queue_id=g.queue.id).count(),
        locations=[t for t in locations if t[1]],
        current_inquiry=Inquiry.current(),
        ttr=g.queue.ttr(),
        earliest_request=Inquiry.query.filter_by(status='unresolved',
            queue_id=g.queue.id).order_by(Inquiry.created_at).first())
Beispiel #8
0
def inquiry():
    """
    Place a new request, which may be authored by either a system user or an
    anonymous user.
    """
    user, form = flask_login.current_user, InquiryForm(request.form)
    if user.is_authenticated:
        form = InquiryForm(request.form, obj=user)
    elif g.queue.setting(name='require_login').enabled:
        return render_queue('confirm.html',
            title='Login Required',
            message='Login to add an inquiry, and start using this queue.')
    n = int(g.queue.setting(name='max_requests').value)
    filter_id = User.email == current_user().email if \
        current_user().is_authenticated else User.name == request.form.get('name', None)
    not_logged_in_max = ''
    if Inquiry.query.join(User).filter(
        filter_id,
        Inquiry.status=='unresolved',
        Inquiry.queue_id==g.queue.id
        ).count() >= n:
        if not current_user().is_authenticated:
            not_logged_in_max = 'If you haven\'t submitted a request, try logging in and re-requesting.'
        return render_queue('confirm.html',
            title='Oops',
            message='Looks like you\'ve reached the maximum number of times you can add yourself to the queue at once (<code>%d</code>). %s' % (n, not_logged_in_max or 'Would you like to cancel your oldest request?'),
            action='Cancel Oldest Request',
            url=url_for('queue.cancel'))
    form.location.choices = choicify(
        g.queue.setting('locations').value.split(','))
    form.category.choices = choicify(
        g.queue.setting('inquiry_types').value.split(','))
    if request.method == 'POST' and form.validate() and \
        g.queue.is_valid_assignment(request, form):
        inquiry = Inquiry(**request.form)
        inquiry.queue_id = g.queue.id
        if current_user().is_authenticated:
            inquiry.owner_id = current_user().id
        inquiry.save()
        emitQueueInfo(g.queue)
        return redirect(url_for('queue.waiting', inquiry_id=inquiry.id))
    return render_queue('form.html', form=form, title='Request Help',
        submit='Request Help')
Beispiel #9
0
def help_latest(location: str=None, category: str=None) -> str:
    """Automatically select next inquiry."""
    if g.queue.show_inquiry_types() and not category:
        categories = Inquiry.get_categories_unresolved(location=location)
        if len(categories) > 1:
            return render_admin(
                'categories.html',
                title='Request Type',
                location=location,
                categories=categories)
    inquiry = Inquiry.get_current_or_latest(
        location=location,
        category=category)
    Inquiry.maybe_unlock_delayed()
    if not inquiry:
        return redirect(url_for('admin.home', notification=NOTIF_HELP_DONE))
    inquiry.lock().link(current_user())
    return redirect(url_for(
        'admin.help_inquiry',
        id=inquiry.id,
        location=location))
Beispiel #10
0
def get_inquiry_for_asker(inquiry_id: int) -> Inquiry:
    """Fetch the current inquiry for the asker."""
    if inquiry_id:
        return Inquiry.query.get(inquiry_id)
    else:
        return Inquiry.get_current_asking()
Beispiel #11
0
def resolved() -> str:
    """List all 'resolved' inquiries."""
    return render_admin(
        'resolved.html',
        inquiries=Inquiry.get_inquiries(status='resolved', limit=20))