-
Notifications
You must be signed in to change notification settings - Fork 52
Feature/exercise #227
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
Open
orontamir
wants to merge
86
commits into
PythonFreeCourse:develop
Choose a base branch
from
orontamir:oron_exercise
base: develop
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
Feature/exercise #227
Changes from 46 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
a557ed9
add exercise to calendar
orontamir b069b84
Merge branch 'develop' into oron_exercise
orontamir ae0f2f2
fix warning
orontamir 8907a4f
fix missing new line
orontamir 4e14436
fix config file
orontamir 5866aa6
Update unit test
orontamir 731c0a9
fix blank line
orontamir 67deec3
fix trailing whitespace
orontamir 16e2e0f
fix PureDreamer issues
orontamir 4186ead
fix unused import
orontamir 96f514d
fix ivarshav's issues
orontamir cb9bc6f
fix unit test
orontamir fe6a45f
Merge branch 'develop' into oron_exercise
orontamir 62e5134
fix Yam Comment
orontamir 6ff8680
Merge branch 'oron_exercise' of https://github.com/orontamir/calendar…
orontamir 83bf989
switch session user
orontamir d069a0b
add space between parameters
orontamir 419138f
add session=session and user=user
orontamir af3d449
Add exercise tag
orontamir 9269c23
Merge branch 'develop' into oron_exercise
orontamir 14af5ae
remove unused import
orontamir bc39b5d
update test
orontamir 6b8b70e
remove test_process_new_event because its show twise
orontamir 1eb57a3
fix TestBotClient test
orontamir 33dc416
fix test_user_registered
orontamir 4aea280
remove new line
orontamir 7801291
fix TestBotClient tests
orontamir 4cb0dbf
Fix Yam Comments
orontamir 5dfbad5
fix build issues
orontamir 135314e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir d4a5816
update date time
orontamir b85bc90
Fix event tests and user_exercise test
orontamir be08a20
fix line too long
orontamir 9b275fc
fix merging
orontamir 4d30d68
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir ec9b90e
fix unused import
orontamir 60a0983
fix remove unused import
orontamir 82ace54
fix test add save to user exercise
orontamir cf5f221
fix import in exercise
orontamir 8d02b1b
fix put two blank line
orontamir 6721204
fix tests in test user exercise
orontamir 03d93b6
fix remove space
orontamir 586212e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 9dd9447
fix Yam Comments
orontamir 72f7fc3
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 239706f
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 866ba66
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 6036409
Fix Yam issues
orontamir ba7d670
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir dfd93e2
fix the issue blank 2 lines
orontamir 5e719d1
fix tests user exercise
orontamir ee7737e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 8e2e13e
add html file
orontamir c5bc680
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 79c4c71
update html files
orontamir b3b4516
update html files
orontamir 06c4c8a
update html files
orontamir 9239a3e
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 26ae6f2
Remove all exercise images
orontamir 98318f6
fix line too long
orontamir 4ed9fc4
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 58f2bb9
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir ed39214
Merge branch 'develop' into oron_exercise
orontamir 3e2549c
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 7ff5475
Merge branch 'oron_exercise' of https://github.com/orontamir/calendar…
orontamir 401e663
fix exception
orontamir 13e07a0
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 41be098
Remove htm file and update to PNG file
orontamir eead190
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir afff575
fix 2 blank lines
orontamir 235acb5
Add pytest.fixture to user exercise
orontamir ad0e25b
Write by myself exercises
orontamir 952f5f4
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 3fff6d8
add exercise to feature
orontamir 5083bcb
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 6447cc0
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 1ecc062
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir e424f6e
add Session import
orontamir b04e125
import datetime
orontamir 8287a7b
fix test user
orontamir fa5b4ee
fix two blank line
orontamir a923103
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 7ad9aa0
add new line
orontamir ec126c3
remove new line
orontamir 5712c63
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
orontamir 6f784b5
update test exercise
orontamir 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from fastapi import APIRouter, Depends, Request | ||
from app.database.models import User | ||
from app.dependencies import get_db, templates | ||
from app.routers.user_exercise import get_user_exercise | ||
from datetime import datetime | ||
from app import config | ||
from sqlalchemy.orm import Session | ||
|
||
router = APIRouter( | ||
prefix="/exercise", | ||
tags=["exercise"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
|
||
@router.get("/") | ||
async def exercise( | ||
request: Request, | ||
session: Session = Depends(get_db), | ||
): | ||
""" | ||
If is active exercise = True | ||
Show user exercise for a specific day if is_active_exercise is ture. | ||
""" | ||
user = session.query(User).filter_by(id=1).first() | ||
if not user: | ||
# create empty default user | ||
user = User( | ||
username='', | ||
password='', | ||
email='' | ||
) | ||
# Get user exercise | ||
user_exercise = get_user_exercise(session, user_id=user.id) | ||
if user_exercise: | ||
# Get exercise day | ||
delta = datetime.now() - user_exercise[0].start_date | ||
# All exercises split to 30 days | ||
day = (delta.days % 30) + 1 | ||
else: | ||
day = 1 | ||
exercise_day = str(config.EXERCISE_FILE.format(num=day)) | ||
return templates.TemplateResponse("exercise.html", { | ||
"request": request, | ||
"user": user, | ||
"exercise": exercise_day | ||
}) |
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from sqlalchemy.exc import SQLAlchemyError | ||
from sqlalchemy.orm import Session | ||
from datetime import datetime | ||
from app.database.models import Base, User, UserExercise | ||
|
||
|
||
def save(session: Session, instance: Base) -> bool: | ||
"""Commits an instance to the db. | ||
source: app.database.models.Base""" | ||
|
||
if issubclass(instance.__class__, Base): | ||
session.add(instance) | ||
session.commit() | ||
return True | ||
return False | ||
|
||
|
||
def create_user_exercise(session: Session, user: User) -> UserExercise: | ||
""" Create and save new user exercise """ | ||
orontamir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not does_user_exercise_exist(session=session, user_id=user.id): | ||
user_exercise = UserExercise( | ||
user_id=user.id, | ||
start_date=datetime.now() | ||
) | ||
save(session=session, instance=user_exercise) | ||
else: | ||
user_exercise = update_user_exercise(session=session, user=user) | ||
return user_exercise | ||
|
||
|
||
def does_user_exercise_exist(session: Session, user_id: int) -> bool: | ||
""" | ||
orontamir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Check if a user exercise for user id exists. | ||
""" | ||
return get_user_exercise(session=session, user_id=user_id) | ||
|
||
|
||
def get_user_exercise(session: Session, **param) -> list: | ||
"""Returns user exercise filter by param.""" | ||
try: | ||
user_exercise = list(session.query(UserExercise).filter_by(**param)) | ||
except SQLAlchemyError: | ||
return [] | ||
else: | ||
return user_exercise | ||
|
||
|
||
def update_user_exercise(session: Session, user: User) -> UserExercise: | ||
user_ex = session.query(UserExercise).filter_by(user_id=user.id).first() | ||
# Update database | ||
user_ex.start_date = datetime.now() | ||
session.commit() | ||
return user_ex | ||
orontamir marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% extends "base.html" %} | ||
|
||
|
||
{% block content %} | ||
|
||
<div class="container mt-4"> | ||
<div class="row"> | ||
<!-- Right side --> | ||
<div class="col-5"> | ||
<!-- Exercise --> | ||
{% if user.is_active_exercise %} | ||
<div class="exercise"> | ||
<img src="{{ url_for('static', path=exercise) }}" alt="exercise image" width="270%" height="200%"> | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from app.routers.user_exercise import create_user_exercise,\ | ||
does_user_exercise_exist, get_user_exercise | ||
from app.routers.user import create_user | ||
|
||
|
||
class TestUserExercise: | ||
|
||
def test_create_user_exercise(self, session): | ||
orontamir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_user = create_user( | ||
session=session, | ||
username='new_test_username', | ||
password='new_test_password', | ||
email='[email protected]', | ||
language='english', | ||
language_id=1, | ||
) | ||
user_exercise = create_user_exercise( | ||
session=session, | ||
user=_user | ||
) | ||
assert user_exercise.user_id == _user.id | ||
session.delete(user_exercise) | ||
session.delete(_user) | ||
session.commit() | ||
|
||
def test_get_users_exercise_success(self, user_exercise, session): | ||
assert get_user_exercise(user_id=user_exercise.user_id, | ||
session=session) == [user_exercise] | ||
|
||
def test_get_user_exercise_failure(self, user_exercise, session): | ||
assert get_user_exercise(user_id=100, session=session) == [] | ||
|
||
def test_does_user_exercise_exist_success(self, user_exercise, session): | ||
assert does_user_exercise_exist(session=session, | ||
user_id=user_exercise.user_id) | ||
|
||
def test_does_user_exercise_exist_failure(self, session): | ||
assert not does_user_exercise_exist(session=session, user_id=100) |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.