coolfarmtool package
coolfarmtool.context module
Django template context processors
- coolfarmtool.context.GET_FULL_LANGUAGE(request)
- coolfarmtool.context.LANGUAGES(request)
- coolfarmtool.context.assessment_creation(request)
- coolfarmtool.context.current_farm(request)
- coolfarmtool.context.environment(requests)
context for Environment banner
- coolfarmtool.context.get_formats()
Inspired by django_jquerylocalize
- coolfarmtool.context.l10n(request)
Add format localisation info to request context
- coolfarmtool.context.piwik_site_url(request)
Add piwik site url for matomo
- coolfarmtool.context.product_types(request)
Add list of crop and livestock types to request context
- coolfarmtool.context.select_farm_form(request)
- coolfarmtool.context.this_year(request)
Add current year to request context
- coolfarmtool.context.version(request)
Add
settings.PROJECT_VERSION
to request context
- coolfarmtool.context.water_url(request)
Add settings.WATER_URL to request context
coolfarmtool.decimal_json module
- class coolfarmtool.decimal_json.DecimalHardEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
django.core.serializers.json.DjangoJSONEncoder
Lazy-aware JSON encoder
Handles
django.utils.functional.__proxy__
objects correctly by callingdjango.utils.encoding.force_text()
.See https://stackoverflow.com/a/31746279/399367
- default(o)
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class coolfarmtool.decimal_json.DecimalLazyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
django.core.serializers.json.DjangoJSONEncoder
Lazy-aware JSON encoder
Handles
django.utils.functional.__proxy__
objects correctly by callingdjango.utils.encoding.force_text()
.See https://stackoverflow.com/a/31746279/399367
- default(o)
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
coolfarmtool.fields module
- class coolfarmtool.fields.ChoiceField(*args, **kwargs)
Bases:
dj.choices.fields.ChoiceField
- from_db_value(value, expression, connection)
- get_choices(*args, **kwargs)
Return choices with a default blank choices included, for use as <select> choices for this field.
- class coolfarmtool.fields.DefaultCharField(*args, **kwargs)
Bases:
django.db.models.fields.CharField
CharField
withmax_length
set toDEFAULT_CHARFIELD_LENGTH
- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- class coolfarmtool.fields.DefaultDecimalField(*args, **kwargs)
Bases:
django.db.models.fields.DecimalField
DecimalField
withDEFAULT_DECIMAL_*
properties- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- formfield(**kwargs)
Return a django.forms.Field instance for this field.
- class coolfarmtool.fields.GroupedModelChoiceField(queryset, *, empty_label='---------', required=True, widget=None, label=None, initial=None, help_text='', to_field_name=None, limit_choices_to=None, blank=False, **kwargs)
Bases:
django.forms.models.ModelChoiceField
display choices in <optgroup>s
- class ExampleChoiceField(GroupedModelChoiceField):
- def optgroup_from_instance(self, obj):
return obj.group.name
https://gist.github.com/JulieGoldberg/dfc672ee39f4f1695547
- property choices
- optgroup_from_instance(obj)
- class coolfarmtool.fields.MinYearsAgoField(*args, **kwargs)
Bases:
django.db.models.fields.DecimalField
- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- default_validators = [<django.core.validators.MinValueValidator object>]
- class coolfarmtool.fields.MonthField(*args, **kwargs)
Bases:
django.db.models.fields.IntegerField
IntegerField
withchoices
set to list of months- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- class coolfarmtool.fields.NegativePercentageField(*args, **kwargs)
Bases:
django.db.models.fields.DecimalField
- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- default_validators = [<django.core.validators.MaxValueValidator object>, <django.core.validators.MinValueValidator object>]
- formfield(**kwargs)
Return a django.forms.Field instance for this field.
- class coolfarmtool.fields.PercentageField(*args, **kwargs)
Bases:
django.db.models.fields.DecimalField
- deconstruct()
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):
None, bool, str, int, float, complex, set, frozenset, list, tuple, dict
UUID
datetime.datetime (naive), datetime.date
top-level classes, top-level functions - will be referenced by their full import path
Storage instances - these have their own deconstruct() method
This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.
There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.
- default_validators = [<django.core.validators.MaxValueValidator object>, <django.core.validators.MinValueValidator object>]
- formfield(**kwargs)
Return a django.forms.Field instance for this field.
- class coolfarmtool.fields.YearsAgoField(*args, **kwargs)
Bases:
coolfarmtool.fields.MinYearsAgoField
MinYearsAgoField
with a 99-year maximum, for carbon stock changes- default_validators = [<django.core.validators.MaxValueValidator object>]
coolfarmtool.forms module
- class coolfarmtool.forms.BaseInlineFormSet(data=None, files=None, instance=None, save_as_new=False, prefix=None, queryset=None, **kwargs)
Bases:
coolfarmtool.forms.DontDeleteBaseFormSet
,django.forms.models.BaseInlineFormSet
- class coolfarmtool.forms.BaseModelFormSet(data=None, files=None, auto_id='id_%s', prefix=None, queryset=None, *, initial=None, **kwargs)
Bases:
coolfarmtool.forms.DontDeleteBaseFormSet
,django.forms.models.BaseModelFormSet
- class coolfarmtool.forms.ConditionalForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)
Bases:
floppyforms.forms.Form
- base_fields = {}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- class coolfarmtool.forms.ConditionalModelForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)
Bases:
floppyforms.__future__.models.ModelForm
- base_fields = {}
- declared_fields = {}
- property media
Return all media required to render the widgets on this form.
- class coolfarmtool.forms.DontDeleteBaseFormSet
Bases:
object
Don’t delete instances when commit=False: https://code.djangoproject.com/ticket/10284 FIXME: backported from Django 1.7, remove after update
- delete_objects(commit=True)
- save_existing_objects(commit=True)
- coolfarmtool.forms.label_from_instance(obj)
Translation-aware label_from_instance for ModelChoiceField
coolfarmtool.resources module
- class coolfarmtool.resources.BitFieldWidget(flags, separator=None, *args, **kwargs)
Bases:
import_export.widgets.CharWidget
- clean(value, row=None)
Returns an appropriate Python object for an imported value.
For example, if you import a value from a spreadsheet,
clean()
handles conversion of this value into the corresponding Python object.Numbers or dates can be cleaned to their respective data types and don’t have to be imported as Strings.
- render(value, obj=None)
Returns an export representation of a Python value.
For example, if you have an object you want to export,
render()
takes care of converting the object’s field to a value that can be written to a spreadsheet.
- class coolfarmtool.resources.ChoiceField(choices=None, *args, **kwargs)
Bases:
import_export.fields.Field
- get_value(obj)
Returns the value of the object’s attribute.
- save(obj, data, is_m2m=False)
If this field is not declared readonly, the object’s attribute will be set to the value returned by
clean()
.
- class coolfarmtool.resources.DecimalWidget
Bases:
import_export.widgets.DecimalWidget
- clean(value, row=None)
Returns an appropriate Python object for an imported value.
For example, if you import a value from a spreadsheet,
clean()
handles conversion of this value into the corresponding Python object.Numbers or dates can be cleaned to their respective data types and don’t have to be imported as Strings.
- class coolfarmtool.resources.ForeignKeyWidget(model, field='pk', *args, **kwargs)
Bases:
import_export.widgets.ForeignKeyWidget
- clean(value, row=None)
Returns an appropriate Python object for an imported value.
For example, if you import a value from a spreadsheet,
clean()
handles conversion of this value into the corresponding Python object.Numbers or dates can be cleaned to their respective data types and don’t have to be imported as Strings.
- render(value, obj=None)
Returns an export representation of a Python value.
For example, if you have an object you want to export,
render()
takes care of converting the object’s field to a value that can be written to a spreadsheet.
- class coolfarmtool.resources.JSONWidget
Bases:
import_export.widgets.CharWidget
- clean(value, row=None)
Returns an appropriate Python object for an imported value.
For example, if you import a value from a spreadsheet,
clean()
handles conversion of this value into the corresponding Python object.Numbers or dates can be cleaned to their respective data types and don’t have to be imported as Strings.
- render(value, obj=None)
Returns an export representation of a Python value.
For example, if you have an object you want to export,
render()
takes care of converting the object’s field to a value that can be written to a spreadsheet.
- class coolfarmtool.resources.ModelResource
Bases:
import_export.resources.ModelResource
- fields = {}
- classmethod widget_from_django_field(f, *args, **kwargs)
Returns the widget that would likely be associated with each Django type.
Includes mapping of Postgres Array and JSON fields. In the case that psycopg2 is not installed, we consume the error and process the field regardless.
coolfarmtool.utils module
- class coolfarmtool.utils.BarChartDataObject(number_format=None, x_axis_height=40, *args, **kwargs)
Bases:
object
- add(name, value, dataset=None)
- property json
- property json_string
- class coolfarmtool.utils.PieChartDataObject(type='pie', title=None, colours=None, percentages=True, *args, **kwargs)
Bases:
object
- add(name, value)
- property json
- property json_string
- class coolfarmtool.utils.RawChart(raw_chart_dict={})
Bases:
object
- property json
- property json_string
- coolfarmtool.utils.get_test_product_by_user(username, cls)
shortcut which is mainly used to get a crop product in a shell, could be used in other instances but is not fool-proof :param username: :str: String of the username you want to get the Crop Product for :return: :CropProduct:
- coolfarmtool.utils.validate_json(json_data, json_schema)
Validate json data against a json schema :return list of errors if any or []
coolfarmtool.views module
- class coolfarmtool.views.AboutView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.base.TemplateView
- get_context_data(**kwargs)
- template_name = 'about.html'
- class coolfarmtool.views.Handler500(**kwargs)
Bases:
django.views.generic.base.TemplateView
- classmethod as_error_view()
- template_name = '500.html'
- class coolfarmtool.views.HelpView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.base.TemplateView
- get_context_data(**kwargs)
- template_name = 'help.html'
- class coolfarmtool.views.LanguageDropdownView(**kwargs)
Bases:
django.views.generic.base.View
- get(request, *args, **kwargs)
- class coolfarmtool.views.WelcomeView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.base.TemplateView
- get_context_data(**kwargs)
- post(request, **kwargs)
- template_name = 'welcome.html'
coolfarmtool.widgets module
Custom form widgets
- class coolfarmtool.widgets.CommentArea(*args, **kwargs)
Bases:
floppyforms.widgets.Textarea
TextArea ‘comments’ box with helpful placeholder text
- property media