-
Notifications
You must be signed in to change notification settings - Fork 52
refactor/jinja-global-variable #302
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
issac211
wants to merge
17
commits into
PythonFreeCourse:develop
Choose a base branch
from
issac211:refactor/jinja-global-variable
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
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
98670be
feat: adding global variable
issac211 e04d7c1
Merge branch 'develop' into refactor/jinja-global-variable
issac211 59411df
fix: fixed for flake8
issac211 ce3fa34
Merge branch 'refactor/jinja-global-variable' of https://github.com/i…
issac211 2a57add
fix: little fix, README file
issac211 365e49c
feat: added a link to the forum
issac211 914ba31
Merge branch 'develop' into refactor/jinja-global-variable
issac211 2890b74
fix: improved code for requested changes
issac211 cb0e0f9
local merge
issac211 d3b5258
Merge branch 'develop' into refactor/jinja-global-variable
issac211 7ac04f0
fix: Small correction
issac211 9b2f121
fix: Small correction
issac211 e7fb749
Merge branch 'develop' into refactor/jinja-global-variable
issac211 eb56e7c
Merge branch 'develop' into refactor/jinja-global-variable
issac211 32be156
fix: made it more usable with the security module
issac211 df6be83
fix: for flake8
issac211 4e8d5bf
fix: saves only the username to the global variables
issac211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from fastapi import APIRouter, Depends, Request | ||
from sqlalchemy.orm import Session | ||
|
||
from app.database.models import User | ||
from app.dependencies import get_db, templates | ||
|
||
|
||
router = APIRouter( | ||
prefix="/global-variable", | ||
tags=["global-variable"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
|
||
@router.get("/") | ||
async def global_var(request: Request, db: Session = Depends(get_db)): | ||
user = User( | ||
username='test_user', | ||
email='[email protected]', | ||
password='1a2s3d4f5g6', | ||
full_name='My Name', | ||
language_id=1, | ||
telegram_id='', | ||
) | ||
user_db = db.query(User).filter_by(username=user.username).first() | ||
if not user_db: | ||
db.add(user) | ||
db.commit() | ||
user = db.query(User).filter_by(username=user.username).first() | ||
templates.env.globals['user'] = user | ||
return templates.TemplateResponse("global_var_test.html", { | ||
"request": request | ||
}) |
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,7 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
|
||
<h2>username: {{ user.username }}</h2> | ||
|
||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_global_var(global_var_test_client): | ||
response = global_var_test_client.get("/global-variable") | ||
assert response.ok | ||
assert b'test_user' in response.content |
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.