def get(self, task_name): try: task = self.contest.get_task(task_name) except KeyError: raise tornado.web.HTTPError(404) for statement in itervalues(task.statements): lang_code = statement.language if is_language_country_code(lang_code): statement.language_name = \ translate_language_country_code(lang_code, self.locale) elif is_language_code(lang_code): statement.language_name = \ translate_language_code(lang_code, self.locale) elif is_country_code(lang_code): statement.language_name = \ translate_country_code(lang_code, self.locale) else: statement.language_name = lang_code self.r_params["primary_statements"] = task.primary_statements try: self.r_params["user_primary"] = \ self.current_user.user.preferred_languages except ValueError as e: self.r_params["user_primary"] = [] logger.error("Preferred languages for user %s is invalid [%r].", self.current_user.user.username, e) self.render("task_description.html", task=task, **self.r_params)
def get(self, task_name): try: task = self.contest.get_task(task_name) except KeyError: raise tornado.web.HTTPError(404) for statement in task.statements.itervalues(): lang_code = statement.language if is_language_country_code(lang_code): statement.language_name = \ translate_language_country_code(lang_code, self.locale) elif is_language_code(lang_code): statement.language_name = \ translate_language_code(lang_code, self.locale) elif is_country_code(lang_code): statement.language_name = \ translate_country_code(lang_code, self.locale) else: statement.language_name = lang_code self.render("task_description.html", task=task, **self.r_params)
def get(self, task_name): try: task = self.contest.get_task(task_name) except KeyError: raise tornado.web.HTTPError(404) if self.contest.restrict_level and self.current_user.user.level != task.level and self.current_user.user.level != "x" and task.level != "x": raise tornado.web.HTTPError(404) for statement in task.statements.itervalues(): lang_code = statement.language if is_language_country_code(lang_code): statement.language_name = \ translate_language_country_code(lang_code, self.locale) elif is_language_code(lang_code): statement.language_name = \ translate_language_code(lang_code, self.locale) elif is_country_code(lang_code): statement.language_name = \ translate_country_code(lang_code, self.locale) else: statement.language_name = lang_code try: self.r_params["primary_statements"] = \ json.loads(task.primary_statements) except ValueError as e: self.r_params["primary_statements"] = [] logger.error("Primary statements for task %s is invalid [%r].", task_name, e) try: self.r_params["user_primary"] = \ json.loads(self.current_user.user.preferred_languages) except ValueError as e: self.r_params["user_primary"] = [] logger.error("Preferred languages for user %s is invalid [%r].", self.current_user.user.username, e) self.render("task_description.html", task=task, **self.r_params)
def render_params(self): ret = super(ContestHandler, self).render_params() ret["contest"] = self.contest if hasattr(self, "contest_url"): ret["contest_url"] = self.contest_url ret["phase"] = self.contest.phase(self.timestamp) ret["printing_enabled"] = (config.printer is not None) ret["questions_enabled"] = self.contest.allow_questions ret["testing_enabled"] = self.contest.allow_user_tests if self.current_user is not None: participation = self.current_user res = compute_actual_phase( self.timestamp, self.contest.start, self.contest.stop, self.contest.analysis_start if self.contest.analysis_enabled else None, self.contest.analysis_stop if self.contest.analysis_enabled else None, self.contest.per_user_time, participation.starting_time, participation.delay_time, participation.extra_time) ret["actual_phase"], ret["current_phase_begin"], \ ret["current_phase_end"], ret["valid_phase_begin"], \ ret["valid_phase_end"] = res if ret["actual_phase"] == 0: ret["phase"] = 0 # set the timezone used to format timestamps ret["timezone"] = get_timezone(participation.user, self.contest) # some information about token configuration ret["tokens_contest"] = self._get_token_status(self.contest) t_tokens = sum(self._get_token_status(t) for t in self.contest.tasks) if t_tokens == 0: ret["tokens_tasks"] = 0 # all disabled elif t_tokens == 2 * len(self.contest.tasks): ret["tokens_tasks"] = 2 # all infinite else: ret["tokens_tasks"] = 1 # all finite or mixed # TODO Now all language names are shown in the active language. # It would be better to show them in the corresponding one. ret["lang_names"] = {} # Get language codes for allowed localizations lang_codes = self.langs.keys() if len(self.contest.allowed_localizations) > 0: lang_codes = filter_language_codes( lang_codes, self.contest.allowed_localizations) for lang_code, trans in self.langs.iteritems(): language_name = None # Filter lang_codes with allowed localizations if lang_code not in lang_codes: continue try: language_name = translate_language_country_code( lang_code, trans) except ValueError: language_name = translate_language_code( lang_code, trans) ret["lang_names"][lang_code.replace("_", "-")] = language_name ret["cookie_lang"] = self.cookie_lang ret["browser_lang"] = self.browser_lang return ret
def render_params(self): """Return the default render params used by almost all handlers. return (dict): default render params """ ret = {} ret["timestamp"] = self.timestamp ret["contest"] = self.contest ret["url_root"] = get_url_root(self.request.path) ret["phase"] = self.contest.phase(self.timestamp) ret["printing_enabled"] = (config.printer is not None) ret["questions_enabled"] = self.contest.allow_questions ret["testing_enabled"] = self.contest.allow_user_tests if self.current_user is not None: participation = self.current_user res = compute_actual_phase(self.timestamp, self.contest.start, self.contest.stop, self.contest.per_user_time, participation.starting_time, participation.delay_time, participation.extra_time) ret["actual_phase"], ret["current_phase_begin"], \ ret["current_phase_end"], ret["valid_phase_begin"], \ ret["valid_phase_end"] = res if ret["actual_phase"] == 0: ret["phase"] = 0 # set the timezone used to format timestamps ret["timezone"] = get_timezone(participation.user, self.contest) # some information about token configuration ret["tokens_contest"] = self._get_token_status(self.contest) t_tokens = sum(self._get_token_status(t) for t in self.contest.tasks) if t_tokens == 0: ret["tokens_tasks"] = 0 # all disabled elif t_tokens == 2 * len(self.contest.tasks): ret["tokens_tasks"] = 2 # all infinite else: ret["tokens_tasks"] = 1 # all finite or mixed # TODO Now all language names are shown in the active language. # It would be better to show them in the corresponding one. ret["lang_names"] = {} # Get language codes for allowed localizations lang_codes = self.langs.keys() if len(self.contest.allowed_localizations) > 0: lang_codes = filter_language_codes( lang_codes, self.contest.allowed_localizations) for lang_code, trans in self.langs.iteritems(): language_name = None # Filter lang_codes with allowed localizations if lang_code not in lang_codes: continue try: language_name = translate_language_country_code( lang_code, trans) except ValueError: language_name = translate_language_code(lang_code, trans) ret["lang_names"][lang_code.replace("_", "-")] = language_name ret["cookie_lang"] = self.cookie_lang ret["browser_lang"] = self.browser_lang if self.current_user is not None: tree_menu = {'childs': {}, 'tasks': []} for t in self.contest.tasks: if not self.contest.restrict_level or self.current_user.user.level == t.level or self.current_user.user.level == "x" or t.level == "x": node = tree_menu if t.category: for subcat in t.category.split('.'): if subcat not in node['childs']: node['childs'][subcat] = { 'childs': {}, 'tasks': [] } node = node['childs'][subcat] node['tasks'].append(t) def make_list(tree, result, ancname="root"): for name in sorted(tree['childs']): fullname = ancname + '.' + name result.append({ 'type': 'startcat', 'name': name, 'fullname': fullname, 'parent': ancname }) make_list(tree['childs'][name], result, fullname) result.append({'type': 'endcat'}) for t in sorted(tree['tasks'], key=lambda t: t.name): result.append({ 'type': 'task', 'task': t, 'parent': ancname }) ret['list_tree_menu'] = [] make_list(tree_menu, ret['list_tree_menu']) return ret
def render_params(self): """Return the default render params used by almost all handlers. return (dict): default render params """ ret = {} ret["timestamp"] = self.timestamp ret["contest"] = self.contest ret["url_root"] = get_url_root(self.request.path) ret["phase"] = self.contest.phase(self.timestamp) ret["printing_enabled"] = (config.printer is not None) if self.current_user is not None: participation = self.current_user res = compute_actual_phase( self.timestamp, self.contest.start, self.contest.stop, self.contest.per_user_time, participation.starting_time, participation.delay_time, participation.extra_time) ret["actual_phase"], ret["current_phase_begin"], \ ret["current_phase_end"], ret["valid_phase_begin"], \ ret["valid_phase_end"] = res if ret["actual_phase"] == 0: ret["phase"] = 0 # set the timezone used to format timestamps ret["timezone"] = get_timezone(participation.user, self.contest) # some information about token configuration ret["tokens_contest"] = self._get_token_status(self.contest) t_tokens = sum(self._get_token_status(t) for t in self.contest.tasks) if t_tokens == 0: ret["tokens_tasks"] = 0 # all disabled elif t_tokens == 2 * len(self.contest.tasks): ret["tokens_tasks"] = 2 # all infinite else: ret["tokens_tasks"] = 1 # all finite or mixed # TODO Now all language names are shown in the active language. # It would be better to show them in the corresponding one. ret["lang_names"] = {} for lang_code, trans in self.langs.iteritems(): language_name = None try: language_name = translate_language_country_code( lang_code, trans) except ValueError: language_name = translate_language_code( lang_code, trans) ret["lang_names"][lang_code.replace("_", "-")] = language_name ret["cookie_lang"] = self.cookie_lang ret["browser_lang"] = self.browser_lang return ret
def render_params(self): """Return the default render params used by almost all handlers. return (dict): default render params """ ret = {} ret["timestamp"] = self.timestamp ret["contest"] = self.contest ret["url_root"] = get_url_root(self.request.path) ret["phase"] = self.contest.phase(self.timestamp) ret["printing_enabled"] = (config.printer is not None) ret["questions_enabled"] = self.contest.allow_questions ret["testing_enabled"] = self.contest.allow_user_tests if self.current_user is not None: participation = self.current_user res = compute_actual_phase( self.timestamp, self.contest.start, self.contest.stop, self.contest.per_user_time, participation.starting_time, participation.delay_time, participation.extra_time) ret["actual_phase"], ret["current_phase_begin"], \ ret["current_phase_end"], ret["valid_phase_begin"], \ ret["valid_phase_end"] = res if ret["actual_phase"] == 0: ret["phase"] = 0 # set the timezone used to format timestamps ret["timezone"] = get_timezone(participation.user, self.contest) # some information about token configuration ret["tokens_contest"] = self._get_token_status(self.contest) t_tokens = sum(self._get_token_status(t) for t in self.contest.tasks) if t_tokens == 0: ret["tokens_tasks"] = 0 # all disabled elif t_tokens == 2 * len(self.contest.tasks): ret["tokens_tasks"] = 2 # all infinite else: ret["tokens_tasks"] = 1 # all finite or mixed # TODO Now all language names are shown in the active language. # It would be better to show them in the corresponding one. ret["lang_names"] = {} # Get language codes for allowed localizations lang_codes = self.langs.keys() if len(self.contest.allowed_localizations) > 0: lang_codes = filter_language_codes( lang_codes, self.contest.allowed_localizations) for lang_code, trans in self.langs.iteritems(): language_name = None # Filter lang_codes with allowed localizations if lang_code not in lang_codes: continue try: language_name = translate_language_country_code( lang_code, trans) except ValueError: language_name = translate_language_code( lang_code, trans) ret["lang_names"][lang_code.replace("_", "-")] = language_name ret["cookie_lang"] = self.cookie_lang ret["browser_lang"] = self.browser_lang if self.current_user is not None: tree_menu = {'childs':{}, 'tasks': []} for t in self.contest.tasks: if not self.contest.restrict_level or self.current_user.user.level == t.level or self.current_user.user.level == "x" or t.level == "x": node = tree_menu if t.category: for subcat in t.category.split('.'): if subcat not in node['childs']: node['childs'][subcat] = {'childs':{}, 'tasks': []} node = node['childs'][subcat] node['tasks'].append(t) def make_list(tree, result, ancname="root"): for name in sorted(tree['childs']): fullname = ancname+'.'+name result.append({'type': 'startcat', 'name' : name, 'fullname' : fullname, 'parent' : ancname}) make_list(tree['childs'][name], result, fullname) result.append({'type': 'endcat'}) for t in sorted(tree['tasks'], key=lambda t: t.name): result.append({'type': 'task', 'task' : t, 'parent' : ancname}) ret['list_tree_menu'] = [] make_list(tree_menu, ret['list_tree_menu']) return ret