<s> from django . shortcuts import render_to_response <EOL> from models import UserProfile <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . http import HttpResponseRedirect , HttpResponseNotAllowed <EOL> from django . views . generic import simple <EOL> from openflow . optin_manager . opts . models import UserFlowSpace , UserOpts , OptsFlowSpace , AdminFlowSpace <EOL> from openflow . optin_manager . admin_manager . models import * <EOL> from openflow . optin_manager . users . forms import * <EOL> from django . contrib . auth . forms import PasswordChangeForm <EOL> def index ( request ) : <EOL> if request . user . is_authenticated ( ) : <EOL> return HttpResponseRedirect ( '<STR_LIT>' ) <EOL> else : <EOL> return HttpResponseRedirect ( '<STR_LIT>' ) <EOL> @ login_required <EOL> def change_profile ( request ) : <EOL> '''<STR_LIT>''' <EOL> profile = UserProfile . get_or_create_profile ( request . user ) <EOL> if request . method == "<STR_LIT:GET>" : <EOL> user_form = UserForm ( instance = request . user ) <EOL> pass_change_form = PasswordChangeForm ( request . user ) <EOL> if profile . is_net_admin : <EOL> admin_form = AdminProfileForm ( instance = request . user . get_profile ( ) ) <EOL> elif request . method == "<STR_LIT:POST>" : <EOL> user_form = UserForm ( request . POST , instance = request . user ) <EOL> valid1 = user_form . is_valid ( ) <EOL> if profile . is_net_admin : <EOL> admin_form = AdminProfileForm ( request . POST , instance = request . user . get_profile ( ) ) <EOL> valid3 = admin_form . is_valid ( ) <EOL> else : <EOL> valid3 = True <EOL> if ( request . POST [ '<STR_LIT>' ] != "<STR_LIT>" ) : <EOL> pass_change_form = PasswordChangeForm ( request . user , request . POST ) <EOL> valid2 = pass_change_form . is_valid ( ) <EOL> else : <EOL> pass_change_form = PasswordChangeForm ( request . user ) <EOL> valid2 = True <EOL> if ( valid1 and valid2 and valid3 ) : <EOL> user_form . save ( ) <EOL> if ( request . POST [ '<STR_LIT>' ] != "<STR_LIT>" ) : <EOL> pass_change_form . save ( ) <EOL> if profile . is_net_admin : <EOL> admin_form . save ( ) <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> else : <EOL> return HttpResponseNotAllowed ( "<STR_LIT:GET>" , "<STR_LIT:POST>" ) <EOL> if ( profile . is_net_admin ) : <EOL> return simple . direct_to_template ( request , <EOL> template = '<STR_LIT>' , <EOL> extra_context = { <EOL> '<STR_LIT>' : user_form , <EOL> '<STR_LIT>' : pass_change_form , <EOL> '<STR_LIT>' : admin_form <EOL> } <EOL> ) <EOL> else : <EOL> return simple . direct_to_template ( request , <EOL> template = '<STR_LIT>' , <EOL> extra_context = { <EOL> '<STR_LIT>' : user_form , <EOL> '<STR_LIT>' : pass_change_form , <EOL> } <EOL> ) <EOL> @ login_required <EOL> def dashboard ( request ) : <EOL> '''<STR_LIT>''' <EOL> profile = UserProfile . get_or_create_profile ( request . user ) <EOL> if ( not profile . is_net_admin ) : <EOL> next_steps = <NUM_LIT:0> <EOL> opts = [ ] <EOL> ufs = UserFlowSpace . objects . filter ( user = request . user ) <EOL> if ( len ( ufs ) == <NUM_LIT:0> ) : <EOL> rufs = RequestedUserFlowSpace . objects . filter ( user = request . user ) <EOL> if ( len ( rufs ) == <NUM_LIT:0> ) : <EOL> next_steps = <NUM_LIT:0> <EOL> else : <EOL> next_steps = <NUM_LIT:1> <EOL> else : <EOL> opts = UserOpts . objects . filter ( user = request . user ) . order_by ( '<STR_LIT>' ) <EOL> if ( len ( opts ) == <NUM_LIT:0> ) : <EOL> next_steps = <NUM_LIT:2> <EOL> else : <EOL> next_steps = <NUM_LIT:3> <EOL> return simple . direct_to_template ( request , <EOL> template = '<STR_LIT>' , <EOL> extra_context = { <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : next_steps , <EOL> '<STR_LIT>' : opts , <EOL> } , <EOL> ) <EOL> else : <EOL> adminfs = AdminFlowSpace . objects . filter ( user = request . user ) <EOL> opts = UserOpts . objects . filter ( user = request . user ) . order_by ( '<STR_LIT>' ) <EOL> optsfs = [ ] <EOL> for opt in opts : <EOL> fses = opt . optsflowspace_set . all ( ) <EOL> for fs in fses : <EOL> optsfs . append ( fs ) <EOL> num_user_reqs = RequestedUserFlowSpace . objects . filter ( admin = request . user ) . count ( ) <EOL> num_admin_reqs = RequestedAdminFlowSpace . objects . filter ( admin = request . user ) . count ( ) <EOL> num_admin_promotes = AdminPromoteRequest . objects . filter ( admin = request . user ) . count ( ) <EOL> return simple . direct_to_template ( request , <EOL> template = '<STR_LIT>' , <EOL> extra_context = { <EOL> '<STR_LIT:user>' : request . user , <EOL> '<STR_LIT>' : optsfs , <EOL> '<STR_LIT>' : adminfs , <EOL> '<STR_LIT>' : num_admin_reqs , <EOL> '<STR_LIT>' : num_user_reqs , <EOL> '<STR_LIT>' : num_admin_promotes , <EOL> } , <EOL> ) </s>
