示例#1
0
    def get(self, service_key):
        user_session = self.session.get('user')

        role = self.session.get('role')

        if role != "admin":
            self.redirect("/users/login?message=Unauthorized action")
            return
        else:
            sql_statement = "SELECT name_french, id FROM service WHERE id={0}".format(
                service_key)
            services = QueryHandler.execute_query(sql_statement)
            sql_statement = "DELETE FROM service WHERE id={0}".format(
                service_key)
            update = QueryHandler.execute_query(sql_statement, True)
            service_dict = {
                "service":
                "Delete service '{0}'".format(services[0][0].encode("utf-8"))
            }
            service_json = json.dumps(service_dict)

            user_audit = Audit.save(
                initiated_by=self.session.get("user"),
                organization_affected=self.request.get("name"),
                security_clearance="admin",
                json_data=service_json,
                model="Service",
                action="Delete Service")
            self.redirect("/admin?message={0} {1}".format(
                services[0][0].encode("utf-8"), " deleted"))
示例#2
0
    def get(self, org_key):
        user_session = self.session.get('user')

        role = self.session.get('role')
        if role != "admin":
            self.redirect("/users/login?message=Unauthorized action")
            return
        else:
            sql_statement = "SELECT id FROM org_prog WHERE id={0}".format(
                org_key)
            programs = QueryHandler.execute_query(sql_statement)
            sql_statement = "DELETE FROM org_prog WHERE id={0}".format(org_key)
            # raise Exception(sql_statement)
            update = QueryHandler.execute_query(sql_statement, True)

            program_dict = {"program": "Delete program '{0}'".format(org_key)}
            program_json = json.dumps(program_dict)

            user_audit = Audit.save(
                initiated_by=self.session.get("user"),
                organization_affected=self.request.get("name"),
                security_clearance="admin",
                json_data=program_json,
                model="Program",
                action="Delete Program")
            self.redirect("/admin?message={0}".format("program deleted"))
示例#3
0
    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

        if not self.legacy:
            self.redirect("/#/admin")
            return

        sql_statement = """
      SELECT * FROM organization WHERE id='{0}' AND is_deleted=0 LIMIT 1
    """.format(record_id)

        record = QueryHandler.execute_query(sql_statement)
        sql_services = "SELECT name_french, id  FROM service WHERE org_id = {0};".format(
            record_id)

        services = QueryHandler.execute_query(sql_services)

        sql_programs = """SELECT DISTINCT(`program_id`), `program`.`name_french`, `program`.`name_english`
      FROM `service`
      LEFT JOIN `program`
      ON `service`.`program_id` = `program`.`id`
      WHERE `service`.`org_id` = {0};
    """.format(record_id)
        programs = QueryHandler.execute_query(sql_programs)

        template_values = {
            "message": self.request.get("message"),
            "user_session": user_session,
            "record": record[0],
            "services": services,
            "programs": programs,
            "role": role
        }
        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_view_records.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'view_records.html')
        self.response.write(LEGACY_TEMPLATE.render(template_values))
示例#4
0
  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))
示例#5
0
def update_record(self, service_id):
	data = get_attributes(self)
	valid, errors = validate_attributes(data)
	sql_statement = update_sql_statement(data, service_id)
	record = QueryHandler.execute_query(sql_statement, insert=True)
	record_audit = QueryHandler.create_audit(self, "Service", data['name_french'], data, "Update Service")
	return
    def get(self, export_type):
        self.response.headers['Content-Type'] = 'text/csv'

        if export_type == "map_search":
            self.response.headers['Content-Disposition'] = \
              'attachment; filename="timoun_search_records.csv"'

            page = self.request.get("page")
            page_int = 0
            if page:
                page_int = int(page)
            records = QueryHandler.form_query_builder(self,
                                                      page_int,
                                                      limit=2000)
            writer = csv.writer(self.response.out)
            writer.writerow(RECORDS_CSV_HEADER)
            records_string = ""
            for record in records:
                s = '"' + record[5].encode("utf-8") + '"'
                records_string += '{0},'.format(s)
            records_string = records_string[:-1]

            sql_statement = "SELECT * FROM organization WHERE 1_nom IN ({0});".format(
                records_string)
            # raise Exception(sql_statement)
            org_records = QueryHandler.execute_query(sql_statement)
            for record in org_records:
                writer.writerow(SqlToCsvLine(record, RECORD_CSV_FIELDS))
