Exemplo n.º 1
0
    def test_edit_resource(self):
        """ Edit this resource successfully. """
        params = {
            'label': 'signup',
            'email': '*****@*****.**',
            'question': 'Cool.',
            'status': 'open',
        }

        issue = Issue(**params)
        issue.save()

        params_edit = {
            'label': 'other',
            'email': '*****@*****.**',
            'question': 'Cool.',
            'status': 'closed',
        }

        self.login()
        response = self.client.post(url_for('admin.issues_edit', id=issue.id),
                                    data=params_edit, follow_redirects=True)

        assert_status_with_message(200, response,
                                   _('Issue has been saved successfully.'))
Exemplo n.º 2
0
def issues_edit(id):
    issue = Issue.query.get(id)

    if request.method == 'GET' and issue and issue.status == 'unread':
        issue = Issue.unread_to_open(issue)

    form = IssueForm(obj=issue)

    subject = _('[Catwatch issue] Re: %(issue_type)s',
                issue_type=issue.LABEL[issue.label])

    # Shenanigans to comply with PEP-8's formatting style.
    body_string = '\n\nYou opened an issue regarding:'
    issue_string = '\n\n---\n{0}\n---\n\n'.format(issue.question)
    message = _('Hello,%(body)s:%(issue)s\n\nThanks,\nCatwatch support team',
                body=body_string, issue=issue_string)

    contact_form = IssueContactForm(email=issue.email,
                                    subject=subject, message=message)

    if form.validate_on_submit():
        form.populate_obj(issue)
        issue.save()

        flash(_('Issue has been saved successfully.'), 'success')
        return redirect(url_for('admin.issues'))

    return render_template('admin/issue/edit.jinja2', form=form,
                           contact_form=contact_form, issue=issue)
Exemplo n.º 3
0
def issues(page):
    search_form = SearchForm()
    bulk_form = BulkDeleteForm()

    sort_by = Issue.sort_by(request.args.get('sort', 'status'),
                            request.args.get('direction', 'asc'))
    order_values = '{0} {1}'.format(sort_by[0], sort_by[1])

    paginated_issues = Issue.query \
        .filter(Issue.search(request.args.get('q', ''))) \
        .order_by(text(order_values)) \
        .paginate(page, 20, True)

    return render_template('admin/issue/index.jinja2',
                           form=search_form, bulk_form=bulk_form,
                           issues=paginated_issues, LABEL=Issue.LABEL)
Exemplo n.º 4
0
def issues_contact(id):
    issue = Issue.query.get(id)

    if issue:
        from catwatch.blueprints.admin.tasks import deliver_support_email
        deliver_support_email.delay(id,
                                    request.form.get('subject'),
                                    request.form.get('message'))

        Issue.set_as_contacted(issue)

        flash(_('The person who sent the issue has been contacted.'),
              'success')
    else:
        flash(_('Issue no longer exists, no e-mail was sent.'), 'error')

    return redirect(url_for('admin.issues'))
Exemplo n.º 5
0
def issues_bulk_delete():
    form = BulkDeleteForm()

    if form.validate_on_submit():
        ids = Issue.get_bulk_action_ids(request.form.get('scope'),
                                        request.form.getlist('bulk_ids'),
                                        query=request.args.get('q', ''))

        delete_count = Issue.bulk_delete(ids)

        flash(_n('%(num)d issue was deleted.',
                 '%(num)d issues were deleted.',
                 num=delete_count), 'success')
    else:
        flash(_('No issues were deleted, something went wrong.'), 'error')

    return redirect(url_for('admin.issues'))
Exemplo n.º 6
0
def support():
    # Pre-populate the email field if the user is signed in.
    form = SupportForm(obj=current_user)

    if form.validate_on_submit():
        i = Issue()

        form.populate_obj(i)
        i.save()

        # This prevents circular imports.
        from catwatch.blueprints.issue.tasks import deliver_support_email

        deliver_support_email.delay(i.id)

        flash(_('Help is on the way, expect a response shortly.'), 'success')
        return redirect(url_for('issue.support'))

    return render_template('issue/support.jinja2', form=form)
Exemplo n.º 7
0
def support():
    # Pre-populate the email field if the user is signed in.
    form = SupportForm(obj=current_user)

    if form.validate_on_submit():
        i = Issue()

        form.populate_obj(i)
        i.save()

        # This prevents circular imports.
        from catwatch.blueprints.issue.tasks import deliver_support_email

        deliver_support_email.delay(i.id)

        flash(_('Help is on the way, expect a response shortly.'), 'success')
        return redirect(url_for('issue.support'))

    return render_template('issue/support.jinja2', form=form)