jtroussard/tracker-app

FT: add unit of measurement config

Opened this issue · 0 comments

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