示例#7
0
def find_or_create_program(data):
    sql_statement = """
			SELECT id FROM org_prog WHERE id="{0}"
			""".format(data['program_id'])
    program = QueryHandler.execute_query(sql_statement)
    if len(program) > 0:
        raise Exception("Program already exists")
示例#8
0
def update_record(self, org_key):
	data = get_attributes(self)
	# raise Exception(self.request)
	valid, errors = validate_attributes(data)
	sql_statement = populate_update_statement(data, org_key)
	record = QueryHandler.execute_query(sql_statement, True)
	record_audit = QueryHandler.create_audit(self, "Organization", "Organization", data, "Edit Organization")
	return
示例#9
0
def update_record(self):
    data = get_attributes(self)
    # raise Exception(data)
    valid, errors = validate_attributes(data)
    sql_statement = populate_update_statement(data)
    record = QueryHandler.execute_query(sql_statement, True)
    record_audit = QueryHandler.create_audit(self, "Program", "Program", data,
                                             "Update Program")
    return
示例#10
0
  def get(self, program_id):
    role = self.session.get('role')
    user_session = self.session.get("user")

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

    sql_statement = """
          SELECT * FROM org_prog WHERE id='{0}' LIMIT 1
        """.format(program_id)


    program = QueryHandler.execute_query(sql_statement)

    org_select = """
        SELECT 1_nom FROM organization WHERE id="{0}"
    """.format(program[0][1])

    org = QueryHandler.execute_query(org_select)
    if len(program) == 0:
      self.redirect("/admin?message=That program does not exist")
      return
    template_values = {
      "role": self.session.get("role"),
      "user_session": user_session,
      "message": self.request.get("message"),
      "program": program[0],
      "org": 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_edit_program.html')
    else:
      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('edit_program.html')
    self.response.write(LEGACY_TEMPLATE.render(template_values))
示例#11
0
def save_record(self):
    data = get_attributes(self)
    valid, errors = validate_attributes(data)
    sql_statement = populate_sql_statement(data)
    record = QueryHandler.execute_query(sql_statement, insert=True)
    self.redirect("/admin/records/" + data['org_id'] +
                  "?message=Program saved")
    record_audit = QueryHandler.create_audit(self, "Program", "Program", data,
                                             "Create Program")
    return
示例#12
0
def find_or_create_program(data):
	sql_statement = """
			SELECT id FROM org_prog WHERE id="{0}"
			""".format(data['program_id'])
	program = QueryHandler.execute_query(sql_statement)
	if len(program) == 0:
		sql_statement = """
		INSERT INTO `org_prog` SET
		`id` = NULL,
		`org_id` = "{0}",
		`program_id` = "{1}"
		""".format(data['org_id'], data['program_id'])
示例#13
0
def check_for_service_duplicate(data):
	words = QueryHandler.words
	name_french = data['name_french']
	if name_french:
	    for word in words:
	    	name_french = name_french.replace(word, words[word])
	sql_statement = """
		SELECT name_french FROM service WHERE name_french="{0}" AND org_id="{1}"
		""".format(name_french, data['org_id'])
	service = QueryHandler.execute_query(sql_statement)
	if len(service) > 0:
		raise Exception("Service already exists")
示例#14
0
def save_record(self):
	data = get_attributes(self)
	valid, errors = validate_attributes(data)
	if errors:
		self.redirect("/records/new?message=Please review errors")
		return
	if record_exists(data):

		self.redirect("/records/new?message=Record already exists")
		return

	sql_statement = populate_sql_statement(data)

	record = QueryHandler.execute_query(sql_statement, insert=True)
	# raise Exception(record)
	last_record_sql = "SELECT id FROM organization ORDER BY id DESC LIMIT 1;"

	last = QueryHandler.execute_query(last_record_sql)
	self.redirect("/records/{0}?message=Saved".format(last[0][0]))
	
	record_audit = QueryHandler.create_audit(self, "Organization", data['1_nom'], data, "Create Organization")
	return 
  def get(self, org_id):
    role = self.session.get('role')
    user_session = self.session.get("user")

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

    if not self.legacy:
      self.redirect("/#/organizations/{0}/edit".format(org_id))

    sql_statement = """
          SELECT * FROM organization WHERE id='{0}' LIMIT 1
        """.format(org_id)


    org = QueryHandler.execute_query(sql_statement)
    
    if len(org) == 0:
      self.redirect("/admin?message=That organization does not exist")
      return
    data = OrganizationHelper.get_hash(org[0])
    template_values = {
      "role": self.session.get("role"),
      "user_session": user_session,
      "message": self.request.get("message"),
      "org": org[0],
      "data": data
    }
    # g = "show columns from organization;"
    # r = QueryHandler.execute_query(g)
    # attrs = []
    # # raise Exception(r)
    # for item in r:
    #   attrs.append(item[0])
    # raise Exception(attrs)

    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":
      # raise Exception(2)
      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('fr_edit_organization.html')
    else:
      LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('edit_organization.html')
    self.response.write(LEGACY_TEMPLATE.render(template_values))
示例#16
0
def save_record(self):
	data = get_attributes(self)
	# raise Exception(data)
	find_or_create_program(data)
	check_for_service_duplicate(data)
	valid, errors = validate_attributes(data)
	# raise Exception(len(data))

	sql_statement = populate_sql_statement(data)
	# raise Exception(sql_statement)
	record = QueryHandler.execute_query(sql_statement, insert=True)
	self.redirect("/admin/records/" + data['org_id'] + "?message=Service saved")
	record_audit = QueryHandler.create_audit(self, "Service", data['name_french'], data, "Create Service")
	return 
示例#17
0
def get_record_info(record_id):
    sql_statement = """SELECT `data`.`record_id`, `data`.`attribute_id`, `data`.`program_id`, `data`.`content_integer`, `data`.`content_text`, `data`.`content_decimal`, `data`.`content_date`, `attribute`.`name_safe_short`, `attribute`.`access`, `attribute`.`is_enum`, `attribute`.`format`
  FROM `data`
  LEFT JOIN `attribute` ON `data`.`attribute_id` = `attribute`.`id`
  WHERE `data`.`record_id` = {0};
  """.format(record_id)
    items = QueryHandler.execute_query(sql_statement)

    info_dict = {}

    for item in items:
        info_dict[item[1]] = get_correct_data(item)

    return info_dict
示例#18
0
    def get(self, record_id):

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

        sql_statement = """
      SELECT * FROM service WHERE id='{0}' LIMIT 1
    """.format(record_id)

        service = QueryHandler.execute_query(sql_statement)

        program_name = QueryHandler.execute_query(
            "SELECT name_french FROM program WHERE id={0}".format(
                service[0][11]))

        template_values = {
            "message": self.request.get("message"),
            "user_session": user_session,
            "service": service[0],
            "program": program_name[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_view_public_service.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'view_public_service.html')
        self.response.write(LEGACY_TEMPLATE.render(template_values))
  def get(self, org_key):
    user_session = self.session.get('user')

    role = self.session.get('role')

    if role != "admin":
      self.redirect("/users/login?message=Unauthorized action")
      return
    else:
      sql_statement = "SELECT 1_nom, id FROM organization WHERE id={0}".format(org_key)
      records = QueryHandler.execute_query(sql_statement)
      org_dict = {
        "org": "Delete organization '{0}'".format(records[0][0])
      }
      org_json = json.dumps(org_dict)
      sql_statement = """
        UPDATE `organization` SET
        `is_deleted` = 1
        WHERE `id` = "{0}"
        LIMIT 1;
      """.format(records[0][1])
      update = QueryHandler.execute_query(sql_statement, True)
      user_audit = Audit.save(initiated_by = self.session.get("user"), organization_affected = self.request.get("name"), security_clearance = "admin", json_data = org_json, model= "Organization", action = "Delete Organization")
      self.redirect("/admin/records?message={0} {1}".format(records[0][0], " deleted"))
  def post(self, org_key):
    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

    sql_statement = """
      SELECT id FROM organization WHERE id="{0}"
      """.format(org_key)
    organization = QueryHandler.execute_query(sql_statement)
    if len(organization) > 0:
      OrganizationHelper.update_record(self, org_key)
      self.redirect("/records/" + org_key + "/edit?message=Update complete")
    else:
      self.redirect("/admin?message=Program does not exist")
    def get(self, service_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

        if not self.legacy:
            self.redirect("/#/services/{0}/edit".format(service_key))

        sql_statement = "SELECT * FROM service WHERE id={0}".format(service_id)

        service = QueryHandler.execute_query(sql_statement)
        if len(service) == 0:
            self.redirect("/admin?message=That service does not exist")
            return
        # raise Exception(service)

        template_values = {
            "role": self.session.get("role"),
            "user_session": user_session,
            "message": self.request.get("message"),
            "service": service[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_edit_service.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                'edit_service.html')

        self.response.write(LEGACY_TEMPLATE.render(template_values))
    def post(self, service_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

        sql_statement = """
      SELECT id FROM service WHERE id="{0}"
      """.format(service_id)
        service = QueryHandler.execute_query(sql_statement)
        if len(service) > 0:
            ServiceHelper.update_record(self, service_id)
            self.redirect("/admin/services/" + service_id +
                          "?message=Update complete")
        else:
            self.redirect("/admin?message=Service does not exist")
示例#23
0
  def post(self, program_id):
    role = self.session.get('role')
    user_session = self.session.get("user")

    program_id = self.request.get("program_id")

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

    sql_statement = """
      SELECT id FROM org_prog WHERE id="{0}"
      """.format(program_id)
    program = QueryHandler.execute_query(sql_statement)
    if len(program) > 0:
      ProgramHelper.update_record(self)
      self.redirect("/programs/" + program_id + "/edit?message=Update complete")
    else:
      self.redirect("/admin?message=Program does not exist")
示例#24
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

        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))
示例#25
0
    def get(self):

        role = self.session.get('role')
        user_session = self.session.get("user")
        page = self.request.get("page")
        offset_string = ""
        if page:
            offset = int(page) * 100
            offset_string = "OFFSET {0}".format(offset)

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

        if not self.legacy:
            self.redirect("/#/admin")

        query = Record.Record.query()
        if not page:
            page = 0
        records = None
        if page:
            offset = int(page) * 100
            records = query.fetch(100, offset=offset)
        else:
            records = query.fetch(100)

        if not page:
            page = 0
        else:
            page = int(page)
        records = None
        if search(self):
            records = QueryHandler.form_query_builder(self, page, 100)
        else:
            records = QueryHandler.execute_query(
                "SELECT 1_nom, id, departement FROM organization WHERE is_deleted=0 ORDER BY 1_nom LIMIT 100 {0}"
                .format(offset_string))

        #raise Exception(len(guestlist))
        next_page = page + 1
        last_page = page - 1
        template_values = {
            "message": self.request.get("message"),
            "user_session": user_session,
            "records": records,
            "records_length": len(records),
            "next_page": next_page,
            "last_page": last_page,
            "role": role,
            "search": search(self)
        }

        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":
            if role == "admin":
                LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                    'fr_records.html')
            else:
                LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                    'fr_records.html')
        else:
            if role == "staff":
                LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                    'records.html')
            else:
                LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template(
                    'records.html')

        self.response.write(LEGACY_TEMPLATE.render(template_values))
