-
Notifications
You must be signed in to change notification settings - Fork 80
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
first modifications for language of TOS #543
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!! Looks great. We probably need upload to support a language
parameter as well?
|
||
def test_get_tos_fr(client, tos_file, tos): | ||
params = {'language': 'FR'} | ||
response = client.get('/api/tos', params=params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it equivalent to response = client.get('/api/tos?language=FR')
?
plugins/quetz_tos/quetz_tos/api.py
Outdated
@@ -33,11 +33,15 @@ def post_file(file): | |||
return file.filename | |||
|
|||
|
|||
@router.get("/api/tos", tags=['Terms of Service']) | |||
def get_current_tos(db: Session = Depends(get_db)): | |||
@router.get("/api/tos/?{lang}", tags=['Terms of Service']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this does not work?
For adding query parameters you can look at how it is done here: /~https://github.com/tiangolo/fastapi#create-it. See how they have the "q"
query parameter.
So you probably want something like:
@router.get("/api/tos", tags=['Terms of Service'])
def get_current_tos(lang: str = "EN", db: Session = Depends(get_db)):
And then this API will be called with GET /api/tos?lang=FR
plugins/quetz_tos/quetz_tos/api.py
Outdated
current_tos = ( | ||
db.query(TermsOfService).order_by(TermsOfService.time_created.desc()).first() | ||
#db.query(TermsOfService).order_by(TermsOfService.time_created.desc()).first() | ||
db.query(TermsOfService).filter_by(language == f"{lang}").first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work? It seems language
is not defined here?
For the code styling, f"{lang}"
can simply be lang
.
Maybe the following works? (fetch all terms of services and get the first one that matches the language)
terms_of_services = (
db.query(TermsOfService).order_by(TermsOfService.time_created.desc()).all()
)
current_tos = None
for tos in terms_of_services:
if tos.language == lang:
current_tos = tos
break
|
||
def test_get_tos_fr(client, tos_file, tos): | ||
params = {'language': 'FR'} | ||
response = client.get('/api/tos', params=params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could try response = client.get('/api/tos?lang=FR')
if this does not work.
def test_get_tos_fr(client, tos_file, tos): | ||
params = {'language': 'FR'} | ||
response = client.get('/api/tos', params=params) | ||
print(response.json()) | ||
assert response.json()['filename'] == 'tos.txt' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename of your FR terms of services is tos_fr.txt
, so you probably need to fix this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! To me this looks good.
@wolfv You'd probably want to have a look :)
I am just a bit skeptical about the signing logic now. Because it's one |
Pinging @SylvainCorlay too, you might have an idea on this. |
#552 got merged, so can we close this, @martinRenou, @MichaelKora? |
No description provided.