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

FT: add unit of measurement config #37

Open
jtroussard opened this issue Mar 11, 2023 · 0 comments
Open

FT: add unit of measurement config #37

jtroussard opened this issue Mar 11, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@jtroussard
Copy link
Owner

Summary

Implement a per account setting for system of measurement

Dependencies

  • Database/backend design
  • Translation service

AC

  • As a user, When I go to my account settings page, Then there is a setting for unit of measurement
  • As a user, When I set my unit of measurement setting, all forms display a default measurement that corresponds with the field's unit.

Notes

Design not set yet, but leaning towards setting all the data in the database as metric, then adding a backend translation layer that would make any calculations before passing them to the front end. Look into middleware or custom filters.

Development Tasks

  • Add a field to the user model to store the system of measurement
    • "imperial" or "metric".
  • On login, retrieve user's system of measurement preference from the database and store it in the session object
    • suggestion: session['system_of_measurement']
  • Use the session variable to render the correct unit on the forms. (another ticket to create the generic measurements component)
  • When the form is submitted, retrieve the system_of_measurement value from the session object and use it to convert the weight to the appropriate units.
class User:
    def __init__(self, id, system_of_measurement):
        self.id = id
        # ... and so on
        self.system_of_measurement = system_of_measurement


class WeightForm(FlaskForm):
    weight = FloatField('Weight', validators=[InputRequired())
    system = SelectField('System of Measurement', choices=[('imperial', 'Imperial'), ('metric', 'Metric')])
    submit = SubmitField('Submit')

@app.route('/tracker', methods=['GET', 'POST'])
def tracker():
    # check for user code

    # init form stuff here
    form = WeightForm()
    form.system.default = user.system_of_measurement
    # for the default values (dbl check this) -> form.process()

    if form.validate_on_submit():
        weight = form.weight.data
        # on submit, send to some other back end service to make the translations before committing to the database
@jtroussard jtroussard added this to the Version 2 milestone Mar 11, 2023
@jtroussard jtroussard added the enhancement New feature or request label May 8, 2023
@jtroussard jtroussard changed the title USER SETTINGS: add unit of measurement config FT: add unit of measurement config May 8, 2023
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

No branches or pull requests

1 participant