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))
    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))
示例#3
0
    def get(self):
        keywords = self.request.get("keywords")
        service = self.request.get("service")
        department = self.request.get("department")
        age_start = self.request.get("age_start")
        age_end = self.request.get("age_end")
        gender = self.request.get("gender")
        page = self.request.get("page")
        results = self.request.get("results")
        count = 0
        if not results:
            results = 25
        records = []
        page_offset = 0

        page_int = 0
        page = self.request.get("page")
        if page:
            page_int = int(page)

        if search(self):
            # try:
            count = QueryHandler.form_query_total(self)
            # raise Exception(count)
            records = QueryHandler.form_query_builder(self, page, results)
            records = QueryHandler.add_services(records)
            # except:
            #   self.redirect("/search?message=Invalid search parameters#'")
            #   return
        # raise Exception(len(records))
        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_search.html')
        else:
            LEGACY_TEMPLATE = JINJA_ENVIRONMENT.get_template('en_search.html')

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

        role = self.session.get('role')
        user_session = self.session.get("user")
        template_values = {
            "role": self.session.get("role"),
            "user_session": user_session,
            "message": self.request.get("message"),
            "records": records,
            "page": page_int,
            "keywords": keywords,
            "service": service,
            "department": department,
            "age_start": age_start,
            "age_end": age_end,
            "gender": gender,
            "records_count": len(records),
            "total_count": count
        }

        self.response.write(LEGACY_TEMPLATE.render(template_values))