<s> """<STR_LIT>""" <EOL> import logging <EOL> from django . contrib import messages <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import transaction <EOL> from django . http import HttpResponseRedirect <EOL> from django . views . generic import ( CreateView , DetailView , ListView , <EOL> TemplateView , UpdateView ) <EOL> from django . utils . decorators import method_decorator <EOL> from . import RedirectFormMixin <EOL> from . . forms import ( OrganizationForm , OrganizationCreateForm , <EOL> ManagerAndOrganizationForm ) <EOL> from . . mixins import OrganizationMixin , ProviderMixin <EOL> from . . models import Organization , Subscription , get_broker <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> class RoleListView ( OrganizationMixin , TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( RoleListView , self ) . get_context_data ( ** kwargs ) <EOL> role = self . kwargs . get ( '<STR_LIT>' , None ) <EOL> context . update ( { '<STR_LIT>' : role } ) <EOL> urls_organization = { <EOL> '<STR_LIT>' : reverse ( <EOL> '<STR_LIT>' , args = ( self . organization , role ) ) , <EOL> } <EOL> if '<STR_LIT>' in context : <EOL> if '<STR_LIT>' in context [ '<STR_LIT>' ] : <EOL> context [ '<STR_LIT>' ] [ '<STR_LIT>' ] . update ( urls_organization ) <EOL> else : <EOL> context [ '<STR_LIT>' ] . update ( { '<STR_LIT>' : urls_organization } ) <EOL> else : <EOL> context . update ( { '<STR_LIT>' : { '<STR_LIT>' : urls_organization } } ) <EOL> return context <EOL> class SubscriberListView ( ProviderMixin , TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( SubscriberListView , self ) . get_context_data ( ** kwargs ) <EOL> provider = self . provider <EOL> tabs = [ { <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : reverse ( <EOL> '<STR_LIT>' , args = ( provider , ) ) <EOL> } } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : reverse ( <EOL> '<STR_LIT>' , args = ( provider , ) ) <EOL> } } ] <EOL> context . update ( { '<STR_LIT>' : tabs } ) <EOL> if provider == get_broker ( ) : <EOL> context . update ( { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT>' : reverse ( <EOL> '<STR_LIT>' ) } } } ) <EOL> return context <EOL> class SubscriptionListView ( OrganizationMixin , ListView ) : <EOL> """<STR_LIT>""" <EOL> model = Subscription <EOL> paginate_by = <NUM_LIT:10> <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> return Subscription . objects . active_for ( self . organization ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( SubscriptionListView , self ) . get_context_data ( ** kwargs ) <EOL> context . update ( { '<STR_LIT>' : context [ '<STR_LIT>' ] } ) <EOL> return context <EOL> class OrganizationCreateView ( RedirectFormMixin , CreateView ) : <EOL> """<STR_LIT>""" <EOL> model = Organization <EOL> form_class = OrganizationCreateForm <EOL> pattern_name = '<STR_LIT>' <EOL> template_name = "<STR_LIT>" <EOL> def form_valid ( self , form ) : <EOL> with transaction . atomic ( ) : <EOL> self . object = form . save ( ) <EOL> self . object . add_manager ( self . request . user ) <EOL> return HttpResponseRedirect ( self . get_success_url ( ) ) <EOL> def get_initial ( self ) : <EOL> kwargs = super ( OrganizationCreateView , self ) . get_initial ( ) <EOL> kwargs . update ( { '<STR_LIT>' : self . request . user . username , <EOL> '<STR_LIT>' : self . request . user . get_full_name ( ) , <EOL> '<STR_LIT:email>' : self . request . user . email } ) <EOL> return kwargs <EOL> def get_success_url ( self ) : <EOL> self . kwargs . update ( { '<STR_LIT>' : self . object } ) <EOL> self . success_url = reverse ( self . pattern_name , args = ( self . object , ) ) <EOL> return super ( OrganizationCreateView , self ) . get_success_url ( ) <EOL> class DashboardView ( OrganizationMixin , DetailView ) : <EOL> """<STR_LIT>""" <EOL> model = Organization <EOL> slug_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> def get_object ( self , queryset = None ) : <EOL> return self . organization <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return super ( DashboardView , self ) . get ( request , * args , ** kwargs ) <EOL> class OrganizationProfileView ( OrganizationMixin , UpdateView ) : <EOL> """<STR_LIT>""" <EOL> model = Organization <EOL> slug_field = '<STR_LIT>' <EOL> slug_url_kwarg = '<STR_LIT>' <EOL> template_name = "<STR_LIT>" <EOL> @ method_decorator ( transaction . atomic ) <EOL> def form_valid ( self , form ) : <EOL> if '<STR_LIT>' in form . cleaned_data : <EOL> self . object . is_bulk_buyer = form . cleaned_data [ '<STR_LIT>' ] <EOL> else : <EOL> self . object . is_bulk_buyer = False <EOL> manager = self . attached_manager ( self . object ) <EOL> if manager : <EOL> if form . cleaned_data . get ( '<STR_LIT>' , None ) : <EOL> manager . username = form . cleaned_data [ '<STR_LIT>' ] <EOL> if form . cleaned_data [ '<STR_LIT>' ] : <EOL> name_parts = form . cleaned_data [ '<STR_LIT>' ] . split ( '<STR_LIT:U+0020>' ) <EOL> if len ( name_parts ) > <NUM_LIT:1> : <EOL> manager . first_name = name_parts [ <NUM_LIT:0> ] <EOL> manager . last_name = '<STR_LIT:U+0020>' . join ( name_parts [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> manager . first_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> manager . last_name = '<STR_LIT>' <EOL> if form . cleaned_data [ '<STR_LIT:email>' ] : <EOL> manager . email = form . cleaned_data [ '<STR_LIT:email>' ] <EOL> manager . save ( ) <EOL> return super ( OrganizationProfileView , self ) . form_valid ( form ) <EOL> def get_form_class ( self ) : <EOL> if self . attached_manager ( self . object ) : <EOL> return ManagerAndOrganizationForm <EOL> return OrganizationForm <EOL> def get_initial ( self ) : <EOL> kwargs = super ( OrganizationProfileView , self ) . get_initial ( ) <EOL> kwargs . update ( { '<STR_LIT>' : self . object . is_bulk_buyer } ) <EOL> return kwargs <EOL> def get_success_url ( self ) : <EOL> messages . info ( self . request , '<STR_LIT>' ) <EOL> return reverse ( '<STR_LIT>' , args = ( self . object , ) ) </s>
