def handle(self, example_slug: str, undo: bool, **kwargs):
        if not SLUG_RE.match(example_slug):
            raise CommandError('Invalid slug! {}.'.format(SLUG_HELP))

        template = Example(TEMPLATE_NAME)
        ex = Example(example_slug)

        if undo:
            self.undo_copy(template.template_path, ex.template_path, ex)
            self.undo_copy(template.jinja2_path, ex.jinja2_path, ex)
            self.undo_copy(template.python_path, ex.python_path, ex)
        else:
            self.copy(template.template_path, ex.template_path, ex)
            self.copy(template.jinja2_path, ex.jinja2_path, ex)
            self.copy(template.python_path, ex.python_path, ex)

            self.stdout.write("\nDone! Now edit the above files.")
            self.stdout.write("Then, add '{}' to {}.".format(
                example_slug,
                EXAMPLE_NAMES_PATH,
            ))
            self.stdout.write("You may also want to write tests for "
                              "the example in {}.".format(
                                  EXAMPLE_TESTS_PATH.relative_to(Path.cwd())))
Beispiel #2
0
    def get(self):

        if "example" in self.request.path:
            attacks = Example.get_example_attacks()
            uid = generate_string(6)
        else:
            if self.logged_in:
                attacks = self.current_user.get_attacks_as_dict()
                uid = self.current_user.share_report_and_list_key

        if attacks is not None:
            self.response.headers['Content-Transfer-Encoding'] = 'binary'
            self.response.headers['Accept-Range'] = 'bytes'
            self.response.headers['Content-Encoding'] = 'binary'

            if self.request.path.endswith(".xlsx"):
                self.response.headers['Content-Disposition'] = 'attachment; filename=migraines.xlsx'
                self.response.headers['Content-Type'] = 'application/xlsx'
                
                output_content = generate_xlsx_output(attacks)

            if self.request.path.endswith(".csv"):
                self.response.headers['Content-Disposition'] = 'attachment; filename=migraines.csv'
                self.response.headers['Content-Type'] = 'application/csv'

                output_content = generate_csv_output(attacks)

            if self.request.path.endswith(".ics"):
                self.response.headers['Content-Disposition'] = 'attachment; filename=migraines.ics'
                self.response.headers['Content-Type'] = 'application/ics'

                output_content = generate_ics_output(attacks, uid)

            self.response.out.write(output_content)
        else:
            self.response.out.write("We don't have what you're looking for.")

            self.response.status = 404
Beispiel #3
0
    def get(self):

        matches = re.match(r"/shared/(?P<key>[0-9a-z_]+)/.*",
                           self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(
                    shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(
                        generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {
                    'status': '404 - Not found',
                    'title': 'What a headache!',
                    'message':
                    "Sorry, we couldn't find what you're looking for."
                }

                self.response.status = 404
                path = os.path.join(
                    os.path.join(os.path.dirname(__file__), 'html'),
                    '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {
                'status': '404 - Not found',
                'title': 'What a headache!',
                'message': "Sorry, we couldn't find what you're looking for."
            }

            self.response.status = 404
            path = os.path.join(
                os.path.join(os.path.dirname(__file__), 'html'),
                '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))
Beispiel #4
0
    def get(self):

        matches = re.match(
                r"/shared/(?P<key>[0-9a-z_]+)/.*",
                self.request.path)

        if matches:
            shared_link = matches.group("key")

            response = {}
            attacks = None

            if len(shared_link) == 7:
                # Report with List
                acc = User.get_account_from_share_link_report_and_list(shared_link)

                response['show_list'] = True

                attacks = acc.get_attacks_as_dict()

            if len(shared_link) == 8:
                # Report only
                acc = User.get_account_from_share_link_report_only(shared_link)

                response['show_list'] = False

                attacks = acc.get_attacks_as_dict()

            if shared_link == "example_report":
                response['show_list'] = False

                attacks = Example.get_example_attacks()

            if shared_link == "example_report_and_list":
                response['show_list'] = True

                attacks = Example.get_example_attacks()

            if attacks is not None:
                if len(attacks) > 0:
                    response['data'] = simplejson.dumps(generate_statistics_from_events(attacks))
                else:
                    response['data'] = {}

                response['show_logout'] = False
                response['show_add'] = False
                response['show_options'] = False
                response['shared'] = True
                response['web_debug'] = Configuration.get_instance().web_debug

                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/main.html')
                self.response.out.write(template.render(path, response))
            else:
                template_values = {'status': '404 - Not found',
                                   'title': 'What a headache!',
                                   'message': "Sorry, we couldn't find what you're looking for."}

                self.response.status = 404
                path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
                self.response.out.write(template.render(path, template_values))
        else:
            template_values = {'status': '404 - Not found',
                               'title': 'What a headache!',
                               'message': "Sorry, we couldn't find what you're looking for."}

            self.response.status = 404
            path = os.path.join(os.path.join(os.path.dirname(__file__), 'html'), '../../templates/error.html')
            self.response.out.write(template.render(path, template_values))