示例#26
0
def record_exists(data):
	sql_statement = """SELECT * FROM organization WHERE 1_nom = '{0}'""".format(data["1_nom"])
	record = QueryHandler.execute_query(sql_statement)
	if len(record) > 0:
		return True
	return False
示例#27
0
    def get(self, export_type):
        role = self.session.get('role')
        user_session = self.session.get("user")
        self.response.headers['Content-Type'] = 'text/csv'

        if export_type == "searches":
            if role != "admin" and role != "staff":
                self.redirect(
                    "/?message=You are not authorized to view this page")
                return
            self.response.headers['Content-Disposition'] = \
              'attachment; filename="timoun_search_records.csv"'

            writer = csv.writer(self.response.out)

            writer.writerow(SEARCHES_CSV_FIELDS)
            searches = SearchRecord.SearchRecord.query()
            for search in searches:
                writer.writerow(ToCsvLine(search, SEARCHES_CSV_FIELDS))

        if export_type == "user_dashboard":
            if role != "admin" and role != "staff":
                self.redirect(
                    "/?message=You are not authorized to view this page")
                return
            self.response.headers['Content-Disposition'] = \
              'attachment; filename="timoun_user_dashboard.csv"'

            writer = csv.writer(self.response.out)

            writer.writerow(USER_DASHBOARD_CSV_HEADER)
            audits = Audit.Audit.query(
                Audit.Audit.model_affected == "User").order(
                    Audit.Audit.created_at)

            for audit in audits:
                writer.writerow(ToCsvLine(audit, USER_DASHBOARD_CSV_FIELDS))

        if export_type == "users":
            if role != "admin" and role != "staff":
                self.redirect(
                    "/?message=You are not authorized to view this page")
                return
            self.response.headers['Content-Disposition'] = \
                'attachment; filename="timoun_users.csv"'
            writer = csv.writer(self.response.out)

            writer.writerow(USER_CSV_FIELDS)
            users = User.User.query().order(User.User.email)

            for user in users:
                writer.writerow(ToCsvLine(user, USER_CSV_FIELDS))

        if export_type == "dashboard":
            if role != "admin" and role != "staff":
                self.redirect(
                    "/?message=You are not authorized to view this page")
                return
            self.response.headers['Content-Disposition'] = \
                'attachment; filename="timoun_users.csv"'
            writer = csv.writer(self.response.out)

            writer.writerow(DASHBOARD_CSV_HEADER)
            audits = Audit.Audit.query().order(Audit.Audit.created_at)
            for audit in audits:
                writer.writerow(ToCsvLine(audit, DASHBOARD_CSV_FIELDS))

        if export_type == "records":
            if role != "admin" and role != "staff":
                self.redirect(
                    "/?message=You are not authorized to view this page")
                return
            self.response.headers['Content-Disposition'] = \
                'attachment; filename="timoun_records.csv"'
            writer = csv.writer(self.response.out)

            writer.writerow(RECORDS_CSV_HEADER)
            sql_statement = "SELECT * FROM organization;"
            records = QueryHandler.execute_query(sql_statement)
            for record in records:
                writer.writerow(SqlToCsvLine(record, RECORD_CSV_FIELDS))

        if export_type == "view_record":
            self.response.headers['Content-Disposition'] = \
                'attachment; filename="timoun_records.csv"'
            writer = csv.writer(self.response.out)
            record_id = self.request.get("record_id")
            writer.writerow(RECORDS_CSV_HEADER)
            sql_statement = """
        SELECT * FROM organization WHERE id="{0}" LIMIT 1;
        """.format(record_id)
            records = QueryHandler.execute_query(sql_statement)
            for record in records:
                writer.writerow(SqlToCsvLine(record, RECORD_CSV_FIELDS))
            return

        if export_type == "view_record":
            self.response.headers['Content-Disposition'] = \
                'attachment; filename="timoun_records.csv"'
            writer = csv.writer(self.response.out)
            record_id = self.request.get("record_id")
            writer.writerow(RECORDS_CSV_HEADER)
            sql_statement = """
        SELECT * FROM organization WHERE id="{0}";
        """.format(record_id)
            records = QueryHandler.execute_query(sql_statement)
            for record in records:
                writer.writerow(SqlToCsvLine(record, RECORD_CSV_FIELDS))

        if export_type == "search_records":
            pass