content.py 7.84 KB
Newer Older
Yann Voté's avatar
Yann Voté committed
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

"""cubicweb-seda views for content of archive units."""

import itertools

from cubicweb.predicates import is_instance
from cubicweb.web.views import tabs, uicfg

from cubes.seda.views import rtags_from_rtype_role_targets, viewlib

_ = unicode

pvs = uicfg.primaryview_section
afs = uicfg.autoform_section

# Tabs fields
description_rtype_role = [
    ('seda_description_level', 'subject'),
    ('seda_description', 'object'),
    ('seda_type', 'object'),
    ('seda_document_type', 'object'),
    ('seda_language_from', 'object'),
    ('seda_description_language_from', 'object'),
    ('seda_status', 'object'),
    ('seda_version', 'object'),
    ('seda_gps', 'object'),
]

identification_rtype_role = [
    ('seda_source', 'object'),
    ('seda_file_plan_position', 'object'),
    ('seda_system_id', 'object'),
    ('seda_originating_system_id', 'object'),
    ('seda_archival_agency_archive_unit_identifier', 'object'),
    ('seda_originating_agency_archive_unit_identifier', 'object'),
    ('seda_transferring_agency_archive_unit_identifier', 'object'),
]

service_rtype_role = [
    ('seda_originating_agency_from', 'object'),
    ('seda_submission_agency_from', 'object'),
    ('seda_authorized_agent_from', 'object'),
]

agent_rtype_role = [
    ('seda_writer_from', 'object'),
    ('seda_addressee_from', 'object'),
    ('seda_recipient_from', 'object'),
]

coverage_rtype_role = [
    ('seda_spatial', 'object'),
    ('seda_temporal', 'object'),
    ('seda_juridictional', 'object'),
]

date_rtype_role = [
    ('seda_created_date', 'object'),
    ('seda_transacted_date', 'object'),
    ('seda_acquired_date', 'object'),
    ('seda_sent_date', 'object'),
    ('seda_received_date', 'object'),
    ('seda_registered_date', 'object'),
    ('seda_start_date', 'object'),
    ('seda_end_date', 'object'),
]

keyword_rtype_role = [
    ('seda_keyword', 'object'),
]

event_rtype_role = [
    ('seda_event', 'object'),
]

history_rtype_role = [
    ('seda_custodial_history', 'object'),
]

# Remove from relations section and autoform what is shown in tabs
for rtype, role in (itertools.chain(description_rtype_role,
                                    identification_rtype_role,
                                    service_rtype_role,
                                    agent_rtype_role,
                                    coverage_rtype_role,
                                    date_rtype_role,
                                    keyword_rtype_role,
                                    event_rtype_role,
                                    history_rtype_role)):
    if role == 'object':
        pvs.tag_object_of(('*', rtype, 'SEDAContent'), 'hidden')
        afs.tag_object_of(('*', rtype, 'SEDAContent'), 'main', 'hidden')
    else:
        pvs.tag_subject_of(('SEDAContent', rtype, '*'), 'hidden')
        afs.tag_subject_of(('SEDAContent', rtype, '*'), 'main', 'hidden')


class ContentTabbedPrimaryView(tabs.TabbedPrimaryView):
    __select__ = tabs.TabbedPrimaryView.__select__ & is_instance('SEDAContent')

    tabs = [
        'main_tab',
        _('seda_content_advanced_description_tab'),
        _('seda_content_identification_tab'),
        _('seda_content_date_tab'),
        _('seda_content_service_tab'),
        _('seda_content_agent_tab'),
        _('seda_content_coverage_tab'),
        _('seda_content_keyword_tab'),
        _('seda_content_event_tab'),
        _('seda_content_history_tab'),
    ]


class AbstractContentPrimaryTab(tabs.PrimaryTab):
    """Generic class for tabs display content information."""

    __abstract__ = True
    __select__ = tabs.PrimaryTab.__select__ & is_instance('SEDAContent')


class ContentDescriptionTab(tabs.PrimaryTab):
    """Display identification data about an archive unit content."""

    __regid__ = 'seda_content_advanced_description_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in description_rtype_role]
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)


class ContentIdentificationTab(tabs.PrimaryTab):
    """Display identification data about an archive unit content."""

    __regid__ = 'seda_content_identification_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in identification_rtype_role]
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)


class ContentDateTab(tabs.PrimaryTab):
    """Display date information about an archive unit content."""

    __regid__ = 'seda_content_date_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in date_rtype_role]
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)


class ContentServiceTab(tabs.PrimaryTab):
    """Display service information about an archive unit content."""

    __regid__ = 'seda_content_service_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in service_rtype_role]
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)


class ContentAgentTab(viewlib.SubObjectsTab):
    """Display keywords about an archive unit content."""

    __regid__ = 'seda_content_agent_tab'
    __select__ = viewlib.SubObjectsTab.__select__ & is_instance('SEDAContent')

    rtype_role_targets = [(rtype, role, None) for rtype, role in agent_rtype_role]

    _('creating SEDAWriter (SEDAWriter seda_writer_from SEDAContent %(linkto)s)')
    _('creating SEDAAddressee (SEDAAddressee seda_addressee_from SEDAContent %(linkto)s)')
    _('creating SEDARecipient (SEDARecipient seda_recipient_from SEDAContent %(linto)s)')


class ContentCoverageTab(viewlib.SubObjectsTab):
    """Display coverage information about an archive unit content."""

    __regid__ = 'seda_content_coverage_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in coverage_rtype_role]

    _('creating SEDASpatial (SEDASpatial seda_spatial SEDAContent %(linkto)s)')
    _('creating SEDATemporal (SEDATemporal seda_temporal SEDAContent %(linkto)s)')
    _('creating SEDAJuridictional (SEDAJuridictional seda_juridictional SEDAContent %(linkto)s)')


class ContentKeywordTab(viewlib.SubObjectsTab):
    """Display keywords about an archive unit content."""

    __regid__ = 'seda_content_keyword_tab'
    __select__ = viewlib.SubObjectsTab.__select__ & is_instance('SEDAContent')

    rtype_role_targets = [(rtype, role, None) for rtype, role in keyword_rtype_role]

    _('creating SEDAKeyword (SEDAKeyword seda_keyword SEDAContent %(linkto)s)')


class ContentEventTab(viewlib.SubObjectsTab):
    """Display events about an archive unit content."""

    __regid__ = 'seda_content_event_tab'
    __select__ = viewlib.SubObjectsTab.__select__ & is_instance('SEDAContent')

    rtype_role_targets = [(rtype, role, None) for rtype, role in event_rtype_role]

    _('creating SEDAEvent (SEDAEvent seda_event SEDAContent %(linkto)s)')


class ContentHistoryTab(tabs.PrimaryTab):
    """Display custodial history information about an archive unit content."""

    __regid__ = 'seda_content_history_tab'

    rtype_role_targets = [(rtype, role, None) for rtype, role in history_rtype_role]
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)