Rewrite some API on Event and ExtraLesson #433

Merged
hansegucker merged 4 commits from feature/restructure-event-extra-lesson-api into master 2021-02-21 19:45:41 +01:00
Owner
No description provided.
Author
Owner

mentioned in merge request AlekSIS-App-Alsijil!424

mentioned in merge request AlekSIS-App-Alsijil!424
Owner

There is no linked issue and no description, and the commit message says absolutely nothing.

Why should the code be changed? Assuming you did not just change it for fun because you wanted to change some code, please describe what the intention is, at least in the commit message, and, ideally, also in the MR.

There is no linked issue and no description, and the commit message says absolutely nothing. Why should the code be changed? Assuming you did not just change it for fun because you wanted to change some code, please describe what the intention is, at least in the commit message, and, ideally, also in the MR.
Owner

Looking at the code, it seems your commit also mixes a bugfix and a new feature. Please separate these.

Looking at the code, it seems your commit also mixes a bugfix and a new feature. Please separate these.
Owner

Annotations are done in the QuerySet using the annotate method. While adding arbitrary attributes to Model instances technically works, it will some day hit back when we think it is a real annotation (i.e. one the ORM is aware of) but it is a pure Python attribute.

Annotations are done in the `QuerySet` using the `annotate` method. While adding arbitrary attributes to `Model` instances technically works, it will some day hit back when we think it is a real annotation (i.e. one the ORM is aware of) but it is a pure Python attribute.
Owner

Firstly, if this method stays where it is, it should be renamed:

    def from_period(cls, period: int, day: date):

Methods starting with the get_ prefix are thought to be getter methods, which return an attribute of the current instance. Factories that generate an instance from another object start with the from_ prefix only.

But this also looks like it belongs into the QuerySet or even manager.

Firstly, if this method stays where it is, it should be renamed: ```suggestion:-0+0 def from_period(cls, period: int, day: date): ``` Methods starting with the `get_` prefix are thought to be getter methods, which return an attribute of the current instance. Factories that generate an instance from another object start with the `from_` prefix only. But this also looks like it belongs into the `QuerySet` or even manager.
Owner

This needs proper commetnary.

(Now that this is practically a new method written by you, you have to add a docstring anyway ;).)

This needs proper commetnary. (Now that this is practically a new method written by you, you have to add a docstring anyway ;).)
Owner

See above — annotations are the QuerySet's job.

See above — annotations are the `QuerySet`'s job.
Owner

Wat are these getters good for? They simply return a raw attribute…

Wat are these getters good for? They simply return a raw attribute…
Owner

Wat are these getters good for? They simply return a raw attribute…

Wat are these getters good for? They simply return a raw attribute…
Owner

Now I went through it until the end, it looks like the commit history should have even more logical steps.

Now I went through it until the end, it looks like the commit history should have even more logical steps.
Author
Owner

marked this merge request as draft

marked this merge request as **draft**
Author
Owner

Oh, sorry, of course this is actually still a draft. I missed to add "Draft:" in the title. All necessary information will follow.

Oh, sorry, of course this is actually still a draft. I missed to add "Draft:" in the title. All necessary information will follow.
Author
Owner

added 2 commits

  • 3d1e3660 - Unify API methods of LessonPeriod, Event and ExtraLesson
  • aec87faa - Add some API methods to access dates and periods for events and extra lessons better

Compare with previous version

added 2 commits <ul><li>3d1e3660 - Unify API methods of LessonPeriod, Event and ExtraLesson</li><li>aec87faa - Add some API methods to access dates and periods for events and extra lessons better</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-App-Chronos/-/merge_requests/129/diffs?diff_id=4830&start_sha=f9e128fb442a399144d5640fb14106987f1d185c)
Author
Owner

They are necessary in order to have an unified API of getters on LessonPeriod, Event and ExtraLesson.

They are necessary in order to have an unified API of getters on `LessonPeriod`, `Event` and `ExtraLesson`.
Author
Owner

Okay, I will use from_period as classmethod because it doesn't return a queryset but a single TimePeriod.

Okay, I will use `from_period` as classmethod because it doesn't return a queryset but a single `TimePeriod`.
Author
Owner

They are necessary in order to have an unified API of getters on LessonPeriod, Event and ExtraLesson.

They are necessary in order to have an unified API of getters on `LessonPeriod`, `Event` and `ExtraLesson`.
Author
Owner

changed this line in version 3 of the diff

changed this line in [version 3 of the diff](/AlekSIS/official/AlekSIS-App-Chronos/-/merge_requests/129/diffs?diff_id=4831&start_sha=aec87faa8928e45c7c5df56a2bf98e3c274771b5#aff889560e418df674a6887a541974fc95f8cd36_221_221)
Author
Owner

added 1 commit

  • 4fe76e99 - Fix type hints and add missing doc strings for improved API on ExtraLesson/Event/LessonPeriod

Compare with previous version

added 1 commit <ul><li>4fe76e99 - Fix type hints and add missing doc strings for improved API on ExtraLesson/Event/LessonPeriod</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-App-Chronos/-/merge_requests/129/diffs?diff_id=4831&start_sha=aec87faa8928e45c7c5df56a2bf98e3c274771b5)
Author
Owner

added 1 commit

  • 83c085b6 - Rename get_from_period to from_period and add docstring

Compare with previous version

added 1 commit <ul><li>83c085b6 - Rename get_from_period to from_period and add docstring</li></ul> [Compare with previous version](/AlekSIS/official/AlekSIS-App-Chronos/-/merge_requests/129/diffs?diff_id=4832&start_sha=4fe76e9975034d3703c8c5829aadab4f21446892)
Author
Owner

marked this merge request as ready

marked this merge request as **ready**
Owner

We discussed this, and concluded that gettin the week into a model across a foreign key relation through a manager is non-trivial.

We discussed this, and concluded that gettin the week into a model across a foreign key relation through a manager is non-trivial.
Owner

resolved all threads

resolved all threads
nik merged commit abd5712123 into master 2021-02-21 19:45:41 +01:00
Owner

mentioned in commit abd5712123

mentioned in commit abd5712123ae6a9706bbd7082e89c1bbf3823bad
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
aleksis/AlekSIS-App-Chronos!433
No description provided.