Exemplo n.º 1
0
    def post(self):
        with locks.global_lock:
            username = self.get_argument('username', None)
            password = self.get_argument('password', None)
            if username is None:
                self.write(
                    render_template('auth_error.html',
                                    error=lc.get('no_username')))
                return
            if password is None:
                self.write(
                    render_template('auth_error.html',
                                    error=lc.get('no_password')))
                return

            try:
                session = auth.authenticate_user(username, password)
            except auth.BaseAuthenticationError as e:
                self.write(
                    render_template('auth_error.html', error=lc.get(e.text)))
                return
            self.set_cookie('session_id',
                            session.id,
                            expires=session.expires_at)
            self.redirect('/')
Exemplo n.º 2
0
    def get(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None:
                self.redirect('/login')
                return
            target_team_name = self.get_argument('team', None)
            if target_team_name is None:
                self.clear()
                self.set_status(404)
                self.finish(
                    render_template('team_profile_404.html', session=session))
                return
            try:
                target_team = team.read_team(target_team_name)
            except BaseException:
                self.clear()
                self.set_status(404)
                self.finish(
                    render_template('team_profile_404.html', session=session))
                return

            self.write(
                render_template('team_profile.html',
                                session=session,
                                team=target_team,
                                tasks_module=tasks))
Exemplo n.º 3
0
    def get(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None or not session.is_admin:
                self.write(
                    render_template('admin_error.html',
                                    error=lc.get('not_admin')))
                return

            self.write(render_template('admin_new_team.html', session=session))
Exemplo n.º 4
0
 def get(self):
     with locks.global_lock:
         session_id = self.get_cookie('session_id')
         if auth.load_session(session_id) is not None:
             self.redirect('/')
             return
         if not competition.allow_team_self_registration:
             self.write(
                 render_template('reg_error.html',
                                 error=lc.get('registration_disabled')))
             return
         self.write(render_template('register.html'))
 def __call_template_pesquisa__(self, pesquisa=None, urls=None):
     title = "Pesquisa no Google Acadêmico" if pesquisa == None else "Resultado da pesquisa: " + pesquisa
     if urls != None:
         urls, urls_pdf = self.__get_pdfs_separadamente__(urls)
     options = {"title": title, "urls": urls, "urls_pdf": urls_pdf}
     result = render_template("templates/pesquisa.html", options)
     self.write(result)
Exemplo n.º 6
0
 def render(self, *args, **kwargs):
     self.controller.events.before_render(controller=self.controller)
     self.controller.response.charset = 'utf-8'
     result = template.render_template(self.get_template_names(), self.context, theme=self.theme)
     self.controller.response.unicode_body = result
     self.controller.events.after_render(controller=self.controller, result=result)
     return self.controller.response
Exemplo n.º 7
0
def run_scheduler(db, praw_id, subreddit_name, wiki_config_page, dry_run=False):
    reddit = praw.Reddit(praw_id)
    subreddit = reddit.subreddit(subreddit_name)
    wiki_config = subreddit.wiki[wiki_config_page].content_md

    config_items = list(yaml.load_all(wiki_config))

    current_time = datetime.now()

    for config in config_items:
        posts = list(db.get_saved_post_data())
        posts_by_id = {post.id: post for post in posts}
        next_post_time = datetime.strptime(config['first'], "%B %d, %Y %H:%M")
        repeat = parse_duration(config['repeat'])
        post = posts_by_id.get(config['id'])
        if post:
            while next_post_time < post.date:
                next_post_time += repeat
        if next_post_time > current_time:
            if dry_run:
                print "Not posting %s until %s" % (config['id'], next_post_time)
            continue
        post_template_data = {x['id']: "/" for x in config_items}
        post_template_data.update((post.id, "https://reddit.com/comments/%s/" % post.reddit_id) for post in posts)
        text = Template(config['text']).substitute(post_template_data)
        print "Submitting post %s" % (config['id'])
        if dry_run:
            print "I would submit the text: ", text
        else:
            reddit_post = subreddit.submit(title=render_template(config['title']), selftext=text, send_replies=False)
            reddit_post.mod.distinguish()
            if config.get('sticky', False):
                reddit_post.mod.sticky()
            db.save_post_data( Post(config['id'], current_time, reddit_post.id))
            print "Saved, post is %s" % reddit_post.id
Exemplo n.º 8
0
    def inner(request, response, exception):
        logging.exception(exception)

        response.set_status(code)

        if 'application/json' in request.headers.get(
                'Accept',
            []) or request.headers.get('Content-Type') == 'application/json':
            response.text = unicode(
                json.dumps({
                    'error': str(exception),
                    'code': code
                },
                           encoding='utf-8',
                           ensure_ascii=False))

        else:
            response.content_type = 'text/html'
            response.text = render_template(
                template, {
                    'request': request,
                    'exception': exception,
                    'code': code,
                    'is_backend': (request.path.find("/admin") == 0)
                })
Exemplo n.º 9
0
 def get(self):
     with locks.global_lock:
         session_id = self.get_cookie('session_id')
         if auth.load_session(session_id) is not None:
             self.redirect('/')
             return
         self.write(render_template('login.html'))
Exemplo n.º 10
0
    def post(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None:
                self.redirect('/login')
                return

            old_password = self.get_argument('old_password', None)
            password = self.get_argument('password', None)
            password_c = self.get_argument('password_c', None)
            if old_password is None or old_password == '':
                self.write(
                    render_template(
                        'change_password_error.html',
                        error_message=lc.get('no_old_password'),
                        session=session,
                    ))
                return
            if not auth.verify_password(session.username, old_password):
                self.write(
                    render_template(
                        'change_password_error.html',
                        error_message=lc.get('invalid_old_password'),
                        session=session,
                    ))
                return
            if password is None or password == '':
                self.write(
                    render_template(
                        'change_password_error.html',
                        error_message=lc.get('no_password'),
                        session=session,
                    ))
                return
            if password != password_c:
                self.write(
                    render_template(
                        'change_password_error.html',
                        error_message=lc.get('password_c_failed'),
                        session=session,
                    ))
                return

            auth.update_password(session.username, password)
            self.write(
                render_template('change_password_ok.html', session=session))
Exemplo n.º 11
0
 def render_response(self, response):
     text = response.get('text')
     try:
         response['orig_text'] = text
         text = render_template(text)
         response['text'] = text
     except Exception as ex:
         logger.error("Rendering template error %s", ex)
         response['text'] = ''
Exemplo n.º 12
0
    def get(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None:
                self.redirect('/login')
                return

            self.write(render_template('change_password.html',
                                       session=session))
Exemplo n.º 13
0
 def render(self, *args, **kwargs):
     self.controller.events.before_render(controller=self.controller)
     self.context.update({'theme': self.theme})
     result = template.render_template(self.get_template_names(), self.context, theme=self.theme)
     self.controller.response.content_type = 'text/html'
     self.controller.response.charset = 'utf-8'
     self.controller.response.unicode_body = result
     self.controller.response.headers["spend-time"] = str(time.time() - self.controller.request_start_time)
     self.controller.events.after_render(controller=self.controller, result=result)
     return self.controller.response
Exemplo n.º 14
0
 def get(self):
     with locks.global_lock:
         session_id = self.get_cookie('session_id')
         if auth.load_session(session_id) is None:
             self.write(
                 render_template('auth_error.html',
                                 error=lc.get('logout_no_session')))
             return
         auth.logout(session_id)
         self.clear_cookie('session_id')
         self.redirect('/')
Exemplo n.º 15
0
    def render(self, *args, **kwargs):
        self.controller.events.before_render(controller=self.controller)

        result = template.render_template(self.get_template_names(), self.context, theme=self.theme)
        self.controller.response.content_type = 'text/html'
        self.controller.response.charset = 'utf-8'
        self.controller.response.unicode_body = result

        self.controller.events.after_render(controller=self.controller, result=result)

        return self.controller.response
Exemplo n.º 16
0
 def get(self):
     with locks.global_lock:
         session = auth.load_session(self.get_cookie('session_id'))
         submissions = team.get_all_submissions()
         if session is None or not session.is_admin:
             self.write(
                 render_template('admin_error.html',
                                 error=lc.get('not_admin')))
             return
         self.write(
             render_template(
                 'admin.html',
                 session=session,
                 tasks=list(tasks.get_task_list()),
                 submissions=list(submissions),
                 teams=list(team.get_all_teams()),
                 groups=dict(tasks.get_group_dict()),
                 read_task=tasks.read_task,
                 build_group_path=tasks.build_group_path,
                 task_gen=task_gen,
             ))
Exemplo n.º 17
0
def render_file(filename, context):
    """
    Reads a template file and pases it through the template engine.

    >>> render_file('test-render-file.html', {"name":"sandy"})
    'My name is sandy'
    """
    with open("templates/" + filename) as f:

        template = f.read()

        return render_template(template, context)
Exemplo n.º 18
0
    def get(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            current_team = team.read_team(session.username)
            if session is None:
                self.redirect('/login')
                return

            self.write(
                render_template('edit_team_info.html',
                                session=session,
                                team=current_team))
Exemplo n.º 19
0
 def get(self):
     with locks.global_lock:
         session_id = self.get_cookie('session_id')
         session = auth.load_session(session_id)
         if session is None:
             self.redirect('/login')
             return
         team_list = list(team.get_all_teams())
         task_list = list(tasks.get_task_list())
         self.write(
             render_template('scoreboard.html',
                             session=session,
                             team_list=team_list,
                             task_list=task_list))
Exemplo n.º 20
0
 def call_template_listas(self, lista, sublistas, itens):
     nome_lista = lista["nome"]
     title = u"Listas Públicas: %s" % nome_lista
     slug_atual, slugs_pais = self.__get_slugs__(lista["slug"])
     options = {"title": title, "lista": lista, "itens": itens, "sublistas": sublistas, "slug_atual": slug_atual, "slugs_pais": slugs_pais,
                "user_events": self.session["user_events"] if "user_events" in self.session else None,
                 "opcao_deleta_todos_os_itens": self.opcao_deleta_todos_os_itens,
                 "opcao_deleta_a_lista": self.opcao_deleta_a_lista,
                 "opcao_deleta_um_item": self.opcao_deleta_um_item,
                 "opcao_edita_a_lista": self.opcao_edita_a_lista,
                 "opcao_edita_um_item": self.opcao_edita_um_item
     }
     result = render_template("listas.html", options)
     self.write(result)
Exemplo n.º 21
0
    def post(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None:
                self.redirect('/login')
                return

            disp_name = self.get_argument('disp_name', None)
            email = self.get_argument('email', None)
            if disp_name is None or disp_name == '':
                self.write(
                    render_template(
                        'edit_team_info_error.html',
                        error_message=lc.get('no_disp_name'),
                        session=session,
                    ))
                return
            tm = team.read_team(session.username)
            tm.full_name = disp_name
            tm.email = email if email != '' else None
            team.write_team(tm)
            self.write(
                render_template('edit_team_info_ok.html', session=session))
Exemplo n.º 22
0
    def post(self):
        with locks.global_lock:
            if not competition.allow_team_self_registration:
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('registration_disabled')))
            username = self.get_argument('username', None)
            password = self.get_argument('password', None)
            password_c = self.get_argument('password-c', None)
            disp_name = self.get_argument('disp-name', None)
            email = self.get_argument('email', None)

            if username is None or username == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_username')))
                return
            if password is None or password == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_password')))
                return
            if password != password_c:
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('password_c_failed')))
                return
            if disp_name is None or disp_name == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_disp_name')))
                return
            if username in auth.get_user_list():
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('user_already_exists')))
                return

            try:
                auth.register_user(username=username,
                                   password=password,
                                   disp_name=disp_name,
                                   email=email)
            except auth.BaseRegistrationError as e:
                self.write(
                    render_template('reg_error.html', error=lc.get(e.text)))
                return
            self.redirect('/')
Exemplo n.º 23
0
 def get(self):
     with locks.global_lock:
         session_id = self.get_cookie('session_id')
         session = auth.load_session(session_id)
         if session is None:
             self.redirect('/login')
             return
         task_list = list(
             task_gen.get_generated_task_list(team_name=session.username))
         current_team = team.read_team(session.username)
         hint_purchases = tasks.get_hint_puchases_for_team(session.username)
         self.write(
             render_template(
                 'tasks.html',
                 session=session,
                 tasks=task_list,
                 team=current_team,
                 hint_purchases=hint_purchases,
                 get_token=task_gen.get_token.__get__(session.username),
             ))
Exemplo n.º 24
0
    def post(self):
        with locks.global_lock:
            session_id = self.get_cookie('session_id')
            session = auth.load_session(session_id)
            if session is None or not session.is_admin:
                self.write(
                    render_template('admin_error.html',
                                    error=lc.get('not_admin')))
                return
            username = self.get_argument('username', None)
            password = self.get_argument('password', None)
            password_c = self.get_argument('password-c', None)
            disp_name = self.get_argument('disp-name', None)
            email = self.get_argument('email', None)
            is_admin = self.get_argument('is_admin', None)

            if is_admin is not None and is_admin not in ['on', 'off']:
                self.write(
                    render_template(
                        'reg_error.html',
                        error=lc.get('api_invalid_data_type').format(
                            param='is_admin',
                            expected=lc.get('bool'),
                        )))
                return
            if is_admin == 'on':
                is_admin = True
            else:
                is_admin = False

            if username is None or username == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_username')))
                return
            if password is None or password == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_password')))
                return
            if disp_name is None or disp_name == '':
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('no_disp_name')))
                return
            if password != password_c:
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('password_c_failed')))
                return
            if username in auth.get_user_list():
                self.write(
                    render_template('reg_error.html',
                                    error=lc.get('user_already_exists')))
                return

            try:
                auth.register_user(
                    username=username,
                    password=password,
                    disp_name=disp_name,
                    email=email,
                    is_admin=is_admin,
                )
            except auth.BaseRegistrationError as e:
                self.write(
                    render_template('reg_error.html', error=lc.get(e.text)))
                return
            self.redirect('/admin')
Exemplo n.º 25
0
def notfound(path=None, create=True):
    path = path or web.ctx.path
    html = template.render_template("notfound", path, create=create)
    return web.notfound(render_site(config.site, html))
Exemplo n.º 26
0
def notfound(path = None, create = True):
    path = path or web.ctx.path
    html = template.render_template("notfound", path, create = create)
    return web.notfound(render_site(config.site, html))
Exemplo n.º 27
0
render_template(
    "index.html",
    graphs={
        "confirmed_cases": uk_cases_graph(uk_cases),
        #        "deaths": england_deaths(phe_deaths, excess_deaths, uk_cases),
        "regional_cases": regional_cases(nhs_region_cases),
        "regional_deaths": regional_deaths(nhs_deaths),
        "triage_online": triage_graph(triage_online, "Online triage"),
        "triage_pathways": triage_graph(triage_pathways, "Phone triage"),
        "hospital_admissions": hospital_admissions_graph(hospital_admissions),
        "age_heatmap": age_heatmap(age_rate),
    },
    scores=calculate_score(
        nhs_deaths,
        nhs_region_cases,
        triage_online,
        triage_pathways,
        hospital_admissions,
    ),
    sources=[
        (
            "Public Health England",
            "Coronavirus (COVID-19) in the UK",
            "https://coronavirus.data.gov.uk",
            uk_cases.attrs["date"],
        ),
        (
            "Public Health England",
            "National COVID-19 surveillance report",
            "https://www.gov.uk/government/publications/national-covid-19-surveillance-reports",
            f"Week {age_rate.index.max() + 1}",
        ),
        #        (
        #            "ONS",
        #            "Deaths registered weekly in England and Wales, provisional",
        #            "https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages"
        #            "/deaths/datasets/weeklyprovisionalfiguresondeathsregisteredinenglandandwales",
        #            date(2020, 7, 28),
        #        ),
        (
            "NHS",
            "Potential COVID-19 symptoms reported through NHS Pathways and 111 online",
            "https://digital.nhs.uk/data-and-information/publications/statistical"
            "/mi-potential-covid-19-symptoms-reported-through-nhs-pathways-and-111-online",
            pd.Timestamp(triage_online["date"].max().item(0)).date(),
        ),
        (
            scot_data.attrs["source"],
            "Coronavirus - COVID-19 - Management Information",
            scot_data.attrs["source_url"],
            scot_data.attrs["date"],
        ),
    ],
)
Exemplo n.º 28
0
render_template(
    "index.html",
    graphs={
        "confirmed_cases": uk_cases_graph(uk_cases_combined, ecdc_cases),
        "deaths": england_deaths(uk_cases, excess_deaths),
        "regional_cases": regional_cases(nhs_region_cases),
        "regional_deaths": regional_deaths(nhs_deaths),
        "triage_online": triage_graph(triage_online, "Online triage"),
        "triage_pathways": triage_graph(triage_pathways, "Phone triage"),
    },
    scores=calculate_score(nhs_deaths, nhs_region_cases, triage_online,
                           triage_pathways, None),
    sources=[
        (
            "European Centres for Disease Control",
            "Data on the geographic distribution of COVID-19 cases worldwide",
            "https://www.ecdc.europa.eu/en/publications-data/"
            "download-todays-data-geographic-distribution-covid-19-cases-worldwide",
            ecdc_cases.attrs["date"] if ecdc_cases else "Data unavailable",
        ),
        (
            "Public Health England",
            "Coronavirus (COVID-19) in the UK",
            "https://coronavirus.data.gov.uk",
            uk_cases.attrs["date"],
        ),
        (
            "ONS",
            "Deaths registered weekly in England and Wales, provisional",
            "https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages"
            "/deaths/datasets/weeklyprovisionalfiguresondeathsregisteredinenglandandwales",
            date(2020, 6, 23),
        ),
        (
            "NHS",
            "Potential COVID-19 symptoms reported through NHS Pathways and 111 online",
            "https://digital.nhs.uk/data-and-information/publications/statistical"
            "/mi-potential-covid-19-symptoms-reported-through-nhs-pathways-and-111-online",
            pd.Timestamp(triage_online["date"].max().item(0)).date(),
        ),
        (
            scot_data.attrs["source"],
            "Coronavirus - COVID-19 - Management Information",
            scot_data.attrs["source_url"],
            scot_data.attrs["date"],
        ),
        (
            wales_by_gss.attrs["source"],
            "Rapid COVID-19 Surveillance",
            wales_by_gss.attrs["source_url"],
            wales_by_gss.attrs["date"],
        ),
    ],
)
 def __call_template_propriedades__(self, resultado):
     options = {"resultado": resultado}
     result = render_template("templates/propriedades.html", options)
     self.write(result)
Exemplo n.º 30
0
 def on_get(self, req, resp):
     resp.status = falcon.HTTP_200
     resp.content_type = 'text/html'
     paragraphs = get_paragraphs('/home/sanchopanca/Documents/thunder.txt')
     resp.body = template.render_template('book.html',
                                          paragraphs=paragraphs)
Exemplo n.º 31
0
 def get(self):
     with locks.global_lock:
         self.write(
             render_template('index.html',
                             session=auth.load_session(
                                 self.get_cookie('session_id'))))
Exemplo n.º 32
0
	def get(self):
		title = u"Listas Públicas - Home"
		options = {"title": title}
		result = render_template("home.html", options)
		self.write(result)