• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OCHA-DAP / hdx-ckan / #5218

11 Apr 2024 11:29AM UTC coverage: 71.375% (+0.06%) from 71.316%
#5218

Pull #6302

coveralls-python

danmihaila
HDX-9444 HDX-9443 HDX-9442 review email subject
Pull Request #6302: Feature/dev org join hdx 9447

98 of 110 new or added lines in 10 files covered. (89.09%)

14 existing lines in 2 files now uncovered.

11667 of 16346 relevant lines covered (71.38%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.81
/ckanext-hdx_org_group/ckanext/hdx_org_group/views/organization_request.py
1
import logging
1✔
2
from typing import Any, Optional, Union, cast
1✔
3

4
from flask import Blueprint
1✔
5
from flask.views import MethodView
1✔
6

7
import ckan.lib.navl.dictization_functions as dictization_functions
1✔
8
import ckan.logic as logic
1✔
9
import ckan.model as model
1✔
10
import ckan.plugins.toolkit as tk
1✔
11
from ckan.common import current_user
1✔
12
from ckan.types import Context, Response
1✔
13
from ckanext.hdx_org_group.controller_logic.organization_request_logic import OrgRequestLogic
1✔
14

15
log = logging.getLogger(__name__)
1✔
16

17
# shortcuts
18
h = tk.h
1✔
19
get_action = tk.get_action
1✔
20
NotAuthorized = tk.NotAuthorized
1✔
21
NotFound = tk.ObjectNotFound
1✔
22
ValidationError = tk.ValidationError
1✔
23
clean_dict = logic.clean_dict
1✔
24
tuplize_dict = logic.tuplize_dict
1✔
25
parse_params = logic.parse_params
1✔
26
redirect = h.redirect_to
1✔
27
url_for = tk.url_for
1✔
28
check_access = tk.check_access
1✔
29
abort = tk.abort
1✔
30
render = tk.render
1✔
31
g = tk.g
1✔
32
_ = tk._
1✔
33
request = tk.request
1✔
34

35
hdx_org_request = Blueprint(u'hdx_org_request', __name__, url_prefix=u'/org/request')
1✔
36

37

38
def _prepare_and_check_access() -> Context:
1✔
39
    context = cast(Context, {
1✔
40
        u'model': model,
41
        u'session': model.Session,
42
        u'user': current_user.name,
43
        u'auth_user_obj': current_user,
44
        u'save': u'save' in request.form,
45
    })
46
    try:
1✔
47
        check_access(u'hdx_send_new_org_request', context)
1✔
NEW
48
    except NotAuthorized:
×
NEW
49
        abort(403, _(u'Page not found'))
×
50
    return context
1✔
51

52

53
def org_request() -> str:
1✔
NEW
54
    return redirect(url_for('hdx_org_request.new'))
×
55

56
class OrgNewRequestView(MethodView):
1✔
57

58
    def post(self) -> Union[Response, str]:
1✔
59
        context = _prepare_and_check_access()
1✔
60
        data_dict = None
1✔
61
        org_request_logic = OrgRequestLogic(context, request)
1✔
62
        try:
1✔
63
            data_dict = org_request_logic.read()
1✔
NEW
64
        except dictization_functions.DataError:
×
NEW
65
            abort(400, _(u'Integrity Error'))
×
66

67
        data, errors = org_request_logic.validate(data_dict)
1✔
68
        if errors:
1✔
NEW
69
            return self.get(data, errors)
×
70

71
        get_action('hdx_send_new_org_request')(context, data)
1✔
72
        return redirect('hdx_org_request.completed_request')
1✔
73
    def get(self,
1✔
74
            data: Optional[dict[str, Any]] = None,
75
            errors: Optional[dict[str, Any]] = None,
76
            error_summary: Optional[dict[str, Any]] = None) -> str:
NEW
77
        context = _prepare_and_check_access()
×
NEW
78
        extra_vars = {
×
79
            u'data': data or {},
80
            u'errors': errors or {},
81
            u'error_summary': error_summary or {}
82
        }
NEW
83
        return render('org/request/org_new_request.html', extra_vars=extra_vars)
×
84

85
def completed_request() -> str:
1✔
86
    if request and request.referrer and '/org/request/new' in request.referrer:
1✔
NEW
87
        context = _prepare_and_check_access()
×
NEW
88
        return render('org/request/completed_request.html')
×
89
    else:
90
        abort(404, _(u'Page not found'))
1✔
91

92

93
hdx_org_request.add_url_rule(u'/', view_func=org_request, strict_slashes=False)
1✔
94
hdx_org_request.add_url_rule(u'/new/', view_func=OrgNewRequestView.as_view(str(u'new')),
1✔
95
                                 methods=[u'GET', u'POST'], strict_slashes=False)
96
hdx_org_request.add_url_rule(u'/completed/', view_func=completed_request, methods=[u'GET'], strict_slashes=False)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc