class PublicUserInformationForm(BaseForm): form_title = _('User information') form_description = _('Your contact information will help our researchers get in touch with you for additional information. We respect and protect your privacy and anonymity, and will never share or publish your personal information. You can also write us directly at [email protected].') tg_public_user = TitleField( required=False, label="", initial=_("User information")) tg_action_comment = forms.CharField( required=True, label="", help_text=_("Write something about yourself and your company. This won't be published."), widget=CommentInput) public_user_name = forms.CharField(required=False, label=_("Name")) public_user_email = forms.EmailField(required=True, label=_("Email")) public_user_phone = forms.CharField(required=False, label=_("Phone")) captcha = ReCaptchaField() #def get_action_comment(self): # action_comment = "" # groups = super(PublicUserInformationForm, self).get_attributes() # if len(groups) > 0: # group = groups[0] # action_comment += "comment: %s\n" % group.get("tg_public_user_comment", "-") # for t in group.get("tags", []): # action_comment += "%s: %s\n" % ( # t.get("key").split("_")[-1], t.get("value") # ) # return action_comment def get_attributes(self, request=None): return {} class Meta: name = 'user_information'
class ParentStakeholderForm(forms.ModelForm): form_title = _('Parent companies') tg_parent_stakeholder = TitleField( required=False, label="", initial=_("Parent company") ) fk_investor = forms.ModelChoiceField( required=False, label=_("Existing parent company"), queryset=Investor.objects.all(), widget=investor_widget) percentage = forms.DecimalField( required=False, max_digits=5, decimal_places=2, label=_("Ownership share"), help_text=_("%")) comment = forms.CharField( required=False, label=_("Comment"), widget=CommentInput) class Meta: name = 'parent-company' model = InvestorVentureInvolvement fields = [ 'tg_parent_stakeholder', 'id', 'fk_investor', 'investment_type', 'percentage', 'loans_amount', 'loans_currency', 'loans_date', 'comment' ]
class DealContractForm(BaseForm): form_title = _('Contracts') tg_contract = TitleField(required=False, label="", initial=_("Contract")) contract_number = forms.CharField(required=False, label=_("Contract number")) contract_date = forms.CharField( required=False, label=_("Contract date"), help_text="[YYYY-MM-DD]", #input_formats=["%d.%m.%Y", "%d:%m:%Y", "%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y"] ) contract_expiration_date = forms.CharField( required=False, label=_("Contract expiration date"), help_text="[YYYY-MM-DD]", #input_formats=["%d.%m.%Y", "%d:%m:%Y", "%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y"] ) sold_as_deal = forms.IntegerField(required=False, label=_("Sold as deal no.")) agreement_duration = forms.IntegerField( required=False, label=_("Duration of the agreement (in years)"), help_text=_("years")) tg_contract_comment = forms.CharField(required=False, label=_("Comment on Contract"), widget=CommentInput) class Meta: name = 'contract'
class DealContractForm(BaseForm): form_title = _('Contracts') tg_contract = TitleField(required=False, label="", initial=_("Contract")) contract_number = forms.CharField(required=False, label=_("Contract number")) contract_date = YearMonthDateField( required=False, label=_("Contract date"), help_text="[YYYY-MM-DD]", ) contract_expiration_date = YearMonthDateField( required=False, label=_("Contract expiration date"), help_text="[YYYY-MM-DD]", ) sold_as_deal = forms.IntegerField(required=False, label=_("Sold as deal no.")) agreement_duration = forms.IntegerField( required=False, label=_("Duration of the agreement (in years)"), help_text=_("years")) tg_contract_comment = forms.CharField(required=False, label=_("Comment on contract"), widget=CommentInput) class Meta: name = 'contract'
class ParentInvestorForm(ParentCompanyForm): form_title = _('Tertiary investor/lender') tg_parent_stakeholder = TitleField(required=False, label="", initial=_("Tertiary investor/lender")) fk_investor = forms.ModelChoiceField( required=False, label=_("Existing investor"), queryset=Investor.objects.none(), widget=forms.Select(attrs={'class': 'form-control investorfield'})) class Meta: name = 'parent-investor' model = InvestorVentureInvolvement fields = [ 'tg_parent_stakeholder', 'id', 'fk_investor', 'investment_type', 'percentage', 'loans_amount', 'loans_date', 'comment', ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Show given/current value only, rest happens via ajax valid_choice = self.data.get('%s-fk_investor' % self.prefix, self.initial.get('fk_investor', None)) if valid_choice: self.fields['fk_investor'].queryset = Investor.objects.filter( pk=valid_choice)
class DealVGGTForm(BaseForm): ''' Voluntary Guidelines on the Responsible Governance of Tenure Form. ''' form_title = _('Guidelines & Principles') APPLIED_CHOICES = ( ("Yes", _("Yes")), ("Partially", _("Partially")), ("No", _("No")), ) tg_vggt = TitleField( required=False, initial= _("Voluntary Guidelines on the Responsible Governance of Tenure (VGGT)" )) vggt_applied = forms.ChoiceField( required=False, label= _("Application of Voluntary Guidelines on the Responsible Governance of Tenure (VGGT)" ), choices=APPLIED_CHOICES, widget=forms.RadioSelect) tg_vggt_applied_comment = forms.CharField(required=False, label=_("Comment on VGGT"), widget=CommentInput) tg_prai = TitleField( required=False, initial=_( "Principles for Responsible Agricultural Investments (PRAI)")) prai_applied = forms.ChoiceField( required=False, label= _("Application of Principles for Responsible Agricultural Investments (PRAI)" ), choices=APPLIED_CHOICES, widget=forms.RadioSelect) tg_prai_applied_comment = forms.CharField(required=False, label=_("Comment on PRAI"), widget=CommentInput) class Meta: name = 'vggt'
class OperationalStakeholderForm(BaseForm): exclude_in_export = ('operational_stakeholder', ) form_title = _('Investor info') tg_operational_stakeholder = TitleField(required=False, label="", initial=_("Operating company")) operational_stakeholder = ModelChoiceField( required=False, label=_("Operating company"), queryset=HistoricalInvestor.objects.none(), widget=InvestorSelect(attrs={'class': 'form-control investorfield'})) actors = ActorsField( required=False, label=_("Actors involved in the negotiation / admission process"), choices=actor_choices) project_name = forms.CharField(required=False, label=_("Name of investment project"), max_length=255) tg_operational_stakeholder_comment = forms.CharField( required=False, label=_("Comment on investment chain"), widget=CommentInput) @classmethod def get_data(cls, activity, group=None, prefix=""): data = super().get_data(activity, group, prefix) # Get operating company queryset = activity.involvements.order_by('-id') if queryset.count() > 0: data['operational_stakeholder'] = str(queryset[0].fk_investor.id) return data def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Show given/current value only, rest happens via ajax valid_choice = self.data.get( 'operational_stakeholder', self.initial.get('operational_stakeholder', None)) if valid_choice: field = self.fields['operational_stakeholder'] field.queryset = HistoricalInvestor.objects.filter(pk=valid_choice) # Add investor identifier as data attribute if field.queryset.count() > 0: field.widget.data = { str(valid_choice): { 'investor-identifier': field.queryset[0].investor_identifier } } class Meta: name = 'investor_info'
class ParentCompanyForm(FieldsDisplayFormMixin, InvestorVentureInvolvementForm): form_title = _('Parent companies') tg_parent_stakeholder = TitleField(required=False, label="", initial=_("Parent company")) fk_investor = forms.ModelChoiceField( required=False, label=_("Existing parent company"), queryset=HistoricalInvestor.objects.none(), widget=InvestorSelect(attrs={'class': 'form-control investorfield'})) percentage = forms.DecimalField(required=False, max_digits=5, decimal_places=2, label=_("Ownership share"), help_text=_("%")) comment = forms.CharField(required=False, label=_("Comment"), widget=CommentInput) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Show given/current value only, rest happens via ajax valid_choice = self.data.get('%s-fk_investor' % self.prefix, self.initial.get('fk_investor', None)) if valid_choice: field = self.fields['fk_investor'] field.queryset = HistoricalInvestor.objects.filter(pk=valid_choice) # Add investor identifier as data attribute if field.queryset.count() > 0: field.widget.data = { str(valid_choice): { 'investor-identifier': field.queryset[0].investor_identifier } } class Meta: name = 'parent-company' model = HistoricalInvestorVentureInvolvement fields = [ 'tg_parent_stakeholder', 'id', 'fk_investor', 'investment_type', 'percentage', 'loans_amount', 'loans_date', 'parent_relation', 'comment', ]
class DealOverallCommentForm(BaseForm): form_title = _('Overall Comment') # Coordinators and reviewers overall comments tg_overall = TitleField(required=False, label="", initial=_("Overall comment")) tg_overall_comment = forms.CharField(required=False, label=_("Overall comment"), widget=CommentInput) class Meta: name = 'overall_comment'
class DealGenderRelatedInfoForm(BaseForm): form_title = _('Gender-related info') tg_gender_specific_info = TitleField( required=False, label="", initial=_("Any gender-specific information about the investment and its impacts")) tg_gender_specific_info_comment = forms.CharField( required=False, label=_("Comment on Gender-related info"), widget=CommentInput) class Meta: name = 'gender-related_info'
class MongoliaForm(BaseForm): ''' This is just a simple example. ''' form_title = _('Mongolia') tg_land_area = TitleField(required=False, label="", initial=_("Land area")) intended_size = forms.IntegerField(required=False, label=_("Intended size"), help_text=_("ha"), widget=NumberInput) test_integer = forms.IntegerField(required=False, label=_("Test integer"), widget=NumberInput) class Meta: name = 'germany specific info'
class ManageDealForm(BaseForm): ''' TODO: where is this actually used/ what is it for? ''' tg_action = TitleField( required=False, label="", initial=_("Action comment")) tg_action_comment = forms.CharField( required=False, label="", widget=CommentInput) def __init__(self, *args, **kwargs): if "instance" in kwargs: kwargs.pop("instance") super(ManageDealForm, self).__init__(*args, **kwargs) def save(self): return self
class ParentInvestorForm(ParentStakeholderForm): form_title = _('Parent investors') tg_parent_stakeholder = TitleField( required=False, label="", initial=_("Parent investor") ) fk_investor = forms.ModelChoiceField( required=False, label=_("Existing investor"), queryset=Investor.objects.all(), widget=investor_widget) class Meta: name = 'parent-investor' model = InvestorVentureInvolvement fields = [ 'tg_parent_stakeholder', 'id', 'fk_investor', 'investment_type', 'percentage', 'loans_amount', 'loans_currency', 'loans_date', 'comment' ]
class OperationalStakeholderForm(BaseForm): exclude_in_export = ('operational_stakeholder',) form_title = _('Investor info') tg_operational_stakeholder = TitleField( required=False, label="", initial=_("Operational company")) operational_stakeholder = ModelChoiceField( required=False, label=_("Operational company"), queryset=Investor.objects.none(), widget=Select(attrs={'class': 'form-control investorfield'})) actors = ActorsField( required=False, label=_("Actors involved in the negotiation / admission process"), choices=actor_choices) project_name = forms.CharField( required=False, label=_("Name of investment project"), max_length=255) tg_operational_stakeholder_comment = forms.CharField( required=False, label=_("Comment on Operational company"), widget=CommentInput) @classmethod def get_data(cls, activity, group=None, prefix=""): data = super().get_data(activity, group, prefix) op = InvestorActivityInvolvement.objects.filter( fk_activity__activity_identifier=activity.activity_identifier).first() if op: data['operational_stakeholder'] = str(op.fk_investor.id) return data def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Show given/current value only, rest happens via ajax valid_choice = self.data.get('operational_stakeholder', self.initial.get('operational_stakeholder', None)) if valid_choice: self.fields['operational_stakeholder'].queryset = Investor.objects.filter(pk=valid_choice) class Meta: name = 'investor_info'
class DealDataSourceForm(BaseForm): form_title = 'Data source' tg_data_source = TitleField( required=False, label="", initial=_("Data source") ) type = forms.ChoiceField( required=False, label=_("Data source type"), choices=( ("", _("---------")), ("Media report", _("Media report")), ("Research Paper / Policy Report", _("Research Paper / Policy Report")), ("Government sources", _("Government sources")), ("Company sources", _("Company sources")), ("Contract", _("Contract")), ("Contract (contract farming agreement)", _("Contract (contract farming agreement)")), ("Personal information", _("Personal information")), ("Crowdsourcing", _("Crowdsourcing")), ("Other", _("Other (Please specify in comment field)")), ) ) url = forms.URLField( required=False, label=_("URL"), ) file = FileFieldWithInitial( required=False, label=_("File"), help_text=_("Maximum file size: 10MB") ) file_not_public = forms.BooleanField( required=False, label=_("Keep PDF not public") ) publication_title = forms.CharField( required=False, label=_("Publication title") ) date = YearMonthDateField( required=False, label=_("Date"), help_text="[YYYY-MM-DD]", # input_formats=["%d.%m.%Y", "%d:%m:%Y", "%Y-%m-%d", "%m/%d/%Y", "%m/%d/%y"] ) # Optional personal information for Crowdsourcing and Personal information name = forms.CharField(required=False, label=_("Name")) company = forms.CharField(required=False, label=_("Organisation")) email = forms.CharField(required=False, label=_("Email")) phone = forms.CharField(required=False, label=_("Phone")) includes_in_country_verified_information = forms.BooleanField( required=False, label=_("Includes in-country-verified information") ) open_land_contracts_id = forms.CharField( required=False, label=_("OpenLandContracts ID") ) tg_data_source_comment = forms.CharField( required=False, label=_("Comment on data source"), widget=CommentInput ) #def clean_date(self): # date = self.cleaned_data["date"] # try: # return date and date.strftime("%Y-%m-%d") or "" # except ValueError: # raise forms.ValidationError( # _("Invalid date. Please enter a date in the format [YYYY-MM-DD]") # ) def clean_file(self): file = self.cleaned_data["file"] if file and isinstance(file, File): n = file.name.split(".") # cleanup special charachters in filename file.name = "%s.%s" % (slugify(n[0]), n[1]) if len(n)>1 else slugify(n[0]) return file def get_availability_total(self): return 4 def get_fields_display(self, user=None): if not (user and user.is_authenticated and user.has_perm('landmatrix.review_activity')): # Remove file field if not Editor/Admin if self.initial.get('file_not_public', False): self.initial.pop('file_not_public') if 'file' in self.initial: self.initial.pop('file') # Remove personal information fields for field_name in ('name', 'company', 'email', 'phone'): if field_name in self.initial: self.initial.pop(field_name) return super().get_fields_display(user=user)
class DealActionCommentForm(BaseForm): exclude_in_export = ("tg_action_comment", "source", "id", "assign_to_user", "tg_feedback_comment", "fully_updated") NOT_PUBLIC_REASON_CHOICES = ( ("", _("---------")), ( "Temporary removal from PI after criticism", _("Temporary removal from PI after criticism"), ), ("Research in progress", _("Research in progress")), ('Land Observatory Import (new)', _('Land Observatory Import (new)')), ( 'Land Observatory Import (duplicate)', _('Land Observatory Import (duplicate)'), ), ) form_title = _('Action Comment') tg_action = TitleField(required=False, label="", initial=_("Action comment")) tg_action_comment = forms.CharField(required=True, label=_('Action comment'), widget=CommentInput) fully_updated = forms.BooleanField(required=False, label=_("Fully updated")) #fully_updated_history = forms.CharField( # required=False, label=_("Fully updated history"), # widget=forms.Textarea(attrs={"readonly":True, "cols": 80, "rows": 5})) tg_not_public = TitleField(required=False, label="", initial=_("Public deal")) not_public = forms.BooleanField( required=False, label=_("Not public"), help_text=_("Please specify in additional comment field")) not_public_reason = forms.ChoiceField(required=False, label=_("Reason"), choices=NOT_PUBLIC_REASON_CHOICES) tg_not_public_comment = forms.CharField(required=False, label=_("Comment on Not Public"), widget=CommentInput) tg_imported = TitleField(required=False, label="", initial=_("Import history")) source = forms.CharField(required=False, label=_("Import source"), widget=forms.TextInput(attrs={'readonly': True})) id = forms.CharField(required=False, label=_("Previous identifier"), widget=forms.TextInput(attrs={ 'size': '64', 'readonly': True })) tg_feedback = TitleField(required=False, label="", initial=_("Feedback")) assign_to_user = UserModelChoiceField( required=False, label=_("Assign to"), queryset=get_user_model().objects.none(), empty_label=_("Unassigned")) tg_feedback_comment = forms.CharField(required=False, label=_("Feedback comment"), widget=CommentInput) class Meta: name = 'action_comment' def __init__(self, *args, **kwargs): super(DealActionCommentForm, self).__init__(*args, **kwargs) self.fields['assign_to_user'].queryset = get_user_model( ).objects.filter( groups__name__in=("Editors", "Administrators")).order_by("username") def get_attributes(self, request=None): # Remove action comment, this field is handled separately in SaveDealView attributes = super(DealActionCommentForm, self).get_attributes(request) del attributes['tg_action_comment'] return attributes @classmethod def get_data(cls, activity, group=None, prefix=""): # Remove action comment, due to an old bug it seems to exist as an attribute too data = super().get_data(activity, group, prefix) if 'tg_action_comment' in data: del data['tg_action_comment'] return data
class DealLocalCommunitiesForm(BaseForm): RECOGNITION_STATUS_CHOICES = ( ( "Indigenous Peoples traditional or customary rights recognized by government", _("Indigenous Peoples traditional or customary rights recognized by government") ), ( "Indigenous Peoples traditional or customary rights not recognized by government", _("Indigenous Peoples traditional or customary rights not recognized by government") ), ( "Community traditional or customary rights recognized by government", _("Community traditional or customary rights recognized by government") ), ( "Community traditional or customary rights not recognized by government", _("Community traditional or customary rights not recognized by government") ), ) COMMUNITY_CONSULTATION_CHOICES = ( ("Not consulted", _("Not consulted")), ("Limited consultation", _("Limited consultation")), ("Free prior and informed consent", _("Free, Prior and Informed Consent (FPIC)")), ("Certified Free, Prior and Informed Consent (FPIC)", _("Certified Free, Prior and Informed Consent (FPIC)")), ("Other", _("Other")), ) COMMUNITY_REACTION_CHOICES = ( ("Consent", _("Consent")), ("Mixed reaction", _("Mixed reaction")), ("Rejection", _("Rejection")), ) # TODO: convert to booleanfield? BOOLEAN_CHOICES = ( ("Yes", _("Yes")), ("No", _("No")), ) NEGATIVE_IMPACTS_CHOICES = ( ("Environmental degradation", _("Environmental degradation")), ("Socio-economic", _("Socio-economic")), ("Cultural loss", _("Cultural loss")), ("Eviction", _("Eviction")), ("Displacement", _("Displacement")), ("Violence", _("Violence")), ("Other", _("Other")), ) BENEFITS_CHOICES = ( ("Health", _("Health")), ("Education", _("Education")), ( "Productive infrastructure", _("Productive infrastructure (e.g. irrigation, tractors, machinery...)") ), ("Roads", _("Roads")), ("Capacity Building", _("Capacity Building")), ("Financial Support", _("Financial Support")), ( "Community shares in the investment project", _("Community shares in the investment project") ), ("Other", _("Other")), ) form_title = _('Local communities / indigenous peoples') # Names of affected communities and indigenous peoples tg_names_of_affected = TitleField( required=False, label="", initial=_("Names of communities / indigenous peoples affected")) name_of_community = MultiCharField( required=False, label=_("Name of community"), widget=forms.TextInput) name_of_indigenous_people = MultiCharField( required=False, label=_("Name of indigenous people"), widget=forms.TextInput) tg_affected_comment = forms.CharField( required=False, label=_("Comment on communities / indigenous peoples affected"), widget=CommentInput) # Recognitions status of community land tenure tg_recognition_status = TitleField( required=False, label="", initial=_("Recognitions status of community land tenure")) recognition_status = forms.MultipleChoiceField( required=False, label=_("Recognition status of community land tenure"), choices=RECOGNITION_STATUS_CHOICES, widget=forms.CheckboxSelectMultiple) tg_recognition_status_comment = forms.CharField( required=False, label=_("Comment on recognitions status of community land tenure"), widget=CommentInput) # Consultation of local community tg_community_consultation = TitleField( required=False, label="", initial=_("Consultation of local community")) community_consultation = forms.ChoiceField( required=False, label=_("Community consultation"), choices=COMMUNITY_CONSULTATION_CHOICES, widget=forms.RadioSelect) tg_community_consultation_comment = forms.CharField( required=False, label=_("Comment on consultation of local community"), widget=CommentInput) # How did community react? tg_community_reaction = TitleField( required=False, label="", initial=_("How did the community react?")) community_reaction = forms.ChoiceField( required=False, label=_("Community reaction"), choices=COMMUNITY_REACTION_CHOICES, widget=forms.RadioSelect) tg_community_reaction_comment = forms.CharField( required=False, label=_("Comment on community reaction"), widget=CommentInput) # Land conflicts tg_land_conflicts = TitleField( required=False, label="", initial=_("Presence of land conflicts")) land_conflicts = forms.ChoiceField( required=False, label=_("Presence of land conflicts"), choices=BOOLEAN_CHOICES, widget=forms.RadioSelect) tg_land_conflicts_comment = forms.CharField( required=False, label=_("Comment on presence of land conflicts"), widget=CommentInput) # Displacement of people tg_displacement_of_people = TitleField( required=False, label="", initial=_("Displacement of people") ) displacement_of_people = forms.ChoiceField( required=False, label=_("Displacement of people"), choices=BOOLEAN_CHOICES, widget=forms.RadioSelect) number_of_displaced_people = forms.IntegerField( required=False, label=_("Number of people actually displaced"), widget=NumberInput) number_of_displaced_households = forms.IntegerField( required=False, label=_("Number of households actually displaced"), widget=NumberInput) number_of_people_displaced_from_community_land = forms.IntegerField( required=False, label=_("Number of people displaced out of their community land"), widget=NumberInput) number_of_people_displaced_within_community_land = forms.IntegerField( required=False, label=_("Number of people displaced staying on community land"), widget=NumberInput) number_of_households_displaced_from_fields = forms.IntegerField( required=False, label=_('Number of households displaced "only" from their agricultural fields'), widget=NumberInput) number_of_people_displaced_on_completion = forms.IntegerField( required=False, label=_('Number of people facing displacement once project is fully implemented'), widget=NumberInput) tg_number_of_displaced_people_comment = forms.CharField( required=False, label=_("Comment on displacement of people"), widget=CommentInput) tg_negative_impacts = TitleField( required=False, label="", initial=_("Negative impacts for local communities")) negative_impacts = forms.MultipleChoiceField( required=False, label=_("Negative impacts for local communities"), choices=NEGATIVE_IMPACTS_CHOICES, widget=forms.CheckboxSelectMultiple) tg_negative_impacts_comment = forms.CharField( required=False, label=_("Comment on negative impacts for local communities"), widget=CommentInput) # Promised compensation tg_promised_compensation = TitleField( required=False, label="", initial=_("Promised or received compensation")) promised_compensation = forms.CharField( required=False, label=_("Promised compensation (e.g. for damages or resettlements)"), widget=CommentInput) received_compensation = forms.CharField( required=False, label=_("Received compensation (e.g. for damages or resettlements)"), widget=CommentInput) # Promised benefits for local communities tg_promised_benefits = TitleField( required=False, label="", initial=_("Promised benefits for local communities")) promised_benefits = forms.MultipleChoiceField( required=False, label=_("Promised benefits for local communities"), choices=BENEFITS_CHOICES, widget=forms.CheckboxSelectMultiple) tg_promised_benefits_comment = forms.CharField( required=False, label=_("Comment on promised benefits for local communities"), widget=CommentInput) # Materialized benefits for local communities tg_materialized_benefits = TitleField( required=False, label="", initial=_("Materialized benefits for local communities") ) materialized_benefits = forms.MultipleChoiceField( required=False, label=_("Materialized benefits for local communities"), choices=BENEFITS_CHOICES, widget=forms.CheckboxSelectMultiple) tg_materialized_benefits_comment = forms.CharField( required=False, label=_("Comment on materialized benefits for local communities"), widget=CommentInput) # Presence of organizations and actions taken (e.g. farmer organizations, NGOs, etc.) tg_presence_of_organizations = TitleField( required=False, initial=_("Presence of organizations and actions taken (e.g. farmer organizations, NGOs, etc.)")) presence_of_organizations = forms.CharField( required=False, label=_("Presence of organizations and actions taken (e.g. farmer organizations, NGOs, etc.)"), widget=CommentInput) class Meta: name = 'local_communities'
class DealFormerUseForm(BaseForm): FORMER_LAND_OWNER_CHOICES = ( ("State", _("State")), ("Private (smallholders)", _("Private (smallholders)")), ("Private (large-scale)", _("Private (large-scale farm)")), ("Community", _("Community")), ("Indigenous people", _("Indigenous people")), ("Other", _("Other")), ) FORMER_LAND_USE_CHOICES = ( ("Commercial (large-scale) agriculture", _("Commercial (large-scale) agriculture")), ("Smallholder agriculture", _("Smallholder agriculture")), ("Shifting cultivation", _("Shifting cultivation")), ("Pastoralism", _("Pastoralism")), ("Hunting/Gathering", _("Hunting/Gathering")), ("Forestry", _("Forestry")), ("Conservation", _("Conservation")), ("Other", _("Other")), ) FORMER_LAND_COVER_CHOICES = ( ("Cropland", _("Cropland")), ("Forest land", _("Forest land")), ("Pasture", _("Pasture")), ("Shrub land/Grassland", _("Shrub land/Grassland (Rangeland)")), ("Marginal land", _("Marginal land")), ("Wetland", _("Wetland")), ("Other land", _("Other land (e.g. developed land – specify in comment field)")), ) form_title = _('Former use') tg_land_owner = TitleField( required=False, label="", initial=_("Former land owner (not by constitution)")) land_owner = forms.MultipleChoiceField( required=False, label=_("Former land owner"), choices=FORMER_LAND_OWNER_CHOICES, widget=forms.CheckboxSelectMultiple) tg_land_owner_comment = forms.CharField( required=False, label=_("Comment on former land owner"), widget=CommentInput) tg_land_use = TitleField( required=False, label="", initial=_("Former land use")) land_use = forms.MultipleChoiceField( required=False, label=_("Former land use"), choices=FORMER_LAND_USE_CHOICES, widget=forms.CheckboxSelectMultiple) tg_land_use_comment = forms.CharField( required=False, label=_("Comment on former land use"), widget=CommentInput) tg_land_cover = TitleField( required=False, label="", initial=_("Former land cover")) land_cover = forms.MultipleChoiceField( required=False, label=_("Former land cover"), choices=FORMER_LAND_COVER_CHOICES, widget=forms.CheckboxSelectMultiple) tg_land_cover_comment = forms.CharField( required=False, label=_("Comment on former land cover"), widget=CommentInput) class Meta: name = 'former_use'
class DealEmploymentForm(BaseForm): form_title = _('Employment') # Total number of jobs created tg_total_number_of_jobs_created = TitleField( required=False, label="", initial=_("Number of total jobs created")) total_jobs_created = forms.BooleanField(required=False, label=_("Jobs created (total)")) total_jobs_planned = forms.IntegerField( required=False, label=_("Planned number of jobs (total)"), help_text=_("jobs"), widget=NumberInput) total_jobs_planned_employees = forms.IntegerField( required=False, label=_("Planned employees (total)"), help_text=_("employees"), widget=NumberInput) total_jobs_planned_daily_workers = forms.IntegerField( required=False, label=_("Planned daily/seasonal workers (total)"), help_text=_("workers"), widget=NumberInput) total_jobs_current = YearBasedIntegerField( required=False, label=_("Current number of jobs (total)"), help_text=_("jobs"), widget=NumberInput) total_jobs_current_employees = YearBasedIntegerField( required=False, label=_("Current number of employees (total)"), help_text=_("employees"), widget=NumberInput) total_jobs_current_daily_workers = YearBasedIntegerField( required=False, label=_("Current number of daily/seasonal workers (total)"), help_text=_("workers"), widget=NumberInput) tg_total_number_of_jobs_created_comment = forms.CharField( required=False, label=_("Comment on jobs created (total)"), widget=CommentInput) # Number of jobs for foreigners created tg_foreign_jobs_created = TitleField( required=False, label="", initial=_("Number of jobs for foreigners created")) foreign_jobs_created = forms.BooleanField( required=False, label=_("Jobs created (foreign)")) foreign_jobs_planned = forms.IntegerField( required=False, label=_("Planned number of jobs (foreign)"), help_text=_("jobs"), widget=NumberInput) foreign_jobs_planned_employees = forms.IntegerField( required=False, label=_("Planned employees (foreign)"), help_text=_("employees"), widget=NumberInput) foreign_jobs_planned_daily_workers = forms.IntegerField( required=False, label=_("Planned daily/seasonal workers (foreign)"), help_text=_("workers"), widget=NumberInput) foreign_jobs_current = YearBasedIntegerField( required=False, label=_("Current number of jobs (foreign)"), help_text=_("jobs")) foreign_jobs_current_employees = YearBasedIntegerField( required=False, label=_("Current number of employees (foreign)"), help_text=_("employees")) foreign_jobs_current_daily_workers = YearBasedIntegerField( required=False, label=_("Current number of daily/seasonal workers (foreign)"), help_text=_("workers")) tg_foreign_jobs_created_comment = forms.CharField( required=False, label=_("Comment on jobs created (foreign)"), widget=CommentInput) # Number of domestic jobs created tg_domestic_jobs_created = TitleField( required=False, label="", initial=_("Number of domestic jobs created")) domestic_jobs_created = forms.BooleanField( required=False, label=_("Jobs created (domestic)")) domestic_jobs_planned = forms.IntegerField( required=False, label=_("Planned number of jobs (domestic)"), help_text=_("jobs"), widget=NumberInput) domestic_jobs_planned_employees = forms.IntegerField( required=False, label=_("Planned employees (domestic)"), help_text=_("employees"), widget=NumberInput) domestic_jobs_planned_daily_workers = forms.IntegerField( required=False, label=_("Planned daily/seasonal workers (domestic)"), help_text=_("workers"), widget=NumberInput) domestic_jobs_current = YearBasedIntegerField( required=False, label=_("Current number of jobs (domestic)"), help_text=_("jobs")) domestic_jobs_current_employees = YearBasedIntegerField( required=False, label=_("Current number of employees (domestic)"), help_text=_("employees")) domestic_jobs_current_daily_workers = YearBasedIntegerField( required=False, label=_("Current number of daily/seasonal workers (domestic)"), help_text=_("workers")) tg_domestic_jobs_created_comment = forms.CharField( required=False, label=_("Comment on jobs created (domestic)"), widget=CommentInput) class Meta: name = 'employment'
class DealGeneralForm(BaseForm): # TODO: why not boolean here? Maybe because there are three options: Yes, No or Unknown. CONTRACT_FARMING_CHOICES = ( ("Yes", _("Yes")), ("No", _("No")), ) form_title = _('General info') # Land area tg_land_area = TitleField( required=False, label="", initial=_("Land area")) intended_size = forms.FloatField(localize=True, required=False, label=_("Intended size (in ha)"), help_text=_("ha"), widget=forms.TextInput(attrs={'placeholder': _('Size')})) contract_size = YearBasedFloatField( required=False, label=_("Size under contract (leased or purchased area, in ha)"), help_text=_("ha"), placeholder=_('Size')) production_size = YearBasedFloatField( required=False, label=_("Size in operation (production, in ha)"), help_text=_("ha"), placeholder=_('Size')) tg_land_area_comment = forms.CharField( required=False, label=_("Comment on land area"), widget=CommentInput) # Intention of investment tg_intention = TitleField( required=False, label="", initial=_("Intention of investment")) intention = YearBasedMultipleChoiceIntegerField( required=False, label=_("Intention of the investment"), choices=grouped_intention_choices) tg_intention_comment = forms.CharField( required=False, label=_("Comment on intention of investment"), widget=CommentInput) # Nature of the deal tg_nature = TitleField( required=False, label="", initial=_("Nature of the deal")) nature = forms.MultipleChoiceField( required=False, label=_("Nature of the deal"), choices=nature_choices, widget=forms.CheckboxSelectMultiple) tg_nature_comment = forms.CharField( required=False, label=_("Comment on nature of the deal"), widget=CommentInput) # Negotiation status, tg_negotiation_status = TitleField( required=False, label="", initial=_("Negotiation status") ) negotiation_status = YearBasedChoiceField( required=False, label=_("Negotiation status"), choices=Activity.NEGOTIATION_STATUS_CHOICES) tg_negotiation_status_comment = forms.CharField( required=False, label=_("Comment on negotiation status"), widget=CommentInput) # Implementation status tg_implementation_status = TitleField( required=False, label="", initial=_("Implementation status")) implementation_status = YearBasedChoiceField( required=False, label=_("Implementation status"), choices=Activity.IMPLEMENTATION_STATUS_CHOICES) tg_implementation_status_comment = forms.CharField( required=False, label=_("Comment on implementation status"), widget=CommentInput) # Purchase price tg_purchase_price = TitleField( required=False, label="", initial=_("Purchase price")) purchase_price = forms.DecimalField( max_digits=19, decimal_places=2, required=False, label=_("Purchase price")) purchase_price_currency = forms.ModelChoiceField( required=False, label=_("Purchase price currency"), queryset=Currency.objects.all().order_by("ranking", "name")) purchase_price_type = forms.TypedChoiceField( required=False, label=_("Purchase price area type"), choices=price_type_choices) purchase_price_area = forms.IntegerField( required=False, label=_("Purchase price area"), help_text=_("ha"), widget=forms.NumberInput(attrs={'placeholder': _('Size')})) tg_purchase_price_comment = forms.CharField( required=False, label=_("Comment on purchase price"), widget=CommentInput) # Leasing fees tg_leasing_fees = TitleField( required=False, label="", initial=_("Leasing fees")) annual_leasing_fee = forms.DecimalField( max_digits=19, decimal_places=2, required=False, label=_("Annual leasing fee")) annual_leasing_fee_currency = forms.ModelChoiceField( required=False, label=_("Annual leasing fee currency"), queryset=Currency.objects.all().order_by("ranking", "name")) annual_leasing_fee_type = forms.TypedChoiceField( required=False, label=_("Annual leasing fee type"), choices=price_type_choices) annual_leasing_fee_area = forms.IntegerField( required=False, label=_("Purchase price area"), help_text=_("ha"), widget=forms.NumberInput(attrs={'placeholder': _('Size')})) tg_leasing_fees_comment = forms.CharField( required=False, label=_("Comment on leasing fees"), widget=CommentInput) # Contract farming tg_contract_farming = TitleField( required=False, label="", initial=_("Contract farming")) contract_farming = forms.ChoiceField( required=False, label=_("Contract farming"), choices=CONTRACT_FARMING_CHOICES, widget=forms.RadioSelect) on_the_lease = forms.BooleanField( required=False, label=_("On leased / purchased area")) on_the_lease_area = YearBasedIntegerField( required=False, label=_("On leased / purchased area (in ha)"), help_text=_("ha"), placeholder=_('Size')) on_the_lease_farmers = YearBasedIntegerField( required=False, label=_("On leased / purchased farmers"), help_text=_("farmers")) on_the_lease_households = YearBasedIntegerField( required=False, label=_("On leased / purchased households"), help_text=_("households")) off_the_lease = forms.BooleanField( required=False, label=_("Not on leased / purchased area (out-grower)")) off_the_lease_area = YearBasedIntegerField( required=False, label=_("Not on leased / purchased area (out-grower, in ha)"), help_text=_("ha"), placeholder=_('Size')) off_the_lease_farmers = YearBasedIntegerField( required=False, label=_("Not on leased / purchased farmers (out-grower)"), help_text=_("farmers")) off_the_lease_households = YearBasedIntegerField( required=False, label=_("Not on leased / purchased households (out-grower)"), help_text=_("households")) tg_contract_farming_comment = forms.CharField( required=False, label=_("Comment on contract farming"), widget=CommentInput) class Meta: name = 'general_information'
class DealWaterForm(BaseForm): BOOLEAN_CHOICES = ( ("Yes", _("Yes")), ("No", _("No")), ) SOURCE_OF_WATER_EXTRACTION_CHOICES = ( ("Groundwater", _("Groundwater"), None), ("Surface water", _("Surface water"), ( ("River", _("River")), ("Lake", _("Lake")), )), ) form_title = _('Water') tg_water_extraction_envisaged = TitleField( required=False, initial=_("Water extraction envisaged")) water_extraction_envisaged = forms.ChoiceField( required=False, label=_("Water extraction envisaged"), choices=BOOLEAN_CHOICES, widget=forms.RadioSelect) tg_water_extraction_envisaged_comment = forms.CharField( required=False, label=_("Comment on Water extraction envisaged"), widget=CommentInput) tg_source_of_water_extraction = TitleField( required=False, initial=_("Source of water extraction")) source_of_water_extraction = NestedMultipleChoiceField( required=False, label=_("Source of water extraction"), choices=SOURCE_OF_WATER_EXTRACTION_CHOICES) tg_source_of_water_extraction_comment = forms.CharField( required=False, label=_("Comment on Source of water extraction"), widget=CommentInput) tg_how_much_do_investors_pay = TitleField( required=False, initial= _("How much do investors pay for water and the use of water infrastructure?" )) tg_how_much_do_investors_pay_comment = forms.CharField( required=False, label=_("Comment on How much do investors pay for water"), widget=CommentInput) tg_water_extraction_amount = TitleField( required=False, initial=_("How much water is extracted?")) water_extraction_amount = forms.CharField( required=False, label=_("Water extraction amount"), help_text=_("m3/year")) tg_water_extraction_amount_comment = forms.CharField( required=False, label=_("Comment on How much water is extracted"), widget=CommentInput) use_of_irrigation_infrastructure = forms.ChoiceField( required=False, label=_("Use of irrigation infrastructure"), choices=BOOLEAN_CHOICES, widget=forms.RadioSelect) tg_use_of_irrigation_infrastructure_comment = forms.CharField( required=False, label=_("Comment on Use of irrigation infrastructure"), widget=CommentInput) water_footprint = forms.CharField( required=False, label=_("Water footprint of the investment project"), widget=CommentInput) class Meta: name = 'water'
class DealProduceInfoForm(BaseForm): BOOLEAN_CHOICES = ( ("Yes", _("Yes")), ("No", _("No")), ) form_title = _('Produce info') # Detailed crop, animal and mineral information tg_crop_animal_mineral = TitleField( required=False, label="", initial=_("Detailed crop, animal and mineral information")) crops = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Crops area"), queryset=Crop.objects.all()) crops_yield = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Crops yield"), queryset=Crop.objects.all()) crops_export = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Crops export"), queryset=Crop.objects.all()) tg_crops_comment = forms.CharField(required=False, label=_("Comment on Crops"), widget=CommentInput) animals = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Livestock area"), queryset=Animal.objects.all()) animals_yield = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Livestock yield"), queryset=Animal.objects.all()) animals_export = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Livestock export"), queryset=Animal.objects.all()) tg_animals_comment = forms.CharField(required=False, label=_("Comment on Livestock"), widget=CommentInput) minerals = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Resources area"), queryset=Mineral.objects.all()) minerals_yield = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Resources yield"), queryset=Mineral.objects.all()) minerals_export = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Resources export"), queryset=Mineral.objects.all()) tg_minerals_comment = forms.CharField(required=False, label=_("Comment on Resources"), widget=CommentInput) # Detailed contract farming crop, animal and mineral information tg_contract_farming_crop_animal_mineral = TitleField( required=False, initial=_( "Detailed contract farming crop, animal and mineral information")) contract_farming_crops = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Contract farming crops"), queryset=Crop.objects.all()) tg_contract_farming_crops_comment = forms.CharField( required=False, label=_("Comment on Contract farming crops"), widget=CommentInput) contract_farming_animals = YearBasedModelMultipleChoiceIntegerField( required=False, label=_("Contract farming livestock"), queryset=Animal.objects.all()) tg_contract_farming_animals_comment = forms.CharField( required=False, label=_("Comment on Contract farming livestock"), widget=CommentInput) # Use of produce tg_use_of_produce = TitleField(required=False, label="", initial=_("Use of produce")) has_domestic_use = forms.BooleanField(required=False, label=_("Has domestic use")) domestic_use = forms.IntegerField(required=False, label=_("Domestic use"), help_text=_("%"), widget=NumberInput) has_export = forms.BooleanField(required=False, label=_("Has export")) export = forms.IntegerField(required=False, label=_("Export"), help_text=_("%"), widget=NumberInput) # TODO: surely this should be a formset? export_country1 = forms.ModelChoiceField( required=False, label=_("Country 1"), queryset=Country.objects.defer('geom').all().order_by("name")) export_country1_ratio = forms.IntegerField(required=False, label=_("Country 1 ratio"), help_text=_("%"), widget=NumberInput) export_country2 = forms.ModelChoiceField( required=False, label=_("Country 2"), queryset=Country.objects.defer('geom').all().order_by("name")) export_country2_ratio = forms.IntegerField(required=False, label=_("Country 2 ratio"), help_text=_("%"), widget=NumberInput) export_country3 = forms.ModelChoiceField( required=False, label=_("Country 3"), queryset=Country.objects.defer('geom').all().order_by("name")) export_country3_ratio = forms.IntegerField(required=False, label=_("Country 3 ratio"), help_text=_("%"), widget=NumberInput) tg_use_of_produce_comment = forms.CharField( required=False, label=_("Comment on Use of produce"), widget=CommentInput) # In-country processing of produce tg_in_country_processing = TitleField( required=False, label="", initial=_("In country processing of produce")) # TODO: YesNoField? in_country_processing = forms.ChoiceField( required=False, label=_("In country processing of produce"), choices=BOOLEAN_CHOICES, widget=forms.RadioSelect) tg_in_country_processing_comment = forms.CharField( required=False, label=_("Comment on In country processing of produce"), widget=CommentInput) processing_facilities = forms.CharField( required=False, label=_( "Processing facilities / production infrastructure of the project (e.g. oil mill, " "ethanol distillery, biomass power plant etc.)"), widget=CommentInput) in_country_end_products = forms.CharField( required=False, label=_("In-country end products of the project"), widget=CommentInput) class Meta: name = 'produce_info'
class DealSpatialForm(BaseForm): exclude_in_export = ['contract_area', 'intended_area', 'production_area'] ACCURACY_CHOICES = ( ("", _("---------")), ("Country", _("Country")), ("Administrative region", _("Administrative region")), ("Approximate location", _("Approximate location")), ("Exact location", _("Exact location")), ("Coordinates", _("Coordinates")), ) AREA_FIELDS = ( 'contract_area', 'intended_area', 'production_area', ) form_title = _('Location') tg_location = TitleField( required=False, label="", initial=_("Location")) level_of_accuracy = forms.ChoiceField( required=False, label=_("Spatial accuracy level"), choices=ACCURACY_CHOICES) location = forms.CharField( required=False, label=_("Location"), widget=LocationWidget) point_lat = forms.CharField( required=False, label=_("Latitude"), widget=forms.TextInput, initial="") point_lon = forms.CharField( required=False, label=_("Longitude"), widget=forms.TextInput, initial="") facility_name = forms.CharField( required=False, label=_("Facility name"), widget=forms.TextInput, initial="") target_country = CountryField(required=False, label=_("Target country")) #target_region = forms.ModelChoiceField( # required=False, label=_("Target Region"), widget=forms.HiddenInput, # queryset=Region.objects.all().order_by("name")) location_description = forms.CharField( required=False, label=_("Location description"), widget=forms.TextInput, initial="") contract_area = AreaField(required=False, label=_("Contract area")) intended_area = AreaField(required=False, label=_("Intended area")) production_area = AreaField(required=False, label=_("Area in operation")) tg_location_comment = forms.CharField( required=False, label=_("Comment on location"), widget=CommentInput) class Meta: name = 'location' def __init__(self, *args, **kwargs): ''' Pass the values we need through to map widgets ''' super().__init__(*args, **kwargs) lat_lon_attrs = self.get_default_lat_lon_attrs() # Bind area maps to the main location map area_attrs = { 'bound_map_field_id': '{}-map'.format(self['location'].html_name) } area_attrs.update(lat_lon_attrs) location_attrs = self.get_location_map_widget_attrs() location_attrs.update(lat_lon_attrs) if area_attrs: for polygon_field in self.AREA_FIELDS: widget = AreaWidget(map_attrs=area_attrs) self.fields[polygon_field].widget = widget # Public field gets a mapwidget, so check for that if isinstance(self.fields['location'].widget, MapWidget): self.fields['location'].widget = MapWidget(attrs=location_attrs) else: self.fields['location'].widget = LocationWidget( map_attrs=location_attrs) def get_location_map_widget_attrs(self): attrs = { 'show_layer_switcher': True, } bound_fields = ( ('location', 'bound_location_field_id'), ('target_country', 'bound_target_country_field_id'), ('level_of_accuracy', 'bound_level_of_accuracy_field_id'), ('point_lat', 'bound_lat_field_id'), ('point_lon', 'bound_lon_field_id'), ) for field, attr in bound_fields: try: attrs[attr] = self[field].auto_id except KeyError: pass return attrs def get_default_lat_lon_attrs(self): attrs = {} try: lat = float(self['point_lat'].value() or 0) except ValueError: lat = None try: lon = float(self['point_lon'].value() or 0) except ValueError: lon = None if lat and lon: attrs.update({ 'initial_center_lon': lon, 'initial_center_lat': lat, 'initial_point': [lon, lat], }) return attrs def clean_area_field(self, field_name): value = self.cleaned_data[field_name] try: # Check if we got a file here, as value.name value.size except AttributeError: value_is_file = False else: value_is_file = True if value_is_file: # Files are the second widget, so append _1 field_name = '{}_1'.format(self[field_name].html_name) shapefile_data = hasattr(self.files, 'getlist') and self.files.getlist(field_name) or self.files[field_name] try: value = parse_shapefile(shapefile_data) except ValueError as err: error_msg = _('Error parsing shapefile: %s') % err raise forms.ValidationError(error_msg) return value def clean_contract_area(self): return self.clean_area_field('contract_area') def clean_intended_area(self): return self.clean_area_field('intended_area') def clean_production_area(self): return self.clean_area_field('production_area') def get_attributes(self, request=None): attributes = super().get_attributes() # For polygon fields, pass the value directly for field_name in self.AREA_FIELDS: polygon_value = self.cleaned_data.get(field_name) attributes[field_name] = {'polygon': polygon_value} return attributes @classmethod def get_data(cls, activity, group=None, prefix=""): data = super().get_data(activity, group=group, prefix=prefix) for area_field_name in cls.AREA_FIELDS: area_attribute = activity.attributes.filter( fk_group__name=group, name=area_field_name).first() if area_attribute: data[area_field_name] = area_attribute.polygon return data def get_fields_display(self, user=None): fields = super().get_fields_display(user=user) # Hide coordinates depending on level of accuracy accuracy = self.initial.get('level_of_accuracy', '') if accuracy in ('Country', 'Administrative region', 'Approximate location'): for field in fields: if field['name'] in ('point_lat', 'point_lon'): field['hidden'] = True return fields