coddingtonbear / django-measurement

Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.
MIT License
145 stars 33 forks source link

unit_choices generated from .get_units(); LABELS attribute for unicode labels #25

Closed iansprice closed 8 years ago

iansprice commented 8 years ago

Made two changes for personal use that I think would benefit the library overall-

  1. Populate a form's unit_choices via MeasureBase/BidimensionalMeasure's .get_units method instead of UNITS (allowing for population of measures generated via SI_UNITS).
  2. If MeasureBase subclass has a LABELS attribute (dict of 'unit':u'unit_label') and unit in that attribute, create label for the specific option from that. This allows user to supply unicode labels without exceptions regardless of whether on Python 2 or 3.

Great lib, thanks!

codingjoe commented 8 years ago

@iansprice thanks for the PR. Seems like a good thing to have. Can you please write a test? That would be wonderful. Again, thanks!

iansprice commented 8 years ago

Phew! First time going up against Travis-CI, made a bit of a mess :) Wrote tests that test for single and bi-dimensional units w/ unicode labels and measures derived from the base measurement class SI_UNITS attribute.

codingjoe commented 8 years ago

@iansprice thanks, you did a wonderful job beating Travis ;)

Released in 2.3.0