<s> from django . core . exceptions import ObjectDoesNotExist <EOL> from sellmo . apps . checkout . process import AbstractCheckoutStep <EOL> from sellmo . apps . customer . routines import customer_from_request <EOL> from sellmo . contrib . account . forms import AuthenticationForm <EOL> from sellmo . contrib . account . routines import login_user <EOL> from . views import login_step <EOL> class CheckoutLoginStep ( AbstractCheckoutStep ) : <EOL> _context = None <EOL> key = '<STR_LIT>' <EOL> def __init__ ( self , request , order , next_step ) : <EOL> super ( CheckoutLoginStep , self ) . __init__ ( request , order ) <EOL> self . next_step = next_step <EOL> def get_next_step ( self ) : <EOL> return self . next_step <EOL> def is_completed ( self ) : <EOL> customer = customer_from_request ( self . request ) <EOL> return ( <EOL> self . order . pk is not None or customer is not None and <EOL> customer . is_authenticated ( ) <EOL> ) <EOL> def can_skip ( self ) : <EOL> return True <EOL> def contextualize_or_complete ( self , request , context , data = None ) : <EOL> completed = True <EOL> form = AuthenticationForm ( data ) <EOL> completed &= data and form . is_valid ( ) <EOL> if completed : <EOL> user = form . get_user ( ) <EOL> try : <EOL> user . customer is not None <EOL> except ObjectDoesNotExist : <EOL> completed = False <EOL> if completed : <EOL> login_user ( request , user ) <EOL> return completed <EOL> def complete ( self , data ) : <EOL> self . _context = { } <EOL> return self . contextualize_or_complete ( self . request , self . _context , <EOL> data ) <EOL> def render ( self , request , context ) : <EOL> if self . _context is not None : <EOL> context . update ( self . invalid_context ) <EOL> else : <EOL> self . contextualize_or_complete ( request , context ) <EOL> return login_step ( request , self . order , context = context ) </s>
