def render(view_type=None, login=None, code=None): """ Renders the login HTML. Exits. """ # init the settings object settings = utils.load_settings() template_file_path = "templates/login.html" if view_type == 'reset': template_file_path = 'templates/reset_password.html' # grab up the template html_raw = file(template_file_path, "rb").read() html_tmp = Template(html_raw) # create the output output = html.meta.basic_http_header output += html_tmp.safe_substitute( version=settings.get('application', 'version'), title=settings.get('application', 'title'), api_url=api.get_api_url(), prod_url=settings.get('application', 'tld'), released=utils.get_latest_update_string(), login=login, code=code, ) logger = utils.get_logger() # render; don't exit (in case we're metering performance) print(output)
def render_dashboard(self): """ Renders the user's dashboard. Leans heavily on the AngularJS app calling on the API for data, etc.""" output = html.dashboard.angular_app.safe_substitute( application_version=settings.get("application", "version"), api_url=api.get_api_url(), user_id=self.User.user["_id"], ) return output
def render_dashboard(self): """ Renders the user's dashboard. Leans heavily on the AngularJS app calling on the API for data, etc.""" # initialize the angular APP output = html.dashboard.initializer.safe_substitute( application_version = settings.get("application","version"), api_url = api.get_api_url(), user_id = self.User.user["_id"], ) # do the settings block (transitional) output += self.User.html_motd() # do the campaign/settlement inventory for the user output += html.dashboard.angular_app if self.User.is_admin(): output += html.dashboard.panel_button return output
def render_html(self): """ Renders the whole panel. """ try: World = api.route_to_dict("world") W = World["world"] meta = World["meta"] except Exception as e: return "World could not be loaded! %s" % e daemon_block = '<table class="admin_panel_right_child">' daemon_block += '<tr><th colspan="2">World Daemon</th></tr>' for k, v in World["world_daemon"].iteritems(): if type(v) == dict: raw = v["$date"] dt = datetime.fromtimestamp(raw/1000) daemon_block += '<tr><td>%s</td><td>%s</td></tr>' % (k,dt) else: daemon_block += '<tr><td>%s</td><td>%s</td></tr>' % (k,v) daemon_block += "</table>" response_block = '<table class="admin_panel_right_child">' response_block += '<tr><th colspan="4">Response Times</th></tr>' response_block += '<tr><td><i>View</i></td><td><i>#</i></td><td><i>Avg.</i></td><td><i>Max</i></td></tr>' for r in get_response_times(): response_block += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (r["_id"],r["count"],r["avg_time"],r["max_time"]) response_block += "</table>" admins_block = '<table class="admin_panel_right_child">' admins_block += '<tr><th colspan="2">Administrators</th></tr>' admins = mdb.users.find({"admin":{"$exists":True}}) for a in admins: admins_block += '<tr><td>%s</td><td>%s</td></tr>' % (a["login"],a["_id"]) admins_block += '</table>' stat_block = '<table class="admin_panel_right_child">' stat_block += '<tr><th colspan="2">Environment</th></tr>' stat_block += '<tr><td>Host</td><td>%s</td></tr>' % socket.getfqdn() stat_block += '<tr><td>Application version</td><td>%s</td></tr>' % settings.get("application","version") stat_block += '<tr><td>Release</td><td>%s</td></tr>' % get_latest_update_string() stat_block += '<tr><td>API URL</td><td>%s</td></tr>' % api.get_api_url() stat_block += '<tr><td>API admin panel</td><td><a href="%sadmin">%sadmin</a></td></tr>' % (api.get_api_url(), api.get_api_url()) stat_block += '<tr><td>API Version</td><td>%s</td></tr>' % meta["api"]["version"] stat_block += '</table>' output = html.panel.headline.safe_substitute( response_times = response_block, world_daemon = daemon_block, recent_users_count = self.recent_users.count(), users = W["total_users"]["value"], sessions = mdb.sessions.find().count(), settlements = mdb.settlements.find().count(), total_survivors = W["total_survivors"]["value"], live_survivors = W["live_survivors"]["value"], dead_survivors = W["dead_survivors"]["value"], complete_death_records = mdb.the_dead.find({"complete": {"$exists": True}}).count(), latest_fatality = world.api_survivor_to_html(W["latest_fatality"]), latest_settlement = world.api_settlement_to_html(W["latest_settlement"]), latest_kill = world.api_monster_to_html(W["latest_kill"]), current_hunt = world.api_current_hunt(W["current_hunt"]), admin_stats = stat_block, admins = admins_block, ) for user in self.recent_users: User = assets.User(user_id=user["_id"], session_object=self.Session) # create settlement summaries settlements = mdb.settlements.find({"created_by": User.user["_id"]}).sort("name") settlement_strings = [] for s in settlements: S = assets.Settlement(settlement_id=s["_id"], session_object=self.Session, update_mins=False) settlement_strings.append(S.render_admin_panel_html()) output += html.panel.user_status_summary.safe_substitute( user_name = User.user["login"], u_id = User.user["_id"], ua = User.user["latest_user_agent"], latest_sign_in = User.user["latest_sign_in"].strftime(ymdhms), latest_sign_in_mins = (datetime.now() - User.user["latest_sign_in"]).seconds // 60, session_length = (User.user["latest_activity"] - User.user["latest_sign_in"]).seconds // 60, latest_activity = User.user["latest_activity"].strftime(ymdhms), latest_activity_mins = (datetime.now() - User.user["latest_activity"]).seconds // 60, latest_action = User.user["latest_action"], settlements = "<br/>".join(settlement_strings), survivor_count = mdb.survivors.find({"created_by": User.user["_id"]}).count(), user_created_on = User.user["created_on"].strftime(ymd), user_created_on_days = (datetime.now() - User.user["created_on"]).days ) output += "<hr/>" log_lines = self.get_last_n_log_lines(50) zebra = False for l in reversed(log_lines): if zebra: output += html.panel.log_line.safe_substitute(line=l, zebra=zebra) zebra = False else: output += html.panel.log_line.safe_substitute(line=l) zebra = "grey" output += html.meta.hide_full_page_loader return output
def current_view_html(self, body=None): """ This func uses session's 'current_view' attribute to render the html for that view. A view's HTML does NOT include header/footer type elements. Rather, it involes a container element that contains all the user controls, and then, outside of/beneath the container element, all of the 'modal' UI stuff that a user might need in a view. In this method then, we use the current view to figure out what to put in the container and what to append to the container. The whole thing is decorated in a function that captures failures and asks users to report them (and kills their session, logging them out, so they don't get stuck in a state where they can't stop re-creating the error, etc. """ # set the current view and settlement, if possible self.get_current_view() if not hasattr(self, "Settlement") or self.Settlement is None: self.set_current_settlement() include_ui_templates = True # start the container output = html.meta.start_container # now get us some HTML if self.current_view == "dashboard": body = "dashboard" include_ui_templates = False output += html.get_template('dashboard') elif self.current_view == "new_settlement": body = 'create_new_settlement' output += html.get_template('new_settlement.html') elif self.current_view == "view_campaign": body = 'view_campaign_summary' output += html.get_template('campaign_summary') elif self.current_view == "view_settlement": body = 'view_settlement_sheet' output += html.get_template('settlement_sheet') elif self.current_view == "view_survivor": body = 'view_survivor_sheet' output += html.get_template('survivor_sheet') else: self.logger.error("[%s] requested unhandled view '%s'" % (self.User, self.current_view)) raise Exception("Unknown View!") # now close the container output += html.meta.close_container # add UI templates if include_ui_templates: for t in settings.get('application', 'ui_templates').split(','): output += html.get_template(t.strip()) # finally, do a single, monster variable substitution pass: output = Template(output).safe_substitute( api_url=api.get_api_url(), application_version=settings.get("application", "version"), user_id=self.User.user['_id'], user_login=self.User.user["login"], settlement_id=self.session['current_settlement'], survivor_id=self.session.get('current_asset', None), ) return output, body