def action_index(self, keyword=None): """ GET, POST & parameter usage example. This function is automatically routed to: http://localhost:8080/example/pokemon/parameter """ # get keyword if 'keyword' in request.GET: keyword = request.GET['keyword'] elif 'keyword' in request.POST: keyword = request.POST['keyword'] if keyword is None: keyword = '' # get action action = '' if 'action' in request.POST: action = request.POST['action'] # get data private_code = '' pokemon_id = '' pokemon_name = '' if 'pokemon_id' in request.POST: pokemon_id = request.POST['pokemon_id'] if 'pokemon_name' in request.POST: pokemon_name = request.POST['pokemon_name'] # rely on private_code and keep calm on accidental refresh if '__private_code' in request.POST: private_code = request.POST['__private_code'] elif '__private_code' in request.GET: private_code = request.GET['__private_code'] # do the action if '__private_code' in request.SESSION and private_code == request.SESSION['__private_code']: # upload image if action == 'add' or action == 'edit': pokemon_image = self.upload_image() # save the data if action == 'add': self.db_model.insert_pokemon(pokemon_name, pokemon_image) elif action == 'edit': self.db_model.update_pokemon(pokemon_id, pokemon_name, pokemon_image) elif action == 'delete': row = self.db_model.get_pokemon_by_id(pokemon_id) if row != False: image = row.image remove_asset(os.path.join('uploads', image), 'example') self.db_model.delete_pokemon(pokemon_id) private_code = self.generate_private_code() # get pokemons pokemon_list = self.db_model.get_pokemon(keyword) return load_view('example', 'pokemon', pokemon_list=pokemon_list, __private_code = private_code)
def action_index(self): url_list = { 'Group' : base_url('cms/group'), 'Third Party Authenticator' : base_url('cms/third_party_authenticator'), 'Page' : base_url('cms/page'), 'Theme' : base_url('cms/theme'), 'Layout' : base_url('cms/layout'), 'Widget' : base_url('cms/widget'), 'User' : base_url('cms/user'), 'Language' : base_url('cms/language'), 'Configuration' : base_url('cms/configuration') } return load_view('cms', 'index', url_list = url_list)
def error_500(error): import random error_messages = [ 'Something goes wrong', 'No no no... Not again...', 'Congratulation, you have just found an error !!!', ] message_index = random.randrange(0,len(error_messages)) error_message = error_messages[message_index] data = { 'error_title' : '500, Internal Server Error', 'error_message' : error_message, } return load_view('index','error', data = data)
def error_403(error): import random error_messages = [ 'You have just landed at area 51', 'No, you cannot access this, Cowboy !!!', 'Restricted, you must be 200 years old to access this page', ] message_index = random.randrange(0,len(error_messages)) error_message = error_messages[message_index] data = { 'error_title' : '403, Forbidden', 'error_message' : error_message, } return load_view('index','error', data = data)
def error_404(error): import random error_messages = [ 'Sorry, but there is no gray elephant in Pacific', 'Has you correctly write the URL?', 'Go home you are drunk !!!', ] message_index = random.randrange(0,len(error_messages)) error_message = error_messages[message_index] data = { 'error_title' : '404, Page not found', 'error_message' : error_message, } return load_view('index','error', data = data)
def _load_view(self, view): if os.path.exists(application_path(os.path.join(self.__application_name__, 'views', self.__model_name__, view))): # normal load_view (if view exists) content = load_view(self.__application_name__, self.__model_name__ + '/' + view, **self._get_view_parameter()) else: # take default key content content = '' content = file_get_contents(os.path.join(os.path.dirname(__file__), 'views', view + '.html')) content = content.replace('G_Table_Name', self.__model_name__.title()) content = content.replace('g_table_name', self.__model_name__) content = content.replace('g_application_name', self.__application_name__) # do load_template content = load_template(content, **self._get_view_parameter()) return self.preprocess_content(content)
def action_index(self): return load_view('example', 'classification', classifiers = self.classifiers)
def index(): return load_view("index", "index.html", active_page="home")
def action_index(self): url_list = { # g_url_pairs } return load_view('g_application_name', 'index', url_list = url_list)
def action_index(self): import json return load_view('example', 'classification', classifiers = self.classifiers, json_classifiers = json.dumps(self.classifiers))
def index(): return load_view('index', 'index.html', active_page = 'home')
def action_index(self): return load_view('example', 'index')
def action_form_edit_pokemon(self, pokemon_id): pokemon = self.db_model.get_pokemon_by_id(pokemon_id) private_code = self.generate_private_code() return load_view('example','pokemon_edit_form', pokemon=pokemon, __private_code = private_code)
def action_form_add_pokemon(self): private_code = self.generate_private_code() return load_view('example', 'pokemon_add_form', __private_code = private_code)
def load_view(self, application_name, view_name, *args, **kwargs): # get content content = load_view(application_name, view_name, *args, **kwargs) # preprocess return self.preprocess_content(content)
def getting_started(): return load_view('index', 'getting_started.html', active_page = 'getting_started')
def action_index(self): return load_view('example','plotting')