Skip to content
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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .flake8
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
64 changes: 32 additions & 32 deletions .github/workflows/test.yml
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

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.

18 changes: 9 additions & 9 deletions .gitignore
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
76 changes: 38 additions & 38 deletions README.md
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.
174 changes: 87 additions & 87 deletions checklist.md
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.
16 changes: 8 additions & 8 deletions cinema/admin.py
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
12 changes: 6 additions & 6 deletions cinema/apps.py
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"
Loading
Loading