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

first modifications for language of TOS #543

Closed
wants to merge 16 commits into from

Conversation

MichaelKora
Copy link
Contributor

No description provided.

Copy link
Member

@martinRenou martinRenou left a 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?

@hbcarlos hbcarlos added the enhancement New feature or request label Jun 23, 2022

def test_get_tos_fr(client, tos_file, tos):
params = {'language': 'FR'}
response = client.get('/api/tos', params=params)
Copy link
Member

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')?

@@ -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'])
Copy link
Member

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

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()
Copy link
Member

@martinRenou martinRenou Jun 24, 2022

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)
Copy link
Member

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'
Copy link
Member

@martinRenou martinRenou Jun 24, 2022

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.

Copy link
Member

@martinRenou martinRenou left a 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 :)

@martinRenou
Copy link
Member

I am just a bit skeptical about the signing logic now.

Because it's one TermsOfServices object per-language, it's one id per-language. So when someone signs a specific version of the terms of services, they sign it for the language they read.
It's probably fine though?

@martinRenou
Copy link
Member

Pinging @SylvainCorlay too, you might have an idea on this.

@janjagusch
Copy link
Collaborator

#552 got merged, so can we close this, @martinRenou, @MichaelKora?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants