def form_valid(self, investor_form, stakeholders_formset, investors_formset): hinvestor = investor_form.save(user=self.request.user) stakeholders_formset.save(self.object) investors_formset.save(self.object) if 'approve_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hinvestor): messages.success( self.request, self.success_message_admin.format( hinvestor.investor_identifier)) hinvestor.approve_change(self.request.user, hinvestor.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hinvestor): hinvestor.reject_change(self.request.user, hinvestor.comment) else: messages.success( self.request, self.success_message.format(hinvestor.investor_identifier)) # Is dialog? self.object = hinvestor if self.request.GET.get('popup', False): response = self.render_popup() else: response = HttpResponseRedirect(self.get_success_url()) return response
def form_valid(self, forms): old_hactivity = self.get_object() investor_form = list( filter(lambda f: isinstance(f, OperationalStakeholderForm), forms))[0] is_admin = self.request.user.has_perm('landmatrix.change_activity') is_editor = self.request.user.has_perm('landmatrix.review_activity') if old_hactivity.fk_status_id == HistoricalActivity.STATUS_PENDING: # Only editors and administrators are allowed to edit pending versions if not is_editor and not is_admin: return HttpResponseForbidden('Deal version is pending') # Don't create new version if rejected if 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, old_hactivity): hactivity = old_hactivity else: # Create new historical activity hactivity = HistoricalActivity( activity_identifier=old_hactivity.activity_identifier, fk_status_id=HistoricalActivity.STATUS_PENDING, history_user=self.request.user) hactivity.save(update_elasticsearch=False) # Create new activity attributes hactivity.comment = self.create_attributes(hactivity, forms) form = self.get_form_by_type(forms, DealActionCommentForm) if form: hactivity.fully_updated = self.get_fully_updated(form) else: hactivity.fully_updated = False hactivity.save(update_elasticsearch=False) self.create_involvement(hactivity, investor_form) if not is_admin: self.create_activity_changeset(hactivity) # Create activity feedback form = self.get_form_by_type(forms, DealActionCommentForm) if form: self.create_activity_feedback(hactivity, form) if 'approve_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hactivity): messages.success( self.request, self.success_message_admin.format( hactivity.activity_identifier)) hactivity.approve_change(self.request.user, hactivity.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hactivity): hactivity.reject_change(self.request.user, hactivity.comment) else: messages.success( self.request, self.success_message.format(hactivity.activity_identifier)) return redirect('deal_detail', deal_id=hactivity.activity_identifier)
def form_valid(self, forms): activity_identifier = HistoricalActivity.objects.values().aggregate( Max('activity_identifier'))['activity_identifier__max'] or 0 activity_identifier += 1 investor_form = list( filter(lambda f: isinstance(f, OperationalStakeholderForm), forms))[0] # Create new historical activity hactivity = HistoricalActivity( activity_identifier=activity_identifier, history_user=self.request.user, ) is_admin = self.request.user.has_perm('landmatrix.add_activity') hactivity.fk_status_id = hactivity.STATUS_PENDING hactivity.save() # Create new activity attributes hactivity.comment = self.create_attributes(hactivity, forms) form = self.get_form_by_type(forms, DealActionCommentForm) if form: hactivity.fully_updated = self.get_fully_updated(form) else: hactivity.fully_updated = False hactivity.save(update_elasticsearch=False) self.create_involvement(hactivity, investor_form) # Create activity feedback form = self.get_form_by_type(forms, DealActionCommentForm) if form: self.create_activity_feedback(hactivity, form) if is_admin: redirect_url = reverse( 'deal_detail', kwargs={'deal_id': hactivity.activity_identifier}) else: # TODO: check that is is correct, but all deals seems like a # reasonable place to redirect to, as these users can't see the # deal yet redirect_url = reverse('data') if 'approve_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hactivity): messages.success( self.request, self.success_message_admin.format( hactivity.activity_identifier)) hactivity.approve_change(self.request.user, hactivity.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hactivity): hactivity.reject_change(self.request.user, hactivity.comment) else: messages.success( self.request, self.success_message.format(hactivity.activity_identifier)) return HttpResponseRedirect(redirect_url)
def form_valid(self, forms): activity_identifier = HistoricalActivity.objects.values().aggregate(Max('activity_identifier'))['activity_identifier__max'] or 0 activity_identifier += 1 investor_form = list(filter(lambda f: isinstance(f, OperationalStakeholderForm), forms))[0] # Create new historical activity hactivity = HistoricalActivity( activity_identifier=activity_identifier, history_user=self.request.user, ) is_admin = self.request.user.has_perm('landmatrix.add_activity') hactivity.fk_status_id = hactivity.STATUS_PENDING hactivity.save() # Create new activity attributes hactivity.comment = self.create_attributes(hactivity, forms) form = self.get_form_by_type(forms, DealActionCommentForm) if form: hactivity.fully_updated = self.get_fully_updated(form) else: hactivity.fully_updated = False hactivity.save(update_elasticsearch=False) self.create_involvement(hactivity, investor_form) # Create activity feedback form = self.get_form_by_type(forms, DealActionCommentForm) if form: self.create_activity_feedback(hactivity, form) if is_admin: redirect_url = reverse( 'deal_detail', kwargs={'deal_id': hactivity.activity_identifier}) else: # TODO: check that is is correct, but all deals seems like a # reasonable place to redirect to, as these users can't see the # deal yet redirect_url = reverse('data') if 'approve_btn' in self.request.POST and has_perm_approve_reject(self.request.user, hactivity): messages.success( self.request, self.success_message_admin.format(hactivity.activity_identifier)) hactivity.approve_change(self.request.user, hactivity.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject(self.request.user, hactivity): hactivity.reject_change(self.request.user, hactivity.comment) else: messages.success( self.request, self.success_message.format(hactivity.activity_identifier)) return HttpResponseRedirect(redirect_url)
def form_valid(self, forms): old_hactivity = self.get_object() investor_form = list(filter(lambda f: isinstance(f, OperationalStakeholderForm), forms))[0] is_admin = self.request.user.has_perm('landmatrix.change_activity') is_editor = self.request.user.has_perm('landmatrix.review_activity') if old_hactivity.fk_status_id == HistoricalActivity.STATUS_PENDING: # Only editors and administrators are allowed to edit pending versions if not is_editor and not is_admin: raise HttpResponseForbidden('Deal version is pending') # Don't create new version if rejected if 'reject_btn' in self.request.POST and has_perm_approve_reject(self.request.user, old_hactivity): hactivity = old_hactivity else: # Create new historical activity hactivity = HistoricalActivity( activity_identifier=old_hactivity.activity_identifier, fk_status_id=HistoricalActivity.STATUS_PENDING, history_user=self.request.user) hactivity.save(update_elasticsearch=False) # Create new activity attributes hactivity.comment = self.create_attributes(hactivity, forms) form = self.get_form_by_type(forms, DealActionCommentForm) if form: hactivity.fully_updated = self.get_fully_updated(form) else: hactivity.fully_updated = False hactivity.save(update_elasticsearch=False) self.create_involvement(hactivity, investor_form) if not is_admin: self.create_activity_changeset(hactivity) # Create activity feedback form = self.get_form_by_type(forms, DealActionCommentForm) if form: self.create_activity_feedback(hactivity, form) if 'approve_btn' in self.request.POST and has_perm_approve_reject(self.request.user, hactivity): messages.success(self.request, self.success_message_admin.format(hactivity.activity_identifier)) hactivity.approve_change(self.request.user, hactivity.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject(self.request.user, hactivity): hactivity.reject_change(self.request.user, hactivity.comment) else: messages.success(self.request, self.success_message.format(hactivity.activity_identifier)) return redirect('deal_detail', deal_id=hactivity.activity_identifier)
def form_valid(self, investor_form, stakeholders_formset, investors_formset): old_hinvestor = self.get_object() is_admin = self.request.user.has_perm('landmatrix.change_investor') is_editor = self.request.user.has_perm('landmatrix.review_investor') if old_hinvestor.fk_status_id == HistoricalInvestor.STATUS_PENDING: # Only editors and administrators are allowed to edit pending versions if not is_editor and not is_admin: return HttpResponseForbidden('Investor version is pending') # Don't create new version if rejected if 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, old_hinvestor): hinvestor = old_hinvestor else: hinvestor = investor_form.save(user=self.request.user) stakeholders_formset.save(hinvestor) investors_formset.save(hinvestor) if 'approve_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hinvestor): messages.success( self.request, self.success_message_admin.format( hinvestor.investor_identifier)) hinvestor.approve_change(self.request.user, hinvestor.comment) elif 'reject_btn' in self.request.POST and has_perm_approve_reject( self.request.user, hinvestor): hinvestor.reject_change(self.request.user, hinvestor.comment) else: messages.success( self.request, self.success_message.format(hinvestor.investor_identifier)) # Is dialog? self.object = hinvestor if self.request.GET.get('popup', False): return self.render_popup() return redirect('investor_detail', investor_id=hinvestor.investor_identifier)
def can_approve_reject(user, object=None): return has_perm_approve_reject(user, object)