def get(self):

    sql_statement= """
      SELECT `t0`.`id` AS `lev0_id`, `t0`.`name_french` AS `lev0_name_fr`, `t0`.`name_english` AS `lev0_name_en`, `t1`.`id` AS `lev1_id`, `t1`.`name_french` AS `lev1_name_fr`, `t1`.`name_english` AS `lev1_name_en`, `t1`.`name_safe_short` AS `lev1_name_short`, `t1`.`access` AS `lev1_access`, `t1`.`html_form_type` AS `lev1_type`, `t2`.`id` AS `lev2_id`, `t2`.`name_french` AS `lev2_name_fr`, `t2`.`name_english` AS `lev2_name_en`, `t2`.`name_safe_short` AS `lev2_name_short`, `t2`.`access` AS `lev2_access`, `t2`.`html_form_type` AS `lev2_type`, `t3`.`id` AS `lev3_id`, `t3`.`name_french` AS `lev3_name_fr`, `t3`.`name_english` AS `lev3_name_en`, `t3`.`name_safe_short` AS `lev3_name_short`, `t3`.`access` AS `lev3_access`, `t3`.`html_form_type` AS `lev3_type`
      FROM `section` AS `t0`
      LEFT JOIN `attribute` AS `t1` ON `t1`.`section_id` = `t0`.`id`
      LEFT JOIN `attribute` AS `t2` ON `t2`.`parent_id` = `t1`.`id`
      LEFT JOIN `attribute` AS `t3` ON `t3`.`parent_id` = `t2`.`id`
      WHERE `t1`.`parent_id` = 0
      AND `t1`.`is_depreciated` = 0;

    """

    better_sql = """
      SELECT `name_safe_short`, `name_french`, `name_english` FROM `attribute` WHERE `is_depreciated` = 0 AND `section_id` < 16;
    """

    records = QueryHandler.execute_query(sql_statement)
    # raise Exception(records[23][8])
    better_records = QueryHandler.execute_query(better_sql)
    better_html = better_form(better_records)

    html_string = form_builder(records)
    role = self.session.get('role')
    user_session = self.session.get("user")

    if role != "admin" and role != "staff":
      self.redirect("/users/login?message={0}".format("You are not authorized to view this page"))
      return


    form = Record.RecordForm()
    template_values = {
      "form": form,
      "user_session": user_session,
      "html_string": html_string,
      "better_html": better_html,
      "message": self.request.get("message")
    }
    language = None
    if "language" in self.request.cookies:
      language = self.request.cookies["language"]
    else:
      language = "fr"
      self.response.set_cookie("language", "fr")

    language = language.replace('"', '').replace("'", "")
    if language == "fr":

      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('fr_new_record.html')
    else:
      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('new_record.html')
    self.response.write(LEGACY_TEMPLATE.render(template_values))
  def post(self, record_id):
    role = self.session.get('role')
    user_session = self.session.get("user")

    if role != "admin":
      self.redirect("/users/login?message={0}".format("You are not authorized to view this page"))
      return

    record = Record.Record.get_by_id(int(record_id))
    if not record:
      self.response.write(LEGACY_TEMPLATE.render({"form": form, "message": "Unable to find program. Please contact administrator."}))

    form = Record.RecordForm(self.request.POST)
    if form.validate():
      Record.update(self, LEGACY_TEMPLATE, form, record_id)
    else:
      self.response.write(LEGACY_TEMPLATE.render({"form": form}))
  def get(self, record_id):
    role = self.session.get('role')
    user_session = self.session.get("user")
    if role != "admin" and role != "staff":
      self.redirect("/users/login?message={0}".format("You are not authorized to view this page"))
      return

    record = Record.Record.get_by_id(int(record_id))
    if not record:
      self.response.write(TEMPLATE.render({"form": form, "message": "Unable to find Record. Please contact administrator."}))

    form = Record.RecordForm()
    record_dict = record.to_dict()
    for obj in record_dict:
      try:
        form[obj].data = record_dict[obj]
      except:
        pass

    template_values = {
      "message": self.request.get("message"),
      "user_session": user_session,
      "form": form,
      "record": record,

    }
    language = None
    if "language" in self.request.cookies:
      language = self.request.cookies["language"]
    else:
      language = "fr"
      self.response.set_cookie("language", "fr")

    language = language.replace('"', '').replace("'", "")
    if language == "fr":

      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('fr_edit_record.html')
    else:
      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('edit_record.html')
    self.response.write(LEGACY_TEMPLATE.render(template_values))
    def get(self):
        role = self.session.get('role')
        user_session = self.session.get("user")

        if role != "admin" and role != "staff":
            self.redirect("/users/login?message={0}".format(
                "You are not authorized to view this page"))
            return

        org_id = self.request.get("record")

        sql_statement = "SELECT 1_nom FROM organization WHERE id={0} LIMIT 1".format(
            org_id)
        org = QueryHandler.execute_query(sql_statement)
        form = Record.RecordForm()
        template_values = {
            "form": form,
            "user_session": user_session,
            "org_id": self.request.get("record"),
            "org_name": org[0][0]
        }
        language = None
        if "language" in self.request.cookies:
            language = self.request.cookies["language"]
        else:
            language = "fr"
            self.response.set_cookie("language", "fr")

        language = language.replace('"', '').replace("'", "")
        if language == "fr":

            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'fr_new_programs.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'new_programs.html')
        self.response.write(LEGACY_TEMPLATE.render(template_values))
Beispiel #5
0
    def get(self):
        role = self.session.get('role')
        user_session = self.session.get("user")

        if role != "admin" and role != "staff":
            self.redirect("/users/login?message={0}".format(
                "You are not authorized to view this page"))
            return

        url = self.request.url
        index = url.index("=")
        record_id = url[index + 1:]

        form = Record.RecordForm()
        template_values = {
            "form": form,
            "user_session": user_session,
            "org_id": self.request.get("record"),
            "record_id": record_id
        }
        language = None
        if "language" in self.request.cookies:
            language = self.request.cookies["language"]
        else:
            language = "fr"
            self.response.set_cookie("language", "fr")

        language = language.replace('"', '').replace("'", "")
        if language == "fr":

            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'fr_new_services.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'new_services.html')
        self.response.write(LEGACY_TEMPLATE.render(template_values))