<s> import logging <EOL> from django . http import HttpResponseRedirect , Http404 <EOL> from django . shortcuts import resolve_url <EOL> from django . views . generic import TemplateView <EOL> from stackdio . api . cloud . models import CloudAccount <EOL> logger = logging . getLogger ( __name__ ) <EOL> class StackdioView ( TemplateView ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if request . user . is_authenticated ( ) : <EOL> return super ( StackdioView , self ) . get ( request , * args , ** kwargs ) <EOL> else : <EOL> redirect_url = resolve_url ( '<STR_LIT>' ) <EOL> if request . path != '<STR_LIT:/>' : <EOL> redirect_url = '<STR_LIT>' . format ( redirect_url , request . path ) <EOL> return HttpResponseRedirect ( redirect_url ) <EOL> class RootView ( StackdioView ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> if request . user . is_authenticated ( ) : <EOL> has_account_perm = request . user . has_perm ( '<STR_LIT>' ) <EOL> if has_account_perm and CloudAccount . objects . count ( ) == <NUM_LIT:0> : <EOL> redirect_view = '<STR_LIT>' <EOL> else : <EOL> redirect_view = '<STR_LIT>' <EOL> return HttpResponseRedirect ( resolve_url ( redirect_view ) ) <EOL> else : <EOL> return super ( RootView , self ) . get ( request , * args , ** kwargs ) <EOL> class AppMainView ( TemplateView ) : <EOL> template_name = '<STR_LIT>' <EOL> content_type = '<STR_LIT>' <EOL> class PageView ( StackdioView ) : <EOL> viewmodel = None <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( PageView , self ) . __init__ ( ** kwargs ) <EOL> assert self . viewmodel is not None , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( PageView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . viewmodel <EOL> return context <EOL> class ModelPermissionsView ( PageView ) : <EOL> template_name = '<STR_LIT>' <EOL> model = None <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( ModelPermissionsView , self ) . __init__ ( ** kwargs ) <EOL> assert self . model is not None , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ModelPermissionsView , self ) . get_context_data ( ** kwargs ) <EOL> model_name = self . model . _meta . model_name <EOL> context [ '<STR_LIT>' ] = model_name . capitalize ( ) <EOL> return context <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> app_label = self . model . _meta . app_label <EOL> model_name = self . model . _meta . model_name <EOL> if not request . user . has_perm ( '<STR_LIT>' % ( app_label , model_name ) ) : <EOL> raise Http404 ( ) <EOL> return super ( ModelPermissionsView , self ) . get ( request , * args , ** kwargs ) <EOL> class ObjectPermissionsView ( PageView ) : <EOL> template_name = '<STR_LIT>' <EOL> def get_object ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ObjectPermissionsView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . get_object ( ) . _meta . model_name . capitalize ( ) <EOL> context [ '<STR_LIT>' ] = kwargs . get ( '<STR_LIT>' ) <EOL> return context <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> obj = self . get_object ( ) <EOL> app_label = obj . _meta . app_label <EOL> model_name = obj . _meta . model_name <EOL> if not request . user . has_perm ( '<STR_LIT>' % ( app_label , model_name ) , obj ) : <EOL> raise Http404 ( ) <EOL> return super ( ObjectPermissionsView , self ) . get ( request , * args , ** kwargs ) </s>
