-
Notifications
You must be signed in to change notification settings - Fork 722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #757
Open
dxrrkwm
wants to merge
2
commits into
mate-academy:master
Choose a base branch
from
dxrrkwm:dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Solution #757
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[flake8] | ||
inline-quotes = " | ||
ignore = E203, E266, W503, N807, N818, F401, VNE003 | ||
max-line-length = 79 | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9,Q0,N8,VNE | ||
exclude = | ||
**migrations | ||
venv | ||
[flake8] | ||
inline-quotes = " | ||
ignore = E203, E266, W503, N807, N818, F401, VNE003 | ||
max-line-length = 79 | ||
max-complexity = 18 | ||
select = B,C,E,F,W,T4,B9,Q0,N8,VNE | ||
exclude = | ||
**migrations | ||
venv | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set Up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install requirements | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
|
||
- name: Run flake8 | ||
run: flake8 | ||
|
||
- name: Run tests | ||
timeout-minutes: 5 | ||
run: python manage.py test | ||
name: Test | ||
on: | ||
pull_request: | ||
branches: | ||
- "master" | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
- name: Set Up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
- name: Install requirements | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run flake8 | ||
run: flake8 | ||
- name: Run tests | ||
timeout-minutes: 5 | ||
run: python manage.py test | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
.idea/ | ||
.vscode/ | ||
*.iml | ||
.env | ||
.DS_Store | ||
venv/ | ||
.pytest_cache/ | ||
**__pycache__/ | ||
*.pyc | ||
.idea/ | ||
.vscode/ | ||
*.iml | ||
.env | ||
.DS_Store | ||
venv/ | ||
.pytest_cache/ | ||
**__pycache__/ | ||
*.pyc | ||
db.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
# API Views | ||
|
||
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before starting. | ||
|
||
Now, you are going to implement views via class-based views. | ||
|
||
Create `Genre`, `Actor`, `CinemaHall` models and update `Movie` model to | ||
the ones you wrote in Django ORM module. Modules should have such fields: | ||
- `Actor`: `first_name`, `last_name` | ||
- `Genre`: `name` (note: must be unique) | ||
- `CinemaHall`: `name`, `rows`, `seats_in_row` | ||
- `Movie`: `title`, `description`, `actors`, `genres`, `duration`. (note: you | ||
already have a new field here) | ||
|
||
Create serializers for all these models. Do not use related serializers for | ||
ManyToMany relations. | ||
|
||
Use the following command to load prepared data from fixture to test and debug your code: | ||
`python manage.py loaddata cinema_serviсe_db_data.json`. | ||
|
||
Create views for models interaction endpoints via different class-based views: | ||
- For the `Genre` model use an `APIView` | ||
- For the `Actor` model use a `GenericAPIView` | ||
- For the `CinemaHall` model use a `GenericViewSet` | ||
- For the `Movie` model use a `ModelViewSet` and `routers` | ||
|
||
Feel free to add more data using admin panel, if needed. | ||
|
||
For every `<entity>` from `actors`, `genres`, `cinema_halls`, `movies`, such | ||
endpoints should work: | ||
* `GET api/cinema/<entity>/` - should return a list of the all entity items | ||
* `POST api/cinema/<entity>/` - should create a new entity based on passed data | ||
* `GET api/cinema/<entity>/<pk>/` - should return an entity with given id | ||
* `PUT api/cinema/<entity>/<pk>/` - should update the entity with given id based on passed data | ||
* `PATCH api/cinema/<entity>/<pk>/` - should partially update the entity with given id based on passed data | ||
* `DELETE api/cinema/<entity>/<pk>/` - should delete the entity with given id | ||
|
||
### Note: Check your code using this [checklist](checklist.md) before pushing your solution. | ||
# API Views | ||
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before starting. | ||
Now, you are going to implement views via class-based views. | ||
Create `Genre`, `Actor`, `CinemaHall` models and update `Movie` model to | ||
the ones you wrote in Django ORM module. Modules should have such fields: | ||
- `Actor`: `first_name`, `last_name` | ||
- `Genre`: `name` (note: must be unique) | ||
- `CinemaHall`: `name`, `rows`, `seats_in_row` | ||
- `Movie`: `title`, `description`, `actors`, `genres`, `duration`. (note: you | ||
already have a new field here) | ||
Create serializers for all these models. Do not use related serializers for | ||
ManyToMany relations. | ||
Use the following command to load prepared data from fixture to test and debug your code: | ||
`python manage.py loaddata cinema_serviсe_db_data.json`. | ||
Create views for models interaction endpoints via different class-based views: | ||
- For the `Genre` model use an `APIView` | ||
- For the `Actor` model use a `GenericAPIView` | ||
- For the `CinemaHall` model use a `GenericViewSet` | ||
- For the `Movie` model use a `ModelViewSet` and `routers` | ||
Feel free to add more data using admin panel, if needed. | ||
For every `<entity>` from `actors`, `genres`, `cinema_halls`, `movies`, such | ||
endpoints should work: | ||
* `GET api/cinema/<entity>/` - should return a list of the all entity items | ||
* `POST api/cinema/<entity>/` - should create a new entity based on passed data | ||
* `GET api/cinema/<entity>/<pk>/` - should return an entity with given id | ||
* `PUT api/cinema/<entity>/<pk>/` - should update the entity with given id based on passed data | ||
* `PATCH api/cinema/<entity>/<pk>/` - should partially update the entity with given id based on passed data | ||
* `DELETE api/cinema/<entity>/<pk>/` - should delete the entity with given id | ||
### Note: Check your code using this [checklist](checklist.md) before pushing your solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,87 @@ | ||
# Check Your Code Against the Following Points | ||
|
||
## Code Style | ||
|
||
1. Don't forget define the `related_name` for `ManyToManyField`. | ||
|
||
2. Don't forget return `Response` with `errors` if serializer is not valid: | ||
|
||
Good example: | ||
|
||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
``` | ||
|
||
Another good example: | ||
|
||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
``` | ||
|
||
Bad example: | ||
|
||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
``` | ||
|
||
Another bad example: | ||
|
||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST) | ||
``` | ||
|
||
3. Group imports using `()` if needed. | ||
|
||
Good example: | ||
|
||
```python | ||
from django.contrib.auth.mixins import ( | ||
LoginRequiredMixin, | ||
UserPassesTestMixin, | ||
PermissionRequiredMixin, | ||
) | ||
``` | ||
|
||
Bad example: | ||
|
||
```python | ||
from django.contrib.auth.mixins import LoginRequiredMixin, \ | ||
UserPassesTestMixin, PermissionRequiredMixin | ||
``` | ||
|
||
Another bad example: | ||
|
||
```python | ||
from django.contrib.auth.mixins import ( | ||
LoginRequiredMixin, | ||
UserPassesTestMixin, PermissionRequiredMixin, | ||
) | ||
``` | ||
|
||
## Clean Code | ||
Add comments, prints, and functions to check your solution when you write your code. | ||
Don't forget to delete them when you are ready to commit and push your code. | ||
# Check Your Code Against the Following Points | ||
## Code Style | ||
1. Don't forget define the `related_name` for `ManyToManyField`. | ||
2. Don't forget return `Response` with `errors` if serializer is not valid: | ||
Good example: | ||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
``` | ||
Another good example: | ||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
serializer.is_valid(raise_exception=True) | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
``` | ||
Bad example: | ||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
``` | ||
Another bad example: | ||
```python | ||
class GenreList(APIView): | ||
def post(self, request): | ||
serializer = GenreSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST) | ||
``` | ||
3. Group imports using `()` if needed. | ||
Good example: | ||
```python | ||
from django.contrib.auth.mixins import ( | ||
LoginRequiredMixin, | ||
UserPassesTestMixin, | ||
PermissionRequiredMixin, | ||
) | ||
``` | ||
Bad example: | ||
```python | ||
from django.contrib.auth.mixins import LoginRequiredMixin, \ | ||
UserPassesTestMixin, PermissionRequiredMixin | ||
``` | ||
Another bad example: | ||
```python | ||
from django.contrib.auth.mixins import ( | ||
LoginRequiredMixin, | ||
UserPassesTestMixin, PermissionRequiredMixin, | ||
) | ||
``` | ||
## Clean Code | ||
Add comments, prints, and functions to check your solution when you write your code. | ||
Don't forget to delete them when you are ready to commit and push your code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
from cinema.models import Movie | ||
|
||
|
||
@admin.register(Movie) | ||
class MovieAdmin(admin.ModelAdmin): | ||
pass | ||
from django.contrib import admin | ||
from cinema.models import Movie | ||
@admin.register(Movie) | ||
class MovieAdmin(admin.ModelAdmin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CinemaConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "cinema" | ||
from django.apps import AppConfig | ||
class CinemaConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "cinema" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
timeout-minutes
setting here might be redundant since the job-level timeout is already set to 10 minutes. Consider removing this line unless you specifically need a shorter timeout for this step.