Skip to content

Commit

Permalink
Modify deadline configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaT99 committed Jul 30, 2024
1 parent d2c2707 commit 0d5d6e8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
5 changes: 5 additions & 0 deletions nbgrader/coursedir.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def _db_url_default(self):
)
).tag(config=True)

deadline_file = Unicode(
"deadlines.json",
help="File for storing deadlines"
).tag(config=True)

groupshared = Bool(
False,
help=dedent(
Expand Down
5 changes: 0 additions & 5 deletions nbgrader/exchange/abc/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class Exchange(LoggingConfigurable):
help="Format string for timestamps"
).tag(config=True)

deadline_file = Unicode(
"deadlines.txt",
help="File for storing deadlines"
).tag(config=True)

@validate('timestamp_format')
def _valid_timestamp_format(self, proposal):
try:
Expand Down
2 changes: 1 addition & 1 deletion nbgrader/server_extensions/assignment_list/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def list_released_assignments(self, course_id=None):
authenticator=authenticator,
config=config)
assignments = lister.start()
assignments = DeadlineManager(config, self.log) \
assignments = DeadlineManager(config.Exchange.root, coursedir, self.log) \
.fetch_deadlines(assignments)

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion nbgrader/server_extensions/formgrader/apihandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def put(self, assignment_id):
assignment = {"duedate": duedate}
assignment_id = assignment_id.strip()
self.gradebook.update_or_create_assignment(assignment_id, **assignment)
DeadlineManager(self.api._trait_values["config"], self.log) \
DeadlineManager(self.api.exchange_root, self.coursedir, self.log) \
.update_or_add_deadline(assignment_id, duedate)
sourcedir = os.path.abspath(self.coursedir.format_path(self.coursedir.source_directory, '.', assignment_id))
if not os.path.isdir(sourcedir):
Expand Down
22 changes: 14 additions & 8 deletions nbgrader/server_extensions/helpers/deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@


class DeadlineManager:
def __init__(self, config, logger):
self.config = config
def __init__(self, exchange_root, coursedir, logger):
self.exchange_root = exchange_root
self.coursedir = coursedir
self.log = logger

def fetch_deadlines(self, assignments):
"""Fetch the deadline for the given course id and assignments."""

dir_name = os.path.join(self.config.Exchange.root, self.config.CourseDirectory.course_id)
file_path = os.path.join(dir_name, self.config.Exchange.deadline_file)
if not self.exchange_root: # Non-FS based exchange
return assignments

dir_name = os.path.join(self.exchange_root, self.coursedir.course_id)
file_path = os.path.join(dir_name, self.coursedir.deadline_file)
if not os.path.exists(file_path) or not os.path.isfile(file_path):
self.log.warning("No deadlines file found at {}".format(file_path))
return assignments
Expand All @@ -27,10 +30,13 @@ def fetch_deadlines(self, assignments):

def update_or_add_deadline(self, assignment_id, deadline):
"""Add a deadline in the deadlines file or update it if it exists."""
if not self.exchange_root: # Non-FS based exchange
return

deadline = self._format_deadline(deadline)

dir_name = os.path.join(self.config.Exchange.root, self.config.CourseDirectory.course_id)
file_path = os.path.join(dir_name, self.config.Exchange.deadline_file)
dir_name = os.path.join(self.exchange_root, self.coursedir.course_id)
file_path = os.path.join(dir_name, self.coursedir.deadline_file)
deadlines = self._read_deadlines(file_path)
deadlines[assignment_id] = deadline

Expand All @@ -50,7 +56,7 @@ def _write_deadlines(self, file_path, deadlines):
self.log.error("Invalid data type to write in file: %s", deadlines)
return

access_mode = 0o664 if self.config.CourseDirectory.groupshared else 0o644
access_mode = 0o664 if self.coursedir.groupshared else 0o644
st_mode = os.stat(file_path).st_mode
if st_mode & access_mode != access_mode:
try:
Expand Down

0 comments on commit 0d5d6e8

Please sign in to comment.