~lifeeth/sahana-eden/ifrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-

"""
    Flood Alerts Module - Controllers

    @author: Fran Boon
    @see: http://eden.sahanafoundation.org/wiki/Pakistan
"""

module = request.controller
resourcename = request.function

if module not in deployment_settings.modules:
    raise HTTP(404, body="Module disabled: %s" % module)

# Options Menu (available in all Functions' Views)
s3_menu(module)

def index():

    """ Custom View """

    module_name = deployment_settings.modules[module].name_nice
    response.title = module_name
    return dict(module_name=module_name)


def river():

    """ Rivers, RESTful controller """

    # Post-processor
    def user_postp(r, output):
        s3_action_buttons(r, deletable=False)
        return output
    response.s3.postp = user_postp

    output = s3_rest_controller()
    return output


def freport():

    """ Flood Reports, RESTful controller """
    tablename = "%s_%s" % (module, resourcename)
    table = db[tablename]

    # Disable legacy fields, unless updating, so the data can be manually transferred to new fields
    #if "update" not in request.args:
    #    table.document.readable = table.document.writable = False

    # Post-processor
    def postp(r, output):
        s3_action_buttons(r, deletable=False)
        return output
    response.s3.postp = postp

    rheader = lambda r: flood_rheader(r, tabs = [(T("Basic Details"), None),
                                                 (T("Locations"), "freport_location")
                                                ])
    output = s3_rest_controller(module, resourcename, rheader=rheader)
    return output

# -----------------------------------------------------------------------------
def flood_rheader(r, tabs=[]):

    """ Resource Headers """

    if r.representation == "html":
        if r.name == "freport":
            report = r.record
            if report:
                rheader_tabs = s3_rheader_tabs(r, tabs)
                location = report.location_id
                if location:
                    location = s3db.gis_location_represent(location)
                rheader = DIV(TABLE(
                                TR(
                                    TH(T("Location") + ": "), location,
                                    TH(T("Date") + ": "), report.datetime
                                  ),
                                ),
                              rheader_tabs)

                return rheader

    return None