<s> from django . contrib . auth . decorators import login_required <EOL> from django . core . urlresolvers import reverse <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . decorators import method_decorator <EOL> from django . views . generic import DetailView , ListView , UpdateView <EOL> from apps . profiles . forms import ProfileForm <EOL> from apps . profiles . models import City , Profile <EOL> class ProfileList ( ListView ) : <EOL> template_name = '<STR_LIT>' <EOL> model = Profile <EOL> def get_queryset ( self ) : <EOL> city_id = self . request . GET . get ( '<STR_LIT>' , False ) <EOL> if city_id : <EOL> return self . model . objects . filter ( city__id = city_id ) <EOL> return super ( ProfileList , self ) . get_queryset ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ProfileList , self ) . get_context_data ( ** kwargs ) <EOL> context . update ( { <EOL> '<STR_LIT>' : City . objects . all ( ) <EOL> } ) <EOL> return context <EOL> class ProfileDetail ( DetailView ) : <EOL> template_name = '<STR_LIT>' <EOL> model = Profile <EOL> def get_object ( self , queryset = None ) : <EOL> username = self . kwargs . get ( '<STR_LIT:username>' ) <EOL> user = get_object_or_404 ( self . model , user__username = username ) <EOL> return user <EOL> class ProfileEdit ( UpdateView ) : <EOL> template_name = '<STR_LIT>' <EOL> form_class = ProfileForm <EOL> model = Profile <EOL> def get_object ( self ) : <EOL> return self . model . objects . get ( <EOL> user__username = self . request . user . username ) <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . request . user . username ] ) <EOL> @ method_decorator ( login_required ) <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> return super ( ProfileEdit , self ) . dispatch ( * args , ** kwargs ) <EOL> def form_valid ( self , form ) : <EOL> form . save ( ) <EOL> return super ( ProfileEdit , self ) . form_valid ( form ) </s>
