Skip to content

Commit

Permalink
Merge pull request #375 from cs50/update/prompts
Browse files Browse the repository at this point in the history
Update submission prompt for CS50x course
  • Loading branch information
rongxin-liu authored Dec 30, 2024
2 parents 8ef8276 + 368aa26 commit f9707d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
description="This is submit50, with which you can submit solutions to problems for CS50.",
long_description="This is submit50, with which you can submit solutions to problems for CS50.",
install_requires=["lib50>=3,<4", "packaging", "requests>=2.19", "setuptools", "termcolor>=1.1"],
install_requires=["lib50>=3,<4", "packaging", "pytz", "requests>=2.19", "setuptools", "termcolor>=1.1"],
keywords=["submit", "submit50"],
name="submit50",
python_requires=">=3.6",
Expand All @@ -26,6 +26,6 @@
entry_points={
"console_scripts": ["submit50=submit50.__main__:main"]
},
version="3.1.5",
version="3.2.0",
include_package_data=True
)
27 changes: 25 additions & 2 deletions submit50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from importlib.resources import files
from packaging import version
from datetime import datetime
from pytz import timezone
from . import __version__, CONFIG_LOADER

# Internationalization
Expand Down Expand Up @@ -137,7 +139,7 @@ def prompt(honesty, included, excluded):
# Show default message
if honesty == True:
honesty_question = _(
"Keeping in mind the course's policy on academic honesty, "
"Keeping in mind the course's policy on academic honesty, including its restrictions on AI use, "
"are you sure you want to submit these files (yes/no)? "
)
# If a custom message is configured, show that instead
Expand All @@ -162,6 +164,26 @@ def prompt(honesty, included, excluded):
return True


def check_slug_year(slug):
"""Warn if the slug is for previous year's CS50x course."""

# extract the year from the slug
try:
year = re.search(r"cs50/problems/(\d{4})/x", slug)
if year and int(year.group(1)) < int(datetime.now(timezone("US/Eastern")).year):
suggested_slug = re.sub(r"cs50/problems/\d{4}/x", f"cs50/problems/{datetime.now(timezone('US/Eastern')).year}/x", slug)
cprint(_("You are submitting to a previous year's CS50x course. Your submission will not be counted towards this year's course."), "yellow")
cprint(_("If you are looking to submit to this year's course, please use the following slug:"), "yellow")
cprint(suggested_slug, "yellow")

# Ask if they want to continue
if not re.match(f"^\s*(?:{_('y|yes')})\s*$", input(_("Do you want to continue with this submission (yes/no)? ")), re.I):
raise Error(_("User aborted submission."))

except ValueError:
pass


def excepthook(type, value, tb):
"""Report an exception."""
if (issubclass(type, Error) or issubclass(type, lib50.Error)) and str(value):
Expand Down Expand Up @@ -223,7 +245,8 @@ def main():

check_announcements()
check_version()

check_slug_year(args.slug)

user_name, commit_hash, message = lib50.push("submit50", args.slug, CONFIG_LOADER, prompt=prompt)
print(message)

Expand Down
8 changes: 4 additions & 4 deletions submit50/locale/es/LC_MESSAGES/submit50.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ msgid "Sorry, something's wrong! Let [email protected] know!"
msgstr "¡Lo siento, algo está mal! ¡Déjale saber a [email protected]!"

msgid ""
"Keeping in mind the course's policy on academic honesty, are you sure you "
"want to submit these files (yes/no)? "
"Keeping in mind the course's policy on academic honesty, including its restrictions on AI use, "
"are you sure you want to submit these files (yes/no)? "
msgstr ""
"Teniendo en cuenta la política de honestidad académica del curso, ¿estás "
"seguro que quieres enviar estos archivos (sí/no)? "
"Teniendo en cuenta la política de honestidad académica del curso, incluidas sus restricciones sobre el uso de IA, "
"¿estás seguro que quieres enviar estos archivos (sí/no)? "

msgid "y|yes"
msgstr "s|s[ií]"
Expand Down

1 comment on commit f9707d4

@22119795
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

submit50 cs50/problems/2025/x/caesar

Please sign in to comment.