<s> from __future__ import absolute_import , unicode_literals <EOL> from braces . views import LoginRequiredMixin , JSONResponseMixin , CsrfExemptMixin <EOL> from django . contrib . gis . geos import GEOSGeometry , Point <EOL> from django . core . urlresolvers import reverse_lazy <EOL> from django . views . generic import View , TemplateView <EOL> from django . views . generic . detail import DetailView <EOL> from django . views . generic . edit import CreateView , UpdateView , DeleteView <EOL> from django . views . generic . list import ListView <EOL> from geojson import FeatureCollection <EOL> from . forms import IncidentForm , AreaOfInterestForm , ReportIncidentForm <EOL> from . models import Incident , AreaOfInterest <EOL> class IncidentListOnSuccessMixin ( object ) : <EOL> def get_success_url ( self ) : <EOL> return reverse_lazy ( '<STR_LIT>' ) <EOL> class AreaOfInterestListOnSuccessMixin ( object ) : <EOL> def get_success_url ( self ) : <EOL> return reverse_lazy ( '<STR_LIT>' ) <EOL> class IncidentListView ( LoginRequiredMixin , ListView ) : <EOL> queryset = Incident . objects . all ( ) . order_by ( '<STR_LIT>' ) <EOL> paginate_by = <NUM_LIT> <EOL> incident_list = IncidentListView . as_view ( ) <EOL> class IncidentDetailView ( LoginRequiredMixin , DetailView ) : <EOL> model = Incident <EOL> incident_detail = IncidentDetailView . as_view ( ) <EOL> class IncidentCreateView ( LoginRequiredMixin , IncidentListOnSuccessMixin , CreateView ) : <EOL> model = Incident <EOL> form_class = IncidentForm <EOL> def form_valid ( self , form ) : <EOL> form . instance . location = GEOSGeometry ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> return super ( IncidentCreateView , self ) . form_valid ( form ) <EOL> incident_create = IncidentCreateView . as_view ( ) <EOL> class ReportIncidentView ( CsrfExemptMixin , CreateView ) : <EOL> model = Incident <EOL> form_class = ReportIncidentForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def form_valid ( self , form ) : <EOL> form . instance . location = Point ( <EOL> ( float ( form . cleaned_data [ '<STR_LIT>' ] ) , float ( form . cleaned_data [ '<STR_LIT>' ] ) ) <EOL> ) <EOL> return super ( ReportIncidentView , self ) . form_valid ( form ) <EOL> report_incident = ReportIncidentView . as_view ( ) <EOL> class ReportIncidentSuccessView ( TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> report_incident_success = ReportIncidentSuccessView . as_view ( ) <EOL> class IncidentUpdateView ( LoginRequiredMixin , IncidentListOnSuccessMixin , UpdateView ) : <EOL> model = Incident <EOL> form_class = IncidentForm <EOL> def get_initial ( self ) : <EOL> initial = super ( IncidentUpdateView , self ) . get_initial ( ) <EOL> initial [ '<STR_LIT>' ] = self . get_object ( ) . location . geojson <EOL> return initial <EOL> def form_valid ( self , form ) : <EOL> form . instance . location = GEOSGeometry ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> return super ( IncidentUpdateView , self ) . form_valid ( form ) <EOL> incident_update = IncidentUpdateView . as_view ( ) <EOL> class IncidentDeleteView ( LoginRequiredMixin , IncidentListOnSuccessMixin , DeleteView ) : <EOL> model = Incident <EOL> incident_delete = IncidentDeleteView . as_view ( ) <EOL> class AreaOfInterestListView ( LoginRequiredMixin , ListView ) : <EOL> model = AreaOfInterest <EOL> paginate_by = <NUM_LIT> <EOL> area_of_interest_list = AreaOfInterestListView . as_view ( ) <EOL> class AreaOfInterestDetailView ( LoginRequiredMixin , DetailView ) : <EOL> model = AreaOfInterest <EOL> area_of_interest_detail = AreaOfInterestDetailView . as_view ( ) <EOL> class AreaOfInterestCreateView ( LoginRequiredMixin , AreaOfInterestListOnSuccessMixin , CreateView ) : <EOL> model = AreaOfInterest <EOL> form_class = AreaOfInterestForm <EOL> def form_valid ( self , form ) : <EOL> form . instance . polygon = GEOSGeometry ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> return super ( AreaOfInterestCreateView , self ) . form_valid ( form ) <EOL> area_of_interest_create = AreaOfInterestCreateView . as_view ( ) <EOL> class AreaOfInterestUpdateView ( LoginRequiredMixin , AreaOfInterestListOnSuccessMixin , UpdateView ) : <EOL> model = AreaOfInterest <EOL> form_class = AreaOfInterestForm <EOL> def get_initial ( self ) : <EOL> initial = super ( AreaOfInterestUpdateView , self ) . get_initial ( ) <EOL> initial [ '<STR_LIT>' ] = self . get_object ( ) . polygon . geojson <EOL> return initial <EOL> def form_valid ( self , form ) : <EOL> form . instance . polygon = GEOSGeometry ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> return super ( AreaOfInterestUpdateView , self ) . form_valid ( form ) <EOL> area_of_interest_update = AreaOfInterestUpdateView . as_view ( ) <EOL> class AreaOfInterestDeleteView ( LoginRequiredMixin , AreaOfInterestListOnSuccessMixin , DeleteView ) : <EOL> model = AreaOfInterest <EOL> area_of_interest_delete = AreaOfInterestDeleteView . as_view ( ) <EOL> class IncidentFeatureCollectionView ( LoginRequiredMixin , JSONResponseMixin , View ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> features = [ incident . geojson_feature for incident in Incident . objects . filter ( closed = False ) ] <EOL> feature_collection = FeatureCollection ( features ) <EOL> return self . render_json_response ( feature_collection ) <EOL> incident_feature_collection = IncidentFeatureCollectionView . as_view ( ) <EOL> class AreaOfInterestFeatureCollectionView ( LoginRequiredMixin , JSONResponseMixin , View ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> features = [ <EOL> area_of_interest . geojson_feature for area_of_interest in AreaOfInterest . objects . all ( ) <EOL> ] <EOL> feature_collection = FeatureCollection ( features ) <EOL> return self . render_json_response ( feature_collection ) <EOL> area_of_interest_feature_collection = AreaOfInterestFeatureCollectionView . as_view ( ) </s>
