From b86b021a0dc7b0520cfa20b7e3b9e3538e8731f7 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Sun, 2 Oct 2022 17:12:48 -0400 Subject: [PATCH] Rename description->type field, raise max_length --- poetry.lock | 14 ++++---- program/models.py | 81 ++++++++++++----------------------------------- 2 files changed, 27 insertions(+), 68 deletions(-) diff --git a/poetry.lock b/poetry.lock index 711ab38b..706ccad9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -568,7 +568,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "pytz" -version = "2022.2.1" +version = "2022.4" description = "World timezone definitions, modern and historical" category = "main" optional = false @@ -602,14 +602,14 @@ use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "setuptools" -version = "65.4.0" +version = "65.4.1" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "main" optional = false python-versions = ">=3.7" [package.extras] -docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mock", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] @@ -1065,8 +1065,8 @@ python-magic = [ {file = "python_magic-0.4.27-py2.py3-none-any.whl", hash = "sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3"}, ] pytz = [ - {file = "pytz-2022.2.1-py2.py3-none-any.whl", hash = "sha256:220f481bdafa09c3955dfbdddb7b57780e9a94f5127e35456a48589b9e0c0197"}, - {file = "pytz-2022.2.1.tar.gz", hash = "sha256:cea221417204f2d1a2aa03ddae3e867921971d0d76f14d87abb4414415bbdcf5"}, + {file = "pytz-2022.4-py2.py3-none-any.whl", hash = "sha256:2c0784747071402c6e99f0bafdb7da0fa22645f06554c7ae06bf6358897e9c91"}, + {file = "pytz-2022.4.tar.gz", hash = "sha256:48ce799d83b6f8aab2020e369b627446696619e79645419610b9facd909b3174"}, ] PyYAML = [ {file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"}, @@ -1115,8 +1115,8 @@ requests = [ {file = "requests-2.28.1.tar.gz", hash = "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983"}, ] setuptools = [ - {file = "setuptools-65.4.0-py3-none-any.whl", hash = "sha256:c2d2709550f15aab6c9110196ea312f468f41cd546bceb24127a1be6fdcaeeb1"}, - {file = "setuptools-65.4.0.tar.gz", hash = "sha256:a8f6e213b4b0661f590ccf40de95d28a177cd747d098624ad3f69c40287297e9"}, + {file = "setuptools-65.4.1-py3-none-any.whl", hash = "sha256:1b6bdc6161661409c5f21508763dc63ab20a9ac2f8ba20029aaaa7fdb9118012"}, + {file = "setuptools-65.4.1.tar.gz", hash = "sha256:3050e338e5871e70c72983072fe34f6032ae1cdeeeb67338199c2f74e083a80e"}, ] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, diff --git a/program/models.py b/program/models.py index d6fada87..565b6c8c 100644 --- a/program/models.py +++ b/program/models.py @@ -189,7 +189,7 @@ class Host(ModelWithImageFields, ModelWithCreatedUpdatedFields): class Link(models.Model): - description = models.CharField(max_length=16) + type = models.CharField(max_length=32) url = models.URLField() class Meta: @@ -352,21 +352,13 @@ class Schedule(models.Model): int(sdl["default_playlist_id"]) if sdl.get("default_playlist_id") else None ) add_days_no = int(sdl["add_days_no"]) if sdl.get("add_days_no") else None - add_business_days_only = ( - True if sdl.get("add_business_days_only") is True else False - ) + add_business_days_only = True if sdl.get("add_business_days_only") is True else False first_date = parse_date(str(sdl["first_date"])) start_time = ( - sdl["start_time"] + ":00" - if len(str(sdl["start_time"])) == 5 - else sdl["start_time"] - ) - end_time = ( - sdl["end_time"] + ":00" - if len(str(sdl["end_time"])) == 5 - else sdl["end_time"] + sdl["start_time"] + ":00" if len(str(sdl["start_time"])) == 5 else sdl["start_time"] ) + end_time = sdl["end_time"] + ":00" if len(str(sdl["end_time"])) == 5 else sdl["end_time"] start_time = parse_time(str(start_time)) end_time = parse_time(str(end_time)) @@ -379,9 +371,7 @@ class Schedule(models.Model): year = timezone.now().year last_date = parse_date(f"{year}-12-31") else: - last_date = first_date + timedelta( - days=+AUTO_SET_LAST_DATE_TO_DAYS_IN_FUTURE - ) + last_date = first_date + timedelta(days=+AUTO_SET_LAST_DATE_TO_DAYS_IN_FUTURE) schedule = Schedule( pk=pk, @@ -433,9 +423,7 @@ class Schedule(models.Model): elif schedule.rrule.freq == 3 and schedule.rrule.pk == 2: # Daily timeslots by_weekday_start = (0, 1, 2, 3, 4, 5, 6) by_weekday_end = (0, 1, 2, 3, 4, 5, 6) - elif ( - schedule.rrule.freq == 3 and schedule.rrule.pk == 3 - ): # Business days MO - FR/SA + elif schedule.rrule.freq == 3 and schedule.rrule.pk == 3: # Business days MO - FR/SA by_weekday_start = (0, 1, 2, 3, 4) if schedule.end_time < schedule.start_time: # End days for over midnight @@ -496,9 +484,7 @@ class Schedule(models.Model): # produces wrong end dates if the 1st Tuesday is before the 1st Monday # In this case we take the next day instead of rrule's calculated end if starts[k] > ends[k]: - ends[k] = datetime.combine( - starts[k] + relativedelta(days=+1), schedule.end_time - ) + ends[k] = datetime.combine(starts[k] + relativedelta(days=+1), schedule.end_time) """ Add a number of days to the generated dates? @@ -567,9 +553,7 @@ class Schedule(models.Model): collision = TimeSlot.objects.get_colliding_timeslots(ts) if collision: - collisions.append( - collision[0] - ) # TODO: Do we really always retrieve one? + collisions.append(collision[0]) # TODO: Do we really always retrieve one? else: collisions.append(None) @@ -597,9 +581,7 @@ class Schedule(models.Model): solution_choices = set() # Get collisions for each timeslot - collision_list = list( - TimeSlot.objects.get_colliding_timeslots(ts).order_by("start") - ) + collision_list = list(TimeSlot.objects.get_colliding_timeslots(ts).order_by("start")) # Add the projected timeslot projected_entry = { @@ -784,9 +766,7 @@ class Schedule(models.Model): code="no-start-after-end", ) - num_conflicts = len( - [pr for pr in conflicts["projected"] if len(pr["collisions"]) > 0] - ) + num_conflicts = len([pr for pr in conflicts["projected"] if len(pr["collisions"]) > 0]) if len(solutions) != num_conflicts: raise ScheduleConflictError( @@ -813,9 +793,7 @@ class Schedule(models.Model): # - Create the projected timeslot and skip # if "solution_choices" not in ts or len(ts["collisions"]) < 1: - projected_ts = TimeSlot.objects.instantiate( - ts["start"], ts["end"], schedule, show - ) + projected_ts = TimeSlot.objects.instantiate(ts["start"], ts["end"], schedule, show) create.append(projected_ts) continue @@ -837,9 +815,7 @@ class Schedule(models.Model): # - Skip # if not solutions[ts["hash"]] in ts["solution_choices"]: - errors[ts["hash"]] = _( - "Given solution is not accepted for this conflict." - ) + errors[ts["hash"]] = _("Given solution is not accepted for this conflict.") continue """Conflict resolution""" @@ -861,9 +837,7 @@ class Schedule(models.Model): # - Delete the existing collision(s) # if solution == "ours": - projected_ts = TimeSlot.objects.instantiate( - ts["start"], ts["end"], schedule, show - ) + projected_ts = TimeSlot.objects.instantiate(ts["start"], ts["end"], schedule, show) create.append(projected_ts) # Delete collision(s) @@ -891,9 +865,7 @@ class Schedule(models.Model): # - Change the start of the existing collision to projected end # if solution == "ours-end": - projected_ts = TimeSlot.objects.instantiate( - ts["start"], ts["end"], schedule, show - ) + projected_ts = TimeSlot.objects.instantiate(ts["start"], ts["end"], schedule, show) create.append(projected_ts) existing_ts = TimeSlot.objects.get(pk=existing["id"]) @@ -917,9 +889,7 @@ class Schedule(models.Model): # - Change end of existing to projected start # if solution == "ours-start": - projected_ts = TimeSlot.objects.instantiate( - ts["start"], ts["end"], schedule, show - ) + projected_ts = TimeSlot.objects.instantiate(ts["start"], ts["end"], schedule, show) create.append(projected_ts) existing_ts = TimeSlot.objects.get(pk=existing["id"]) @@ -951,9 +921,7 @@ class Schedule(models.Model): # - Create another one with start = projected end and end = existing end # if solution == "ours-both": - projected_ts = TimeSlot.objects.instantiate( - ts["start"], ts["end"], schedule, show - ) + projected_ts = TimeSlot.objects.instantiate(ts["start"], ts["end"], schedule, show) create.append(projected_ts) existing_ts = TimeSlot.objects.get(pk=existing["id"]) @@ -968,9 +936,7 @@ class Schedule(models.Model): # If there were any errors, don't make any db changes yet # but add error messages and return already chosen solutions if len(errors) > 0: - conflicts = Schedule.make_conflicts( - model_to_dict(schedule), schedule.pk, show.pk - ) + conflicts = Schedule.make_conflicts(model_to_dict(schedule), schedule.pk, show.pk) partly_resolved = conflicts["projected"] saved_solutions = {} @@ -982,10 +948,7 @@ class Schedule(models.Model): if len(c["collisions"]) > 0: saved_solutions[c["hash"]] = "" - if ( - c["hash"] in solutions - and solutions[c["hash"]] in c["solution_choices"] - ): + if c["hash"] in solutions and solutions[c["hash"]] in c["solution_choices"]: saved_solutions[c["hash"]] = solutions[c["hash"]] if c["hash"] in errors: @@ -1004,9 +967,7 @@ class Schedule(models.Model): ) # Collect upcoming timeslots to delete which might still remain - del_timeslots = TimeSlot.objects.filter( - schedule=schedule, start__gt=schedule.last_date - ) + del_timeslots = TimeSlot.objects.filter(schedule=schedule, start__gt=schedule.last_date) for del_ts in del_timeslots: delete.append(del_ts) @@ -1104,9 +1065,7 @@ class TimeSlotManager(models.Manager): class TimeSlot(models.Model): - schedule = models.ForeignKey( - Schedule, on_delete=models.CASCADE, related_name="timeslots" - ) + schedule = models.ForeignKey(Schedule, on_delete=models.CASCADE, related_name="timeslots") show = models.ForeignKey( Show, editable=False, on_delete=models.CASCADE, related_name="timeslots" ) -- GitLab