Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Fixing time restriction #221

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions migrations/versions/7c34b3fcb2c8_add_restrict_by_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add restrict_by_time

Revision ID: 7c34b3fcb2c8
Revises: 4c81c3744bc4
Create Date: 2020-07-22 19:35:15.597100

"""

# revision identifiers, used by Alembic.
revision = '7c34b3fcb2c8'
down_revision = '4c81c3744bc4'

from alembic import op
import sqlalchemy as sa
import oh_queue.models
from oh_queue.models import *


def upgrade():

# Get alembic DB bind
connection = op.get_bind()
session = orm.Session(bind=connection)

for course in session.query(ConfigEntry.course).distinct():
session.add(ConfigEntry(key='restrict_by_time', value='false', public=True, course=course[0]))

session.commit()


def downgrade():
pass
5 changes: 4 additions & 1 deletion oh_queue/static/js/components/admin_appointments_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ function AdminAppointmentsManager({ state }) {
<tr>
<td>
<p>
How many appointments should a student have be pending simultaneously?
How many appointments should a student have be pending simultaneously?
</p>
(by
<ConfigLinkedToggle config={state.config} configKey="restrict_by_time" onText="minutes" offText="number"/>
)
</td>
<td className="col-md-3">
<ConfigLinkedNumeric
Expand Down
4 changes: 3 additions & 1 deletion oh_queue/static/js/components/future_slots.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function FutureSlots({ state }) {
{" "}
{state.config.simul_appointment_limit}
{" "}
appointments that have not yet occurred.
{(state.config.restrict_by_time != "false") ? "minutes of appointments" : "appointments"}
{" "}
that have not yet occurred.
</h5>
</div>
{(!currentUser || currentUser.isStaff) && <AppointmentButtons />}
Expand Down
25 changes: 20 additions & 5 deletions oh_queue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def init_config():
))
db.session.add(ConfigEntry(
key='appointments_open',
value='false',
value='true',
public=True,
course=get_course(),
))
Expand Down Expand Up @@ -319,6 +319,12 @@ def init_config():
public=True,
course=get_course(),
))
db.session.add(ConfigEntry(
key='restrict_by_time',
value='false',
public=True,
course=get_course(),
))
db.session.add(ConfigEntry(
key='show_okpy_backups',
value='false',
Expand Down Expand Up @@ -922,6 +928,7 @@ def assign_appointment(data):
daily_threshold = int(ConfigEntry.query.filter_by(key="daily_appointment_limit", course=get_course()).one().value)
weekly_threshold = int(ConfigEntry.query.filter_by(key="weekly_appointment_limit", course=get_course()).one().value)
pending_threshold = int(ConfigEntry.query.filter_by(key="simul_appointment_limit", course=get_course()).one().value)
pending_metric= ConfigEntry.query.filter_by(key="restrict_by_time", course=get_course()).one().value

start = appointment.start_time.replace(hour=0, minute=0, second=0, microsecond=0)
week_start = start - datetime.timedelta(days=appointment.start_time.weekday())
Expand All @@ -940,13 +947,21 @@ def assign_appointment(data):
).count()
if num_today >= daily_threshold:
return socket_error("You have already signed up for {} OH slots for the same day".format(daily_threshold))

num_pending = AppointmentSignup.query.join(AppointmentSignup.appointment).filter(
Appointment.status == AppointmentStatus.pending,
AppointmentSignup.user_id == current_user.id,
).count()
if num_pending >= pending_threshold:
return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))
)
if pending_metric != 'false':
start = appointment.duration
num_pend = [appt.appointment.duration for appt in list(num_pending)]
threshold = datetime.timedelta(minutes=pending_threshold)
for item in num_pend:
start += item
if start > threshold:
return socket_error("You cannot sign up for more than {} minutes of OH that have not yet occurred.".format(pending_threshold))
else:
if num_pending.count() >= pending_threshold:
return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))

old_signup = AppointmentSignup.query.filter_by(
appointment_id=data["appointment_id"],
Expand Down