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

OCHA-DAP / hdx-ckan / #5208

09 Apr 2024 01:51PM UTC coverage: 71.377% (+0.07%) from 71.303%
#5208

push

coveralls-python

danmihaila
HDX-9447 new org request

58 of 68 new or added lines in 3 files covered. (85.29%)

10 existing lines in 1 file now uncovered.

11668 of 16347 relevant lines covered (71.38%)

0.71 hits per line

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

83.08
/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✔
48
    except NotAuthorized:
×
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
        context['dan']='123'
1✔
73
        return redirect('hdx_org_request.completed_request')
1✔
74
    def get(self,
1✔
75
            data: Optional[dict[str, Any]] = None,
76
            errors: Optional[dict[str, Any]] = None,
77
            error_summary: Optional[dict[str, Any]] = None) -> str:
NEW
78
        context = _prepare_and_check_access()
×
NEW
79
        extra_vars = {
×
80
            u'data': data or {},
81
            u'errors': errors or {},
82
            u'error_summary': error_summary or {}
83
        }
NEW
84
        return render('org/request/org_new_request.html', extra_vars=extra_vars)
×
85

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

93

94
hdx_org_request.add_url_rule(u'/', view_func=org_request, strict_slashes=False)
1✔
95
hdx_org_request.add_url_rule(u'/new/', view_func=OrgNewRequestView.as_view(str(u'new')),
1✔
96
                                 methods=[u'GET', u'POST'], strict_slashes=False)
97
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