farm package
Estimation of product-level agricultural Greenhouse Gas emissions
farm.forms module
- class farm.forms.BaseBatchImportForm(*args, **kwargs)
Bases:
floppyforms.forms.Form
- property media
Return all media required to render the widgets on this form.
- save_form(form, data, *args, **kwargs)
Save a form with a given related product or a given instance or add an error if the form is invalid
- class farm.forms.CoProductForm(*args, **kwargs)
Bases:
coolfarmtool.forms.ConditionalModelForm
- property media
Return all media required to render the widgets on this form.
- class farm.forms.EnergyUsageForm(*args, **kwargs)
Bases:
floppyforms.__future__.models.ModelForm
- property media
Return all media required to render the widgets on this form.
- class farm.forms.FarmForm(*args, **kwargs)
Bases:
floppyforms.__future__.models.ModelForm
- property media
Return all media required to render the widgets on this form.
- save(commit=True)
Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
- class farm.forms.ProductSaveAsForm(*args, **kwargs)
Bases:
floppyforms.__future__.models.ModelForm
- property media
Return all media required to render the widgets on this form.
- class farm.forms.ProfileForm(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
- property media
Return all media required to render the widgets on this form.
- class farm.forms.TransportForm(*args, **kwargs)
Bases:
coolfarmtool.forms.ConditionalModelForm
- clean()
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- property media
Return all media required to render the widgets on this form.
- class farm.forms.UserFarmSelectionForm(*args, **kwargs)
Bases:
floppyforms.__future__.models.ModelForm
- property media
Return all media required to render the widgets on this form.
- class farm.forms.VersionFormMixin(*args, **kwargs)
Bases:
floppyforms.__future__.models.ModelForm
- property media
Return all media required to render the widgets on this form.
- save(*args, **kwargs)
Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.
farm.models module
- class farm.models.ClimateZone(id, zone, moisture, name)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- class Moisture(value)
Bases:
django.db.models.enums.IntegerChoices
An enumeration.
- exception MultipleObjectsReturned
- class Zone(value)
Bases:
django.db.models.enums.IntegerChoices
An enumeration.
- class farm.models.CoProduct(id, co_product_name, product, percentage_main_value)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- class EconomicAllocation(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
Allocation method
Deprecated since version v0.7.0.
- exception MultipleObjectsReturned
- class farm.models.Continent(id, name)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class farm.models.Currency(id, code, name, symbol)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class Placement(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- save(*args, **kwargs)
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- class farm.models.EnergyUsage(*args, **kwargs)
Bases:
farm.models.LabelMixin
,django.db.models.base.Model
Direct energy use (grid electricity or hydrocarbon combustion)
- class Category(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- exception DoesNotExist
- exception MultipleObjectsReturned
- allocation
Percentage allocated
Deprecated since version v0.0.10.
- category
Categorisation (field or primary processing) for reporting
- property emissions
Calculated CO2 emissions for this activity, in kg CO2e
- factor
Emissions factor (
factor.models.Factor
) for this entry
- usage = <quantity.models.QuantityField: usage>
Consumption
- class farm.models.Farm(id, owner, name, slug, country, territory, latitude, longitude, soil_characteristics, climate, climate_zone, size, intensity, specialisation, currency, farm_identifier, certified_crsb, average_temperature_value, average_temperature_unit)
Bases:
django.db.models.base.Model
- class Climate(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- exception DoesNotExist
- class Intensity(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- exception MultipleObjectsReturned
- class Size(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class SoilCharacteristics(value)
Bases:
django.db.models.enums.IntegerChoices
An enumeration.
- property aggregation_groups
Returns list of aggregation groups used on this farm
- average_temperature = <quantity.models.QuantityField: average_temperature>
Annual average temperature
- climate
Climate (“temperate” or “tropical”
- country
locality.models.Country
- latitude
Latitude of the farm; 3 d.p. is about 100m
- property local_climate
Returns the local climate for regionalised calculations, which is either ‘Wet’ or ‘Dry’.
- name
Text identifier
- save(*args, **kwargs)
Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
- slug
django.db.fields.SlugField
- territory
locality.models.Territory
- class farm.models.FarmItemCost(id, farm, item_name, unit, value)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class farm.models.FarmMessage(id, message, is_active)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class farm.models.HeavilyIndustrialised(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class farm.models.Maintenance(id, is_active)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class farm.models.MonthPeriods(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class farm.models.Product(*args, **kwargs)
Bases:
factor.models.EmissionsModel
,coolfarmtool.mixins.LastUpdatedMixin
,django.db.models.base.Model
Shared behaviour across all product types
- exception DoesNotExist
- exception MultipleObjectsReturned
- class OxygenDemand(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class ResultOutput(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class VerificationStatus(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- class WaterTreatment(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
- property has_regionalised_calculations
Determines if calculations are run using regionalised data or methods.
- selected_folders
Return selected folders per a product.
- property weighting
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- class farm.models.Specialisation(id, name)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
- class farm.models.Transport(id, label, product, factor, source, destination, rejected_percentage, rejected_disposal, rejected_reason_1, rejected_reason_2, rejected_reason_3, waste_quantification, yield_accuracy, allocation, add_vehicle_weight, weight_value, weight_unit, distance_value, distance_unit)
Bases:
farm.models.LabelMixin
,django.db.models.base.Model
- class AddVehicleWeight(filter=(<object object>, ), item=<object object>, grouped=False)
Bases:
dj.choices.Choices
Assume that the vehicle weighs 1/3 of the load
- exception DoesNotExist
- exception MultipleObjectsReturned
- add_vehicle_weight
Adjust
weight
to account for vehicle weightDeprecated as the factors in use for road transport already include an assumed contribution from vehicle weight.
Deprecated since version v0.0.22.
- allocation
Percentage allocated
Deprecated since version v0.0.10.
- factor
Selected emissions factor (mode)
- weight = <quantity.models.QuantityField: weight>
Weight of transported material
- class farm.models.UserFarmSelection(id, user, farm)
Bases:
django.db.models.base.Model
- exception DoesNotExist
- exception MultipleObjectsReturned
Utility function for copying objects involved in one-to-many relationships.
farm.shortcuts module
- farm.shortcuts.remove_nan(val)
Replace “NaN” values in a list or dict of decimal.Decimals
farm.views module
- class farm.views.AjaxResponseMixin
Bases:
braces.views._ajax.AjaxResponseMixin
Extension of braces’ AJAX mixin, supporting:
ajax GET parameter to make testing easier
commit GET parameter for live results calculations
JSON output of form errors
- dispatch(request, *args, **kwargs)
Make request.is_ajax return True if “ajax” is given in GET
- form_invalid(form, formsets=None)
Return a dict of
form.errors
- class farm.views.ExcelResponseMixin
Bases:
object
TODO: implement using django-import-export instead
- class farm.views.FarmCreateView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.edit.CreateView
- dispatch(request, *args, **kwargs)
Redirect to farm_edit if a farm already exists
- form_class
alias of
farm.forms.FarmForm
- form_valid(form)
If the form is valid, save the associated model.
- get_context_data(**kwargs)
Insert the form into the context dict.
- get_form_kwargs()
Return the keyword arguments for instantiating the form.
- model
alias of
farm.models.Farm
- class farm.views.FarmDeleteView(**kwargs)
Bases:
farm.views.FarmMixin
,django.views.generic.edit.DeleteView
- delete(request, *args, **kwargs)
Call the delete() method on the fetched object and then redirect to the success URL.
- get_queryset()
Return the QuerySet that will be used to look up the object.
This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.
- class farm.views.FarmMixin
Bases:
braces.views._access.LoginRequiredMixin
,farm.views.ProductSaveAsMixin
Get user’s farm for views and templates.
When a user has multiple farms, the first one is used.
- get_context_data(**kwargs)
overidden get_context_data to inject a custom form onto certain page contexts in order to allow dynamic fields when using the save as feature e.g. dairy product and crop product would have different forms but this saves us having to create two forms just for the sake of one field
we only use this form on GET because the POST is managed by the ProductSaveAsView
- Returns
dictionary of keyword arguements
- class farm.views.FarmSelectView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,farm.views.AjaxResponseMixin
,braces.views._ajax.JSONResponseMixin
,django.views.generic.base.View
- class farm.views.FarmUpdateView(**kwargs)
Bases:
farm.views.FarmMixin
,django.views.generic.edit.UpdateView
- form_class
alias of
farm.forms.FarmForm
- get_context_data(**kwargs)
overidden get_context_data to inject a custom form onto certain page contexts in order to allow dynamic fields when using the save as feature e.g. dairy product and crop product would have different forms but this saves us having to create two forms just for the sake of one field
we only use this form on GET because the POST is managed by the ProductSaveAsView
- Returns
dictionary of keyword arguements
- get_form_kwargs()
Return the keyword arguments for instantiating the form.
- get_object()
Return the object the view is displaying.
Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.
- class farm.views.GeoFootPrintAPI(**kwargs)
Bases:
farm.views.FarmMixin
,django.views.generic.edit.UpdateView
- get(args, **kwargs)
Handle GET requests: instantiate a blank version of the form.
- class farm.views.ProductAggDetailView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.detail.SingleObjectMixin
,farm.views.AjaxResponseMixin
,braces.views._ajax.JSONResponseMixin
,django.views.generic.base.View
ProductAggDetailView provides aggregation group and folder details for a product.
- model
alias of
farm.models.Product
- class farm.views.ProductCreationMixin
Bases:
object
Checks if Assessments are allowed to be created (controlled via Django admin), when False Assessments cannot be created, but can still be viewed and edited. Assumed if request is POST it’s an API create request USAGE: Use this Mixin class on a create assessment view when you need to apply the assessment creation restriction
- class farm.views.ProductDeleteView(**kwargs)
Bases:
farm.views.ProductMixin
,farm.views.AjaxResponseMixin
,braces.views._ajax.JSONResponseMixin
,django.views.generic.edit.DeleteView
Delete a product
NB we don’t need a confirm_delete template since we’ll be using a dialog
- delete(request, *args, **kwargs)
Return JSON message for AJAX requests, otherwise 302 as normal
- form_valid(*args)
Return JSON string result; “success” or “error”
- get_object(queryset=None)
Return the object the view is displaying.
Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.
- class farm.views.ProductEditMixin
Bases:
object
Save basic product properties, including co-products
- get_form(form_class=None)
Set
self.co_product_formset
- class farm.views.ProductExportView(**kwargs)
Bases:
farm.views.ExcelResponseMixin
,farm.views.CSVResponseMixin
,django.views.generic.detail.DetailView
Export data to an Excel 2007 spreadsheet
- class farm.views.ProductListView(**kwargs)
Bases:
farm.views.FarmMixin
,django.views.generic.base.TemplateView
- get_context_data(**kwargs)
overidden get_context_data to inject a custom form onto certain page contexts in order to allow dynamic fields when using the save as feature e.g. dairy product and crop product would have different forms but this saves us having to create two forms just for the sake of one field
we only use this form on GET because the POST is managed by the ProductSaveAsView
- Returns
dictionary of keyword arguements
- class farm.views.ProductMixin
Bases:
farm.views.FarmMixin
Set
self.product
fromproduct_slug
URL param
- class farm.views.ProductSaveAsView(**kwargs)
Bases:
django.views.generic.detail.SingleObjectMixin
,farm.views.AjaxResponseMixin
,braces.views._ajax.JSONResponseMixin
,django.views.generic.base.View
- get_context_data(**kwargs)
Insert the single object into the context dict.
- save_as_form_class
alias of
farm.forms.ProductSaveAsForm
- class farm.views.SummaryCompareMixin
Bases:
object
Allow comparing two products, defined by a “compare_to” query parameter
Use session to memorise the last product compared for earch product type
- get_context_data(**kwargs)
‘emissions_displayed’ should be defined to override the default emission results.
Bases:
object
Share a
farm.models.Product
with anaggregation.models.AggGroup
- class farm.views.UserFarmManagementView(**kwargs)
Bases:
braces.views._access.LoginRequiredMixin
,django.views.generic.edit.FormView
,django.views.generic.list.MultipleObjectMixin
- form_class
alias of
farm.forms.UserFarmSelectionForm
- get_context_data(**kwargs)
Insert the form into the context dict.
- get_queryset()
Return the list of items for this view.
The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.
- model
alias of
farm.models.Farm