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 #1 #377

Closed
wants to merge 3 commits into from
Closed

Solution #1 #377

wants to merge 3 commits into from

Conversation

erikagayan
Copy link

No description provided.

db/models.py Outdated
]

def clean(self) -> None:
if not self.row <= self.movie_session.cinema_hall.rows:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will be ok if you used PositiveIntegerField. You can receive self.row -3, for example, and it will be no error.

db/models.py Outdated
}
)

if not self.seat <= self.movie_session.cinema_hall.seats_in_row:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same here

row=ticket["row"],
seat=ticket["seat"]
)
order.save()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made save() in if check. If you don't change anything after creation no need to use save() more.

services/user.py Outdated
email=email,
first_name=first_name,
last_name=last_name
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to create user with optional fields (email, first_name, last_name) just in that case if they were provided.

row=ticket["row"],
seat=ticket["seat"]
)
order.save()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I explained not the best way. I meant you had already save() in if check, so you don't need additional one after the remaining part of your code. You need to make save() just in if check like below:
if date:
order.created_at = date
order.save()

services/user.py Outdated
last_name: str = ""
email: str = None,
first_name: str = None,
last_name: str = None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace emal, first_name, last_name with **kwargs. Then you need to create some list/tuple with "email", "first_name", "last_name", and create your object 'User' by username and password. Then you need to unpack your kwargs and iterate one by one, checking if such key exist in your kwargs.items() and checking if value of this key is not "" or None. In this case after your check you can use setattr() to add this value to your 'User' object

services/user.py Outdated
user.first_name = first_name

if last_name:
user.last_name = last_name

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And make the same here. update_user(user_id: int, password: str, **kwargs)

Comment on lines 48 to 49
return list(Ticket.objects.filter(
movie_session_id=movie_session_id).values("row", "seat"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad formmating here

Comment on lines 7 to 10
def create_order(
tickets: list[dict],
username: str,
date: str = None) -> Order:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

services/user.py Outdated
Comment on lines 12 to 24
user_data = {
"username": username,
"password": password,
}

if email:
user_data["email"] = email

if first_name:
user_data["first_name"] = first_name

if last_name:
user_data["last_name"] = last_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to optimize this

Copy link

@Oleg-s-s Oleg-s-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@erikagayan erikagayan closed this by deleting the head repository Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants