<s> from django import http <EOL> from django . conf import settings <EOL> from django . contrib import messages <EOL> from django . contrib . auth import login as auth_login <EOL> from django . contrib . auth import logout as auth_logout <EOL> from django . contrib . auth import update_session_auth_hash <EOL> from django . contrib . sites . shortcuts import get_current_site <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . core . urlresolvers import reverse , reverse_lazy <EOL> from django . shortcuts import get_object_or_404 , redirect <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . views import generic <EOL> from oscar . apps . customer . utils import get_password_reset_url <EOL> from oscar . core . compat import get_user_model <EOL> from oscar . core . loading import ( <EOL> get_class , get_classes , get_model , get_profile_class ) <EOL> from oscar . core . utils import safe_referrer <EOL> from oscar . views . generic import PostActionMixin <EOL> from . import signals <EOL> PageTitleMixin , RegisterUserMixin = get_classes ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> Dispatcher = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> EmailAuthenticationForm , EmailUserCreationForm , OrderSearchForm = get_classes ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> PasswordChangeForm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ProfileForm , ConfirmPasswordForm = get_classes ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> UserAddressForm = get_class ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Order = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Line = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> Basket = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> UserAddress = get_model ( '<STR_LIT:address>' , '<STR_LIT>' ) <EOL> Email = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ProductAlert = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> CommunicationEventType = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> User = get_user_model ( ) <EOL> class AccountSummaryView ( generic . RedirectView ) : <EOL> """<STR_LIT>""" <EOL> pattern_name = settings . OSCAR_ACCOUNTS_REDIRECT_URL <EOL> class AccountRegistrationView ( RegisterUserMixin , generic . FormView ) : <EOL> form_class = EmailUserCreationForm <EOL> template_name = '<STR_LIT>' <EOL> redirect_field_name = '<STR_LIT>' <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if request . user . is_authenticated ( ) : <EOL> return redirect ( settings . LOGIN_REDIRECT_URL ) <EOL> return super ( AccountRegistrationView , self ) . get ( <EOL> request , * args , ** kwargs ) <EOL> def get_logged_in_redirect ( self ) : <EOL> return reverse ( '<STR_LIT>' ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( AccountRegistrationView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:email>' : self . request . GET . get ( '<STR_LIT:email>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . request . GET . get ( self . redirect_field_name , '<STR_LIT>' ) <EOL> } <EOL> kwargs [ '<STR_LIT:host>' ] = self . request . get_host ( ) <EOL> return kwargs <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> ctx = super ( AccountRegistrationView , self ) . get_context_data ( <EOL> * args , ** kwargs ) <EOL> ctx [ '<STR_LIT>' ] = safe_referrer ( self . request , '<STR_LIT>' ) <EOL> return ctx <EOL> def form_valid ( self , form ) : <EOL> self . register_user ( form ) <EOL> return redirect ( form . cleaned_data [ '<STR_LIT>' ] ) <EOL> class AccountAuthView ( RegisterUserMixin , generic . TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> login_prefix , registration_prefix = '<STR_LIT>' , '<STR_LIT>' <EOL> login_form_class = EmailAuthenticationForm <EOL> registration_form_class = EmailUserCreationForm <EOL> redirect_field_name = '<STR_LIT>' <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if request . user . is_authenticated ( ) : <EOL> return redirect ( settings . LOGIN_REDIRECT_URL ) <EOL> return super ( AccountAuthView , self ) . get ( <EOL> request , * args , ** kwargs ) <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> ctx = super ( AccountAuthView , self ) . get_context_data ( * args , ** kwargs ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> ctx [ '<STR_LIT>' ] = self . get_login_form ( ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> ctx [ '<STR_LIT>' ] = self . get_registration_form ( ) <EOL> return ctx <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> if u'<STR_LIT>' in request . POST : <EOL> return self . validate_login_form ( ) <EOL> elif u'<STR_LIT>' in request . POST : <EOL> return self . validate_registration_form ( ) <EOL> return http . HttpResponseBadRequest ( ) <EOL> def get_login_form ( self , bind_data = False ) : <EOL> return self . login_form_class ( <EOL> ** self . get_login_form_kwargs ( bind_data ) ) <EOL> def get_login_form_kwargs ( self , bind_data = False ) : <EOL> kwargs = { } <EOL> kwargs [ '<STR_LIT:host>' ] = self . request . get_host ( ) <EOL> kwargs [ '<STR_LIT>' ] = self . login_prefix <EOL> kwargs [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : self . request . GET . get ( self . redirect_field_name , '<STR_LIT>' ) , <EOL> } <EOL> if bind_data and self . request . method in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> kwargs . update ( { <EOL> '<STR_LIT:data>' : self . request . POST , <EOL> '<STR_LIT>' : self . request . FILES , <EOL> } ) <EOL> return kwargs <EOL> def validate_login_form ( self ) : <EOL> form = self . get_login_form ( bind_data = True ) <EOL> if form . is_valid ( ) : <EOL> user = form . get_user ( ) <EOL> old_session_key = self . request . session . session_key <EOL> auth_login ( self . request , form . get_user ( ) ) <EOL> signals . user_logged_in . send_robust ( <EOL> sender = self , request = self . request , user = user , <EOL> old_session_key = old_session_key ) <EOL> msg = self . get_login_success_message ( form ) <EOL> if msg : <EOL> messages . success ( self . request , msg ) <EOL> return redirect ( self . get_login_success_url ( form ) ) <EOL> ctx = self . get_context_data ( login_form = form ) <EOL> return self . render_to_response ( ctx ) <EOL> def get_login_success_message ( self , form ) : <EOL> return _ ( "<STR_LIT>" ) <EOL> def get_login_success_url ( self , form ) : <EOL> redirect_url = form . cleaned_data [ '<STR_LIT>' ] <EOL> if redirect_url : <EOL> return redirect_url <EOL> if self . request . user . is_staff : <EOL> return reverse ( '<STR_LIT>' ) <EOL> return settings . LOGIN_REDIRECT_URL <EOL> def get_registration_form ( self , bind_data = False ) : <EOL> return self . registration_form_class ( <EOL> ** self . get_registration_form_kwargs ( bind_data ) ) <EOL> def get_registration_form_kwargs ( self , bind_data = False ) : <EOL> kwargs = { } <EOL> kwargs [ '<STR_LIT:host>' ] = self . request . get_host ( ) <EOL> kwargs [ '<STR_LIT>' ] = self . registration_prefix <EOL> kwargs [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : self . request . GET . get ( self . redirect_field_name , '<STR_LIT>' ) , <EOL> } <EOL> if bind_data and self . request . method in ( '<STR_LIT:POST>' , '<STR_LIT>' ) : <EOL> kwargs . update ( { <EOL> '<STR_LIT:data>' : self . request . POST , <EOL> '<STR_LIT>' : self . request . FILES , <EOL> } ) <EOL> return kwargs <EOL> def validate_registration_form ( self ) : <EOL> form = self . get_registration_form ( bind_data = True ) <EOL> if form . is_valid ( ) : <EOL> self . register_user ( form ) <EOL> msg = self . get_registration_success_message ( form ) <EOL> messages . success ( self . request , msg ) <EOL> return redirect ( self . get_registration_success_url ( form ) ) <EOL> ctx = self . get_context_data ( registration_form = form ) <EOL> return self . render_to_response ( ctx ) <EOL> def get_registration_success_message ( self , form ) : <EOL> return _ ( "<STR_LIT>" ) <EOL> def get_registration_success_url ( self , form ) : <EOL> redirect_url = form . cleaned_data [ '<STR_LIT>' ] <EOL> if redirect_url : <EOL> return redirect_url <EOL> return settings . LOGIN_REDIRECT_URL <EOL> class LogoutView ( generic . RedirectView ) : <EOL> url = settings . OSCAR_HOMEPAGE <EOL> permanent = False <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> auth_logout ( request ) <EOL> response = super ( LogoutView , self ) . get ( request , * args , ** kwargs ) <EOL> for cookie in settings . OSCAR_COOKIES_DELETE_ON_LOGOUT : <EOL> response . delete_cookie ( cookie ) <EOL> return response <EOL> class ProfileView ( PageTitleMixin , generic . TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> ctx = super ( ProfileView , self ) . get_context_data ( ** kwargs ) <EOL> ctx [ '<STR_LIT>' ] = self . get_profile_fields ( self . request . user ) <EOL> return ctx <EOL> def get_profile_fields ( self , user ) : <EOL> field_data = [ ] <EOL> for field_name in User . _meta . additional_fields : <EOL> field_data . append ( <EOL> self . get_model_field_data ( user , field_name ) ) <EOL> profile_class = get_profile_class ( ) <EOL> if profile_class : <EOL> try : <EOL> profile = profile_class . objects . get ( user = user ) <EOL> except ObjectDoesNotExist : <EOL> profile = profile_class ( user = user ) <EOL> field_names = [ f . name for f in profile . _meta . local_fields ] <EOL> for field_name in field_names : <EOL> if field_name in ( '<STR_LIT:user>' , '<STR_LIT:id>' ) : <EOL> continue <EOL> field_data . append ( <EOL> self . get_model_field_data ( profile , field_name ) ) <EOL> return field_data <EOL> def get_model_field_data ( self , model_class , field_name ) : <EOL> """<STR_LIT>""" <EOL> field = model_class . _meta . get_field ( field_name ) <EOL> if field . choices : <EOL> value = getattr ( model_class , '<STR_LIT>' % field_name ) ( ) <EOL> else : <EOL> value = getattr ( model_class , field_name ) <EOL> return { <EOL> '<STR_LIT:name>' : getattr ( field , '<STR_LIT>' ) , <EOL> '<STR_LIT:value>' : value , <EOL> } <EOL> class ProfileUpdateView ( PageTitleMixin , generic . FormView ) : <EOL> form_class = ProfileForm <EOL> template_name = '<STR_LIT>' <EOL> communication_type_code = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( ProfileUpdateView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT:user>' ] = self . request . user <EOL> return kwargs <EOL> def form_valid ( self , form ) : <EOL> try : <EOL> old_user = User . objects . get ( id = self . request . user . id ) <EOL> except User . DoesNotExist : <EOL> old_user = None <EOL> form . save ( ) <EOL> new_email = form . cleaned_data . get ( '<STR_LIT:email>' ) <EOL> if new_email and old_user and new_email != old_user . email : <EOL> ctx = { <EOL> '<STR_LIT:user>' : self . request . user , <EOL> '<STR_LIT>' : get_current_site ( self . request ) , <EOL> '<STR_LIT>' : get_password_reset_url ( old_user ) , <EOL> '<STR_LIT>' : new_email , <EOL> } <EOL> msgs = CommunicationEventType . objects . get_and_render ( <EOL> code = self . communication_type_code , context = ctx ) <EOL> Dispatcher ( ) . dispatch_user_messages ( old_user , msgs ) <EOL> messages . success ( self . request , _ ( "<STR_LIT>" ) ) <EOL> return redirect ( self . get_success_url ( ) ) <EOL> class ProfileDeleteView ( PageTitleMixin , generic . FormView ) : <EOL> form_class = ConfirmPasswordForm <EOL> template_name = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> success_url = settings . OSCAR_HOMEPAGE <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( ProfileDeleteView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT:user>' ] = self . request . user <EOL> return kwargs <EOL> def form_valid ( self , form ) : <EOL> self . request . user . delete ( ) <EOL> messages . success ( <EOL> self . request , <EOL> _ ( "<STR_LIT>" ) ) <EOL> return redirect ( self . get_success_url ( ) ) <EOL> class ChangePasswordView ( PageTitleMixin , generic . FormView ) : <EOL> form_class = PasswordChangeForm <EOL> template_name = '<STR_LIT>' <EOL> communication_type_code = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( ChangePasswordView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT:user>' ] = self . request . user <EOL> return kwargs <EOL> def form_valid ( self , form ) : <EOL> form . save ( ) <EOL> update_session_auth_hash ( self . request , self . request . user ) <EOL> messages . success ( self . request , _ ( "<STR_LIT>" ) ) <EOL> ctx = { <EOL> '<STR_LIT:user>' : self . request . user , <EOL> '<STR_LIT>' : get_current_site ( self . request ) , <EOL> '<STR_LIT>' : get_password_reset_url ( self . request . user ) , <EOL> } <EOL> msgs = CommunicationEventType . objects . get_and_render ( <EOL> code = self . communication_type_code , context = ctx ) <EOL> Dispatcher ( ) . dispatch_user_messages ( self . request . user , msgs ) <EOL> return redirect ( self . get_success_url ( ) ) <EOL> class EmailHistoryView ( PageTitleMixin , generic . ListView ) : <EOL> context_object_name = "<STR_LIT>" <EOL> template_name = '<STR_LIT>' <EOL> paginate_by = settings . OSCAR_EMAILS_PER_PAGE <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> return Email . _default_manager . filter ( user = self . request . user ) <EOL> class EmailDetailView ( PageTitleMixin , generic . DetailView ) : <EOL> """<STR_LIT>""" <EOL> template_name = "<STR_LIT>" <EOL> context_object_name = '<STR_LIT:email>' <EOL> active_tab = '<STR_LIT>' <EOL> def get_object ( self , queryset = None ) : <EOL> return get_object_or_404 ( Email , user = self . request . user , <EOL> id = self . kwargs [ '<STR_LIT>' ] ) <EOL> def get_page_title ( self ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' % ( _ ( '<STR_LIT>' ) , self . object . subject ) <EOL> class OrderHistoryView ( PageTitleMixin , generic . ListView ) : <EOL> """<STR_LIT>""" <EOL> context_object_name = "<STR_LIT>" <EOL> template_name = '<STR_LIT>' <EOL> paginate_by = settings . OSCAR_ORDERS_PER_PAGE <EOL> model = Order <EOL> form_class = OrderSearchForm <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if '<STR_LIT>' in request . GET : <EOL> self . form = self . form_class ( self . request . GET ) <EOL> if not self . form . is_valid ( ) : <EOL> self . object_list = self . get_queryset ( ) <EOL> ctx = self . get_context_data ( object_list = self . object_list ) <EOL> return self . render_to_response ( ctx ) <EOL> data = self . form . cleaned_data <EOL> if data [ '<STR_LIT>' ] and not ( data [ '<STR_LIT>' ] or <EOL> data [ '<STR_LIT>' ] ) : <EOL> try : <EOL> order = Order . objects . get ( <EOL> number = data [ '<STR_LIT>' ] , user = self . request . user ) <EOL> except Order . DoesNotExist : <EOL> pass <EOL> else : <EOL> return redirect ( <EOL> '<STR_LIT>' , order_number = order . number ) <EOL> else : <EOL> self . form = self . form_class ( ) <EOL> return super ( OrderHistoryView , self ) . get ( request , * args , ** kwargs ) <EOL> def get_queryset ( self ) : <EOL> qs = self . model . _default_manager . filter ( user = self . request . user ) <EOL> if self . form . is_bound and self . form . is_valid ( ) : <EOL> qs = qs . filter ( ** self . form . get_filters ( ) ) <EOL> return qs <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> ctx = super ( OrderHistoryView , self ) . get_context_data ( * args , ** kwargs ) <EOL> ctx [ '<STR_LIT>' ] = self . form <EOL> return ctx <EOL> class OrderDetailView ( PageTitleMixin , PostActionMixin , generic . DetailView ) : <EOL> model = Order <EOL> active_tab = '<STR_LIT>' <EOL> def get_template_names ( self ) : <EOL> return [ "<STR_LIT>" ] <EOL> def get_page_title ( self ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' % ( _ ( '<STR_LIT>' ) , self . object . number ) <EOL> def get_object ( self , queryset = None ) : <EOL> return get_object_or_404 ( self . model , user = self . request . user , <EOL> number = self . kwargs [ '<STR_LIT>' ] ) <EOL> def do_reorder ( self , order ) : <EOL> """<STR_LIT>""" <EOL> basket = self . request . basket <EOL> lines_to_add = [ ] <EOL> warnings = [ ] <EOL> for line in order . lines . all ( ) : <EOL> is_available , reason = line . is_available_to_reorder ( <EOL> basket , self . request . strategy ) <EOL> if is_available : <EOL> lines_to_add . append ( line ) <EOL> else : <EOL> warnings . append ( reason ) <EOL> total_quantity = sum ( [ line . quantity for line in lines_to_add ] ) <EOL> is_quantity_allowed , reason = basket . is_quantity_allowed ( <EOL> total_quantity ) <EOL> if not is_quantity_allowed : <EOL> messages . warning ( self . request , reason ) <EOL> self . response = redirect ( '<STR_LIT>' ) <EOL> return <EOL> for warning in warnings : <EOL> messages . warning ( self . request , warning ) <EOL> for line in lines_to_add : <EOL> options = [ ] <EOL> for attribute in line . attributes . all ( ) : <EOL> if attribute . option : <EOL> options . append ( { <EOL> '<STR_LIT>' : attribute . option , <EOL> '<STR_LIT:value>' : attribute . value } ) <EOL> basket . add_product ( line . product , line . quantity , options ) <EOL> if len ( lines_to_add ) > <NUM_LIT:0> : <EOL> self . response = redirect ( '<STR_LIT>' ) <EOL> messages . info ( <EOL> self . request , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { '<STR_LIT>' : order . number } ) <EOL> else : <EOL> self . response = redirect ( '<STR_LIT>' ) <EOL> messages . warning ( <EOL> self . request , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : order . number } ) <EOL> class OrderLineView ( PostActionMixin , generic . DetailView ) : <EOL> """<STR_LIT>""" <EOL> def get_object ( self , queryset = None ) : <EOL> order = get_object_or_404 ( Order , user = self . request . user , <EOL> number = self . kwargs [ '<STR_LIT>' ] ) <EOL> return order . lines . get ( id = self . kwargs [ '<STR_LIT>' ] ) <EOL> def do_reorder ( self , line ) : <EOL> self . response = redirect ( '<STR_LIT>' , self . kwargs [ '<STR_LIT>' ] ) <EOL> basket = self . request . basket <EOL> line_available_to_reorder , reason = line . is_available_to_reorder ( <EOL> basket , self . request . strategy ) <EOL> if not line_available_to_reorder : <EOL> messages . warning ( self . request , reason ) <EOL> return <EOL> self . response = redirect ( '<STR_LIT>' ) <EOL> options = [ ] <EOL> for attribute in line . attributes . all ( ) : <EOL> if attribute . option : <EOL> options . append ( { '<STR_LIT>' : attribute . option , <EOL> '<STR_LIT:value>' : attribute . value } ) <EOL> basket . add_product ( line . product , line . quantity , options ) <EOL> if line . quantity > <NUM_LIT:1> : <EOL> msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { <EOL> '<STR_LIT>' : line . quantity , '<STR_LIT>' : line . product } <EOL> else : <EOL> msg = _ ( "<STR_LIT>" ) % line . product <EOL> messages . info ( self . request , msg ) <EOL> class AnonymousOrderDetailView ( generic . DetailView ) : <EOL> model = Order <EOL> template_name = "<STR_LIT>" <EOL> def get_object ( self , queryset = None ) : <EOL> order = get_object_or_404 ( self . model , user = None , <EOL> number = self . kwargs [ '<STR_LIT>' ] ) <EOL> if self . kwargs [ '<STR_LIT>' ] != order . verification_hash ( ) : <EOL> raise http . Http404 ( ) <EOL> return order <EOL> class AddressListView ( PageTitleMixin , generic . ListView ) : <EOL> """<STR_LIT>""" <EOL> context_object_name = "<STR_LIT>" <EOL> template_name = '<STR_LIT>' <EOL> paginate_by = settings . OSCAR_ADDRESSES_PER_PAGE <EOL> active_tab = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return UserAddress . _default_manager . filter ( user = self . request . user ) <EOL> class AddressCreateView ( PageTitleMixin , generic . CreateView ) : <EOL> form_class = UserAddressForm <EOL> model = UserAddress <EOL> template_name = '<STR_LIT>' <EOL> active_tab = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( AddressCreateView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT:user>' ] = self . request . user <EOL> return kwargs <EOL> def get_context_data ( self , ** kwargs ) : <EOL> ctx = super ( AddressCreateView , self ) . get_context_data ( ** kwargs ) <EOL> ctx [ '<STR_LIT:title>' ] = _ ( '<STR_LIT>' ) <EOL> return ctx <EOL> def get_success_url ( self ) : <EOL> messages . success ( self . request , <EOL> _ ( "<STR_LIT>" ) % self . object . summary ) <EOL> return super ( AddressCreateView , self ) . get_success_url ( ) <EOL> class AddressUpdateView ( PageTitleMixin , generic . UpdateView ) : <EOL> form_class = UserAddressForm <EOL> model = UserAddress <EOL> template_name = '<STR_LIT>' <EOL> active_tab = '<STR_LIT>' <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_form_kwargs ( self ) : <EOL> kwargs = super ( AddressUpdateView , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT:user>' ] = self . request . user <EOL> return kwargs <EOL> def get_context_data ( self , ** kwargs ) : <EOL> ctx = super ( AddressUpdateView , self ) . get_context_data ( ** kwargs ) <EOL> ctx [ '<STR_LIT:title>' ] = _ ( '<STR_LIT>' ) <EOL> return ctx <EOL> def get_queryset ( self ) : <EOL> return self . request . user . addresses . all ( ) <EOL> def get_success_url ( self ) : <EOL> messages . success ( self . request , <EOL> _ ( "<STR_LIT>" ) % self . object . summary ) <EOL> return super ( AddressUpdateView , self ) . get_success_url ( ) <EOL> class AddressDeleteView ( PageTitleMixin , generic . DeleteView ) : <EOL> model = UserAddress <EOL> template_name = "<STR_LIT>" <EOL> page_title = _ ( '<STR_LIT>' ) <EOL> active_tab = '<STR_LIT>' <EOL> context_object_name = '<STR_LIT:address>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> def get_queryset ( self ) : <EOL> return UserAddress . _default_manager . filter ( user = self . request . user ) <EOL> def get_success_url ( self ) : <EOL> messages . success ( self . request , <EOL> _ ( "<STR_LIT>" ) % self . object . summary ) <EOL> return super ( AddressDeleteView , self ) . get_success_url ( ) <EOL> class AddressChangeStatusView ( generic . RedirectView ) : <EOL> """<STR_LIT>""" <EOL> url = reverse_lazy ( '<STR_LIT>' ) <EOL> permanent = False <EOL> def get ( self , request , pk = None , action = None , * args , ** kwargs ) : <EOL> address = get_object_or_404 ( UserAddress , user = self . request . user , <EOL> pk = pk ) <EOL> if address . country . is_shipping_country : <EOL> setattr ( address , '<STR_LIT>' % action , True ) <EOL> elif action == '<STR_LIT>' : <EOL> setattr ( address , '<STR_LIT>' , True ) <EOL> else : <EOL> messages . error ( request , _ ( '<STR_LIT>' ) ) <EOL> address . save ( ) <EOL> return super ( AddressChangeStatusView , self ) . get ( <EOL> request , * args , ** kwargs ) </s>
