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

Develop #864

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
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ select = B,C,E,F,W,T4,B9,Q0,N8,VNE
exclude =
**migrations
venv
.venv
tests
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
.env
.DS_Store
venv/
.venv/
.pytest_cache/
**__pycache__/
*.pyc
88 changes: 55 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,62 @@
# Taxi service authentication
# Taxi service home page

Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before starting.
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start
- Use the following command to load prepared data from fixture to test and debug your code:
`python manage.py loaddata taxi_service_db_data.json`.
- After loading data from fixture you can use following superuser (or create another one by yourself):
- Login: `admin.user`
- Password: `1qazcde3`
- Make sure that you change the settings for [html-files](https://github.com/mate-academy/py-task-guideline/blob/main/html_settings/README.MD).

Feel free to add more data using admin panel, if needed.

In this task, you will implement a visit counter, login/logout functionality, and make your site available only
authenticated users.

1. Implement a visit counter on the home screen (use the `num_visits` variable name). It should show how many times a user visited the home page before.

2. Create login/logout screens. Provide authentication to your project using built-in Django authentication.

3. Display the username on the top of the sidebar and login/logout button depending on if the user is authenticated.
If the driver clicks on username - the corresponding Driver detail page must open.
```python manage.py loaddata taxi_service_db_data.json```.

4. Protect all your views from unauthenticated users.

5. In Driver's list view add (Me), if this is a current user:

Example:
```
- Admin User (Me)
- Joyce Byers
- Jim Hopper
```
Feel free to add more data using admin panel, if needed.

NOTE: Attach screenshots of all created or modified pages to pull request. It's important to attach images not links to them. See example:
In this task, you should implement the home page of the site.

1. Inside `taxi_service.urls` add path to the `taxi.urls`. Don't forget to specify `namespace`.
2. Inside `taxi.urls` create a path for the home page. This
page should open when you are accessing `http://127.0.0.1:8000/`. Give this
path the name `index`.
3. Inside `taxi.views` create function `index`. In this function:
- count the number of all drivers with `num_drivers` variable
- count the number of all manufacturers with `num_manufacturers` variable
- count the number of all cars with `num_cars` variable
- return `HttpResponse` with rendered template. Pass received data to this template (don't import `HttpResponse` if you use `render`, this import is unnecessary).

4. Before you create a template you have to create styles for the
template. Create directory `static` next to the directory `taxi`. Inside this
directory create a file with the following path `css/styles.css`. Don't forget to do all necessary steps so that Django can serve these static files.
5. Create directory `templates` next to the directory `taxi`. There you will
store templates for pages. Edit settings so that engine knows where to look for template source files.
6. Inside directory `templates` create template `base.html`, it is a parent
template, other templates will extend `base.html`. Inside `base.html`:
- Inside `<head>`:
- Create block `title` with `Taxi Service` title inside
- Load static and import `styles.css`
- Inside `<body>`:
- Create block `sidebar`
- Create block `content`
7. Inside `templates` create a directory `taxi`. There you will store templates
for the app `taxi`. Create `index.html` there. Inside `index.html`:
- Override block `content` and place (as a list) information about:
- Number of cars
- Number of drivers
- Number of manufacturers
8. Inside `templates` create a directory `includes`. There you will store includes.
Create `sidebar.html` there. Inside `sidebar.html`:
- Write realization of `sidebar` include that must have a list of empty links:
- Home page
- Manufacturers
- Cars
- Drivers
- Anchor tags can serve as placeholder links for this task, meaning the actual destination of the link is not a concern.
For example, you can use `href="#"` as the link destination.

- In `base.html` include `sidebar.html`, so all these links will be accessible on all pages.
9. Check that you put empty lines at the end of each HTML file.
10. Run server, open `http://127.0.0.1:8000/`, check if the information is there and if it is correct.
11. Run `python manage.py test` to check your code results.
12. Avoid adding unnecessary files (like `venv`, `pycache`, `.idea`, `db.sqlite3`) and remember to include a `.gitignore` file in your PR.

### Note: Attach screenshots of all created or modified pages to pull request.

1) Attach screenshots to the comment, NOT in commit.
2) It's important to **attach images** not links to them. See example:

![image](https://mate-academy-images.s3.eu-central-1.amazonaws.com/python_pr_with_images.png)

**Note:** we use the `-` hyphen in URLs names in our Django course, whilst we use the `_` underscore in our DRF course.

### Note: Check your code using this [checklist](checklist.md) before pushing your solution.
58 changes: 26 additions & 32 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
# Сheck Your Code Against the Following Points
# Check Your Code Against the Following Points

## Don't Push db files
## Code Style

Make sure you don't push db files (files with `.sqlite`, `.db3`, etc. extension).
1. Ensure each file ends with a single blank line.

## Don't forget to attach all screenshots of created/modified pages.
2. Add a blank line between different groups of imports and ensure appropriate ordering of imports.

Imports should be grouped in the following order:

## Code Efficiency
1. Make sure you've added a blank line at the end to all your files including `.css`, `.html` and `.gitignore`.
2. Use `pluralize`.
1.Standard library imports.
2.Related third party imports.
3.Local application/library specific imports.

Good example:
Good example

```python
from django.urls import path

```html
<p>You have visited this page {{ num_visits }} time{{ num_visits|pluralize }}</p>
from taxi.views import index
```

Bad example:

```html
<p>You have visited this page {{ num_visits }} {% if num_visits == 1 %} time {% else %} times {% endif %}.</p>
```python
from django.urls import path
from taxi.views import index
```

3. Make sure that `num_visits` works as expected.
When you visit the page for the first time there should be: `You have visited this page 1 time`

4. Make sure you use 2 whitespaces indentations in your `.html` files.

## Code style

Use `-` to split words in URL identification parameter `name`, not the `_`.

3. Use absolute imports instead of relative imports

Good example:


```python
urlpatterns = [
path("buses/", BusListView.as_view(), name="bus-list"),
]
```
from taxi.views import index
```

Bad example:

```python
urlpatterns = [
path("buses/", BusListView.as_view(), name="bus_list"),
]
```

from .views import index
```
## 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.

1. Don't forget to delete comments when you are ready to commit and push your code.
44 changes: 20 additions & 24 deletions taxi/admin.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import Driver, Car, Manufacturer

from taxi.models import Manufacturer, Car, Driver


@admin.register(Car)
class CarAdmin(admin.ModelAdmin):
list_display = ["model", "manufacturer"]
search_fields = ["model"]
list_filter = ["manufacturer"]
ordering = ["manufacturer"]


@admin.register(Manufacturer)
class ManufacturerAdmin(admin.ModelAdmin):
list_display = ["name", "country"]
ordering = ["name"]


@admin.register(Driver)
class DriverAdmin(UserAdmin):
class DriverAdmin(admin.ModelAdmin):
ordering = ["first_name", "last_name"]
list_display = UserAdmin.list_display + ("license_number",)
fieldsets = UserAdmin.fieldsets + (
(("Additional info", {"fields": ("license_number",)}),)
("Additional info", {"fields": ("license_number",)}),
)
add_fieldsets = UserAdmin.add_fieldsets + (
(
(
"Additional info",
{
"fields": (
"first_name",
"last_name",
"license_number",
)
},
),
)
("Additional info", {"fields": ("license_number",)}),
)


@admin.register(Car)
class CarAdmin(admin.ModelAdmin):
search_fields = ("model",)
list_filter = ("manufacturer",)


admin.site.register(Manufacturer)
Loading
Loading