text stringlengths 0 828 |
|---|
for k, v in kwargs.items(): |
if k not in ctorkwargs or ctorkwargs[k] is None: |
ctorkwargs[k] = v |
view_class.__init__(self, func=f, **ctorkwargs) |
clsdict[""__init__""] = constructor |
return type(f.__name__, (view_class,), clsdict) |
return decorator" |
1506,"def register(self, target): |
""""""Registers url_rules on the blueprint |
"""""" |
for rule, options in self.url_rules: |
target.add_url_rule(rule, self.name, self.dispatch_request, **options)" |
1507,"def view(self, *args, **kwargs): |
""""""Decorator to automatically apply as_view decorator and register it. |
"""""" |
def decorator(f): |
kwargs.setdefault(""view_class"", self.view_class) |
return self.add_view(as_view(*args, **kwargs)(f)) |
return decorator" |
1508,"def add_action_view(self, name, url, actions, **kwargs): |
""""""Creates an ActionsView instance and registers it. |
"""""" |
view = ActionsView(name, url=url, self_var=self, **kwargs) |
if isinstance(actions, dict): |
for group, actions in actions.iteritems(): |
view.actions.extend(load_actions(actions, group=group or None)) |
else: |
view.actions.extend(load_actions(actions)) |
self.add_view(view) |
return view" |
1509,"def process(exam_num: int, time: str, date: str) -> None: |
""""""Process the exams in the exam_num folder for the time."""""" |
prefix = Path(f""exams/exam-{exam_num}"") |
problems = list(prefix.glob(f""exam-{exam_num}-{time}-[0-9].ipynb"")) |
problems = sorted(problems, key=lambda k: k.stem[-1]) |
output_directory = (prefix / ""output"").resolve() |
fw = FilesWriter(build_directory=str(output_directory)) |
assignment_zip_name = output_directory / f""exam-{exam_num}-{time}.zip"" |
solution_zip_name = output_directory / f""exam-{exam_num}-{time}-soln.zip"" |
solution_pdfs: List[BytesIO] = [] |
exam_date_time = datetime.strptime(time + date, ""%H%M%d-%b-%Y"") |
res: Dict[str, Union[str, int]] = { |
""exam_num"": exam_num, |
""time"": exam_date_time.strftime(""%I:%M %p""), |
""date"": exam_date_time.strftime(""%b. %d, %Y""), |
""delete_pymarkdown"": True, |
} |
for problem in problems: |
res[""unique_key""] = problem.stem |
problem_fname = str(problem.resolve()) |
if problem.stem.endswith(""1""): |
assignment_nb, _ = sa_nb_exp.from_filename(problem_fname, resources=res) |
with ZipFile(assignment_zip_name, mode=""a"") as zip_file: |
zip_file.writestr(problem.name, assignment_nb) |
else: |
assignment_nb, _ = prob_nb_exp.from_filename(problem_fname, resources=res) |
with ZipFile(assignment_zip_name, mode=""a"") as zip_file: |
zip_file.writestr(problem.name, assignment_nb) |
solution_pdf, _ = solution_pdf_exp.from_filename(problem_fname, resources=res) |
solution_pdfs.append(BytesIO(solution_pdf)) |
solution_nb, _ = solution_nb_exp.from_filename(problem_fname, resources=res) |
with ZipFile(solution_zip_name, mode=""a"") as zip_file: |
zip_file.writestr(problem.name, solution_nb) |
resources: Dict[str, Any] = { |
""metadata"": { |
""name"": f""exam-{exam_num}-{time}-soln"", |
""path"": str(prefix), |
""modified_date"": datetime.today().strftime(""%B %d, %Y""), |
}, |
""output_extension"": "".pdf"", |
} |
fw.write( |
combine_pdf_as_bytes(solution_pdfs), resources, f""exam-{exam_num}-{time}-soln"" |
)" |
1510,"def main(argv: Optional[Sequence[str]] = None) -> None: |
""""""Parse arguments and process the exam assignment."""""" |
parser = ArgumentParser(description=""Convert Jupyter Notebook exams to PDFs"") |
parser.add_argument( |
""--exam"", |
type=int, |
required=True, |
help=""Exam number to convert"", |
dest=""exam_num"", |
) |
parser.add_argument( |
""--time"", type=str, required=True, help=""Time of exam to convert"" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.