def post_banner():
    if request.form.get("delete"):
        # Handle remove scenario
        logger.info("Removing active status from banner",
                    user=current_username())
        admin_controller.remove_banner()
        flash("The alert has been removed")
        return redirect(url_for("admin_bp.get_banner_admin"))

    # Handle create scenario
    form = BannerPublishForm(form=request.form)
    if form.validate():
        banner_text = form.banner_text.data
        session["banner-text"] = banner_text
        return redirect(url_for("admin_bp.get_banner_confirm_publish"))

    breadcrumbs = [{"text": "Banner Admin", "url": ""}]
    all_templates = get_templates()
    return render_template(
        "admin/banner-manage.html",
        form=form,
        list_of_templates=all_templates,
        breadcrumbs=breadcrumbs,
        errors=form.errors.items(),
    )
def get_message_template():
    """
    This endpoint, by the design we were given, renders message template view in text only mode.
    """
    breadcrumbs = [{"text": "Alert Admin", "url": ""}]
    logger.info("Message template page accessed", user=current_username())
    all_templates = get_templates()
    return render_template('admin/banner-view-message-template.html',
                           list_of_templates=all_templates,
                           breadcrumbs=breadcrumbs)
Example #3
0
 def test_get_templates_success(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET,
                  url_template,
                  json=templates_response,
                  status=200,
                  content_type='application/json')
         with self.app.app_context():
             response = admin_controller.get_templates()
             self.assertEqual(response, templates_response)
def manage_alert():
    logger.info("Managing banner templates", user=current_username())
    form = BannerManageForm(form=request.form)
    if form.validate_on_submit():
        template_id = form.template_id.data
        return redirect(
            url_for("admin_bp.get_post_edit_template", banner_id=template_id))

    all_templates = get_templates()
    return render_template('admin/template-manage.html',
                           form=form,
                           list_of_templates=all_templates,
                           errors=form.errors.items())
def get_banner_admin():
    """
    This endpoint, by the design we were given, renders one of two different screens.  Either a 'create' screen if
    there isn't a banner set yet, or a 'remove' screen if there is one.
    """
    breadcrumbs = [{"text": "Alert Admin", "url": ""}]
    current_banner_json = admin_controller.current_banner()
    logger.info("Banner page accessed", user=current_username())
    if current_banner_json:
        # Handle remove scenario
        form = BannerDeleteForm()
        return render_template('admin/banner-remove.html',
                               form=form,
                               current_banner=current_banner_json['content'],
                               breadcrumbs=breadcrumbs)
    # Handle create scenario
    form = BannerPublishForm()
    all_templates = get_templates()
    return render_template('admin/banner-manage.html',
                           form=form,
                           list_of_templates=all_templates,
                           breadcrumbs=breadcrumbs)
Example #6
0
 def test_get_templates_server_error(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, url_template, status=500)
         with self.app.app_context():
             with self.assertRaises(ApiError):
                 admin_controller.get_templates()