def post(self, request, *args, **kwargs): if self.request.POST.has_key('sss_create'): return self.render_to_response(self.get_context_data()) self.object = self.get_object() # needed for update form_class = self.get_form_class() form = self.get_form(form_class) if self.request.POST.has_key( 'action'): # and 'create' not in self.request.get_full_path(): # the 'initial_submit' already cleaned and saved the form, no need to save again # we are here because the redirected page confirmed this action action = self.request.POST.get('action') if action == 'Submit' or action == 'Authorise': update_status(self.request, self.object, action) refresh_gokart(self.request, fire_number=self.object.fire_number, region=self.object.region.id, district=self.object.district.id) return HttpResponseRedirect(self.get_success_url()) # update district, if it has changed (invalidates the current report and creates another with a new fire number) response = check_district_changed(self.request, self.object, form) if response: return response injury_formset = InjuryFormSet(self.request.POST, prefix='injury_fs') damage_formset = DamageFormSet(self.request.POST, prefix='damage_fs') area_burnt_formset = AreaBurntFormSet(self.request.POST, prefix='area_burnt_fs') if form.is_valid(): if form.cleaned_data['fire_not_found']: return self.form_valid(request, form) if injury_formset.is_valid( form.cleaned_data['injury_unknown'] ) and damage_formset.is_valid( form.cleaned_data['damage_unknown'] ): # No need to check area_burnt_formset since the fs is readonly return self.form_valid(request, form, area_burnt_formset, injury_formset, damage_formset) else: return self.form_invalid(request, form, area_burnt_formset, injury_formset, damage_formset) else: return self.form_invalid(request, form, area_burnt_formset, injury_formset, damage_formset)
def post(self, request, *args, **kwargs): if self.request.POST.has_key('bushfire_id'): bushfire = Bushfire.objects.get( id=self.request.POST.get('bushfire_id')) if self.request.POST.has_key('action'): action = self.request.POST.get('action') # Delete Review if action == 'delete_review' and bushfire.is_reviewed: logger.info('Action Delete Review {} - FSSDRS user {}'.format( bushfire.fire_number, request.user.get_full_name())) update_status(request, bushfire, action) # Delete Final Authorisation elif action == 'delete_final_authorisation' and bushfire.report_status == Bushfire.STATUS_FINAL_AUTHORISED: logger.info( 'Action Delete Authorisation {} - FSSDRS user {}'.format( bushfire.fire_number, request.user.get_full_name())) update_status(request, bushfire, action) # Mark Final Report as Reviewed elif action == 'mark_reviewed' and bushfire.can_review: update_status(request, bushfire, action) # Archive elif action == 'archive' and bushfire.report_status >= Bushfire.STATUS_FINAL_AUTHORISED: bushfire.archive = True elif action == 'unarchive' and bushfire.archive: bushfire.archive = False bushfire.save() refresh_gokart(request, fire_number=bushfire.fire_number ) #, region=None, district=None, action='update') return HttpResponseRedirect(self.get_success_url())
def obj_update(self, bundle, **kwargs): try: # Allows BFRS and SSS to perform update only if permitted if is_external_user(bundle.request.user): raise ImmediateHttpResponse(response=HttpUnauthorized()) if not can_maintain_data( bundle.request.user ) and bundle.obj.report_status >= Bushfire.STATUS_FINAL_AUTHORISED: raise ImmediateHttpResponse(response=HttpUnauthorized()) if bundle.request.GET.has_key( 'checkpermission' ) and bundle.request.GET['checkpermission'] == 'true': #this is a permission checking request,return directly. raise ImmediateHttpResponse(response=HttpAccepted()) self.full_hydrate(bundle) #invalidate current bushfire if required. bundle.obj, invalidated = invalidate_bushfire( bundle.obj, bundle.request.user) or (bundle.obj, False) if not invalidated: bundle.obj.save() if bundle.data.has_key('area'): if (bundle.data.get('area') or {}).get('total_area') == None: #no burning area, bundle.obj.tenures_burnt.all().delete() else: #print("Clear tenure burnt data") if bundle.obj.report_status != Bushfire.STATUS_INITIAL and bundle.data[ 'area'].get('layers'): #report is not a initial report, and has area burnt data, save it. #print("Populate new tenure burnt data") update_areas_burnt(bundle.obj, bundle.data['area']) else: #report is a initial report,or has no area burnt data. clear the existing area burnt data #area burnt data is unavailable for initial report bundle.obj.tenures_burnt.all().delete() #save plantations if bundle.data.has_key("plantations"): #need to update plantations if bundle.data.get("plantations"): #has plantation data BushfireProperty.objects.update_or_create( bushfire=bundle.obj, name="plantations", defaults={ "value": json.dumps(bundle.data.get("plantations")) }) else: #no plantation data,remove the plantations data from table BushfireProperty.objects.filter( bushfire=bundle.obj, name="plantations").delete() if bundle.obj.report_status >= Bushfire.STATUS_FINAL_AUTHORISED: if bundle.obj.fire_boundary.contains(bundle.obj.origin_point): # if bushfire has been authorised, update snapshot and archive old snapshot serialize_bushfire('final', 'SSS Update', bundle.obj) else: if bundle.obj.is_reviewed: update_status( bundle.request, bundle.obj, "delete_review", action_desc= "Delete review because origin point is outside of fire boundary after uploading from SSS", action_name="Upload") if bundle.obj.is_final_authorised: update_status( bundle.request, bundle.obj, "delete_final_authorisation", action_desc= "Delete final auth because origin point is outside of fire boundary after uploading from SSS", action_name="Upload") #print("serizlie bushfire") if invalidated: raise ImmediateHttpResponse(response=JsonResponse( { "id": bundle.obj.id, "fire_number": bundle.obj.fire_number }, status=280)) else: return bundle except: if bundle.request.GET.has_key( 'checkpermission' ) and bundle.request.GET['checkpermission'] == 'true': #for permission checking purpose, don't log the exception in log file. pass else: traceback.print_exc() raise