Example #1
0
    def post(self):
        action = self.get_argument('action')
        message = None

        if action != 'add_project':
            raise HTTPError(400, 'Unknown action')

        add_project_form = AddProjectForm(self.request.arguments)

        if add_project_form.validate():
            name = add_project_form.name.data

            try:
                Project.new_project(name)
            except IntegrityError:
                message = 'Project already exists.'
            else:
                logger.info(self.user_audit_text('Created project %s'), name)
                self.redirect(self.reverse_url('project.overview', name))
                return
        else:
            message = 'Error'

        self.render(
            'admin/project/all.html',
            add_project_form=add_project_form,
            projects=Project.all_project_infos(),
            message=message,
            project_budgets=Budget.projects,
        )
Example #2
0
    def post(self):
        action = self.get_argument('action')
        message = None

        if action != 'add_project':
            raise HTTPError(400, 'Unknown action')

        add_project_form = AddProjectForm(self.request.arguments)

        if add_project_form.validate():
            name = add_project_form.name.data

            try:
                Project.new_project(name)
            except IntegrityError:
                message = 'Project already exists.'
            else:
                logger.info(self.user_audit_text('Created project %s'), name)
                self.redirect(self.reverse_url('project.overview', name))
                return
        else:
            message = 'Error'

        self.render(
            'admin/project/all.html',
            add_project_form=add_project_form,
            projects=Project.all_project_infos(),
            message=message,
            project_budgets=Budget.projects,
        )
    def post(self):
        action = self.get_argument("action")
        message = None

        if action != "add_project":
            raise HTTPError(400, "Unknown action")

        add_project_form = AddProjectForm(self.request.arguments)

        if add_project_form.validate():
            name = add_project_form.name.data

            try:
                Project.new_project(name)
            except IntegrityError:
                message = "Project already exists."
            else:
                logger.info("Created project %s", name)
                self.redirect(self.reverse_url("project.overview", name))
                return

        self.render(
            "admin/project/all.html",
            add_project_form=add_project_form,
            projects=Project.all_project_infos(),
            message=message,
            project_budgets=Budget.projects,
        )
Example #4
0
    def post(self, project_id):
        form = ConfirmForm(self.request.arguments)

        if form.validate():
            Project.delete_project(project_id)
            Budget.calculate_budgets()

            logger.info(self.user_audit_text('Deleted project %s'), project_id)
            self.redirect(self.reverse_url('admin.overview'))
        else:
            self.render('admin/project/delete.html', project_id=project_id, form=form)
    def post(self, name):
        form = ConfirmForm(self.request.arguments)

        if form.validate():
            Project.delete_project(name)
            Budget.calculate_budgets()

            logger.info("Deleted project %s", name)
            self.redirect(self.reverse_url("admin.overview"))
        else:
            self.render("admin/project/delete.html", project_name=name, form=form)
    def generate_mock(self):
        with new_session() as session:
            for project_num in range(1, self.args.count + 1):
                project_id = "test_{}".format(project_num)

                project = Project(name=project_id)

                if project_num == 2:
                    project.url_template = "http://example.com/{shortcode}/slash/"

                print("Running insertion")
                session.add(project)
    def generate_mock(self):
        with new_session() as session:
            for project_num in range(1, self.args.count + 1):
                project_id = 'test_{}'.format(project_num)

                project = Project(name=project_id)

                if project_num == 2:
                    project.url_template = 'http://example.com/{shortcode}/slash/'

                print('Running insertion')
                session.add(project)
Example #8
0
    def post(self, project_id):
        form = ConfirmForm(self.request.arguments)

        if form.validate():
            Project.delete_project(project_id)
            Budget.calculate_budgets()

            logger.info(self.user_audit_text('Deleted project %s'), project_id)
            self.redirect(self.reverse_url('admin.overview'))
        else:
            self.render('admin/project/delete.html',
                        project_id=project_id,
                        form=form)
Example #9
0
    def post(self, name):
        project = Project.get_plain(name)
        enable_form = QueueEnableForm(data=self.get_enable_form(project))
        form = QueueSettingsForm(data=self.get_queue_settings_form(project))
        lower_shortcode = project.lower_shortcode()

        message = None
        action = self.get_argument('action', None)

        if action == 'enable':
            enable_form = QueueEnableForm(self.request.arguments)
            if enable_form.validate():
                with Project.get_session_object(name) as project:
                    project.enabled = enable_form.enabled.data
                    logger.info('Project %s enabled=%s',
                                name, project.enabled)
                    message = ('Enabled' if project.enabled else 'Disabled')
            else:
                message = 'Error in Queue Enable Form.'

        elif action == 'autoqueue':
            form = QueueSettingsForm(self.request.arguments)
            if form.validate():
                with Project.get_session_object(name) as project:
                    project.autoqueue = form.autoqueue.data
                    project.num_count_per_item = form.num_count_per_item.data
                    project.max_num_items = form.max_num_items.data
                    project.lower_sequence_num = form.lower_sequence_num.data or 0
                    project.autorelease_time = form.autorelease_time.data * 60 or 0

                    lower_shortcode = project.lower_shortcode()

                logger.debug('Project %s queue settings changed.', name)
                message = 'Settings saved.'
            else:
                message = 'Error in Auto Queue Form.'
        else:
            message = 'Error: unrecognized action argument.'

        Budget.calculate_budgets()

        self.render(
            'admin/project/queue_settings.html',
            project_name=name,
            lower_shortcode=lower_shortcode,
            form=form,
            enable_form=enable_form,
            message=message
        )
Example #10
0
    def post(self, name):
        form = ProjectSettingsForm(self.request.arguments)
        message = None

        if form.validate():
            with Project.get_session_object(name) as project:
                project.alphabet = form.alphabet.data
                project.min_version = form.min_version.data
                project.min_client_version = form.min_client_version.data
                project.url_template = form.url_template.data
                project.request_delay = form.request_delay.data
                project.redirect_codes = form.redirect_codes.data
                project.no_redirect_codes = form.no_redirect_codes.data
                project.unavailable_codes = form.unavailable_codes.data
                project.banned_codes = form.banned_codes.data
                project.body_regex = form.body_regex.data
                project.method = form.method.data

            logger.info('Changed project %s shortener settings', name)
            message = 'Settings saved.'
        else:
            message = 'Error.'

        self.render(
            'admin/project/shortener_settings.html',
            project_name=name, form=form,
            message=message
        )
Example #11
0
    def get(self, project_id):
        project = Project.get_plain(project_id)
        form = ProjectSettingsForm(**project.to_dict())

        self.render(
            'admin/project/shortener_settings.html',
            project_id=project_id, form=form,
        )
Example #12
0
    def get(self):
        name = self.get_argument('name')
        project = Project.get_plain(name)

        if project:
            self.write(project.to_dict())
        else:
            raise HTTPError(404, reason='Project not found')
Example #13
0
    def get(self):
        name = self.get_argument('name')
        project = Project.get_plain(name)

        if project:
            self.write(project.to_dict())
        else:
            raise HTTPError(404, reason='Project not found')
Example #14
0
    def post(self, project_id):
        project = Project.get_plain(project_id)
        enable_form = QueueEnableForm(data=self.get_enable_form(project))
        form = QueueSettingsForm(data=self.get_queue_settings_form(project))
        lower_shortcode = project.lower_shortcode()

        message = None
        action = self.get_argument('action', None)

        if action == 'enable':
            enable_form = QueueEnableForm(self.request.arguments)
            if enable_form.validate():
                with Project.get_session_object(project_id) as project:
                    project.enabled = enable_form.enabled.data
                    logger.info(self.user_audit_text('Project %s enabled=%s'),
                                project_id, project.enabled)
                    message = ('Enabled' if project.enabled else 'Disabled')
            else:
                message = 'Error in Queue Enable Form.'

        elif action == 'autoqueue':
            form = QueueSettingsForm(self.request.arguments)
            if form.validate():
                with Project.get_session_object(project_id) as project:
                    form.populate_obj(project)
                    project.lower_sequence_num = form.lower_sequence_num.data or 0
                    project.autorelease_time = form.autorelease_time.data * 60 or 0

                    lower_shortcode = project.lower_shortcode()

                logger.debug('Project %s queue settings changed.', project_id)
                message = 'Settings saved.'
            else:
                message = 'Error in Auto Queue Form.'
        else:
            message = 'Error: unrecognized action argument.'

        Budget.calculate_budgets()

        self.render('admin/project/queue_settings.html',
                    project_id=project_id,
                    lower_shortcode=lower_shortcode,
                    form=form,
                    enable_form=enable_form,
                    message=message)
Example #15
0
 def get(self, project_id):
     project = Project.get_plain(project_id)
     enable_form = QueueEnableForm(data=self.get_enable_form(project))
     form = QueueSettingsForm(data=self.get_queue_settings_form(project))
     self.render('admin/project/queue_settings.html',
                 project_id=project_id,
                 lower_shortcode=project.lower_shortcode(),
                 form=form,
                 enable_form=enable_form)
Example #16
0
    def get(self, project_id):
        project = Project.get_plain(project_id)
        form = ProjectSettingsForm(**project.to_dict())

        self.render(
            'admin/project/shortener_settings.html',
            project_id=project_id,
            form=form,
        )
    def get(self):
        add_project_form = AddProjectForm()
        projects = Project.all_project_infos()

        self.render(
            "admin/project/all.html",
            projects=projects,
            add_project_form=add_project_form,
            project_budgets=Budget.projects,
        )
Example #18
0
 def get(self, project_id):
     project = Project.get_plain(project_id)
     enable_form = QueueEnableForm(data=self.get_enable_form(project))
     form = QueueSettingsForm(data=self.get_queue_settings_form(project))
     self.render(
         'admin/project/queue_settings.html',
         project_id=project_id,
         lower_shortcode=project.lower_shortcode(),
         form=form,
         enable_form=enable_form
     )
Example #19
0
    def get(self):
        add_project_form = AddProjectForm()
        projects = Project.all_project_infos()

        self.render(
            'admin/project/all.html',
            projects=projects,
            add_project_form=add_project_form,
            project_budgets=Budget.projects,
            project_stats=Stats.instance.get_project(),
        )
Example #20
0
    def get(self):
        add_project_form = AddProjectForm()
        projects = Project.all_project_infos()

        self.render(
            'admin/project/all.html',
            projects=projects,
            add_project_form=add_project_form,
            project_budgets=Budget.projects,
            project_stats=Stats.instance.get_project(),
        )
    def post(self, name):
        project = Project.get_plain(name)
        enable_form = QueueEnableForm(data=self.get_enable_form(project))
        form = QueueSettingsForm(data=self.get_queue_settings_form(project))

        message = None
        action = self.get_argument("action", None)

        if action == "enable":
            enable_form = QueueEnableForm(self.request.arguments)
            if enable_form.validate():
                with Project.get_session_object(name) as project:
                    project.enabled = enable_form.enabled.data
                    logger.info("Project %s enabled=%s", name, project.enabled)
            else:
                message = "Error."

        elif action == "autoqueue":
            form = QueueSettingsForm(self.request.arguments)
            if form.validate():
                with Project.get_session_object(name) as project:
                    project.autoqueue = form.autoqueue.data
                    project.num_count_per_item = form.num_count_per_item.data
                    project.max_num_items = form.max_num_items.data
                    project.lower_sequence_num = form.lower_sequence_num.data or 0
                    project.autorelease_time = form.autorelease_time.data * 60 or 0

                logger.debug("Project %s queue settings changed.", name)
                message = "Settings saved."
            else:
                message = "Error."
        else:
            message = "Error."

        Budget.calculate_budgets()

        self.render(
            "admin/project/queue_settings.html", project_name=name, form=form, enable_form=enable_form, message=message
        )
    def get(self, name):
        project = Project.get_plain(name)
        form = ProjectSettingsForm(
            alphabet=project.alphabet,
            banned_codes=project.banned_codes,
            body_regex=project.body_regex,
            method=project.method,
            min_version=project.min_version,
            min_client_version=project.min_client_version,
            no_redirect_codes=project.no_redirect_codes,
            redirect_codes=project.redirect_codes,
            request_delay=project.request_delay,
            url_template=project.url_template,
            unavailable_codes=project.unavailable_codes,
        )

        self.render("admin/project/shortener_settings.html", project_name=name, form=form)
Example #23
0
    def post(self, project_id):
        form = ProjectSettingsForm(self.request.arguments)
        message = None

        if form.validate():
            with Project.get_session_object(project_id) as project:
                form.populate_obj(project)

            logger.info(
                self.user_audit_text('Changed project %s shortener settings'),
                project_id)
            message = 'Settings saved.'
        else:
            message = 'Error.'

        self.render('admin/project/shortener_settings.html',
                    project_id=project_id,
                    form=form,
                    message=message)
Example #24
0
    def post(self, project_id):
        form = ProjectSettingsForm(self.request.arguments)
        message = None

        if form.validate():
            with Project.get_session_object(project_id) as project:
                form.populate_obj(project)

            logger.info(
                self.user_audit_text('Changed project %s shortener settings'),
                project_id)
            message = 'Settings saved.'
        else:
            message = 'Error.'

        self.render(
            'admin/project/shortener_settings.html',
            project_id=project_id, form=form,
            message=message
        )
 def get(self, name):
     project = Project.get_plain(name)
     enable_form = QueueEnableForm(data=self.get_enable_form(project))
     form = QueueSettingsForm(data=self.get_queue_settings_form(project))
     self.render("admin/project/queue_settings.html", project_name=name, form=form, enable_form=enable_form)