content.py 10.1 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
# 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

23
from cubes.seda.views import rtags_from_rtype_role_targets, viewlib, widgets
Yann Voté's avatar
Yann Voté committed
24
25
26
27
28

_ = unicode

pvs = uicfg.primaryview_section
afs = uicfg.autoform_section
29
30
31
32
33
34
35
36
37
38
39
40
affk = uicfg.autoform_field_kwargs
rec = uicfg.reledit_ctrl

afs.tag_subject_of(('SEDAKeywordReference', 'seda_keyword_reference_to_scheme', '*'),
                   'main', 'attributes')
affk.set_field_kwargs('SEDAKeywordReference', 'seda_keyword_reference_to',
                      widget=widgets.ConceptAutoCompleteWidget(
                          slave_name='seda_keyword_reference_to',
                          master_name='seda_keyword_reference_to_scheme'))
affk.set_fields_order('SEDAKeywordReference', ['user_cardinality',
                                               'seda_keyword_reference_to_scheme',
                                               'seda_keyword_reference_to'])
Yann Voté's avatar
Yann Voté committed
41

42
43
44
45
46
47
48
49
50
51
52
53
54
pvs.tag_subject_of(('SEDAContent', 'seda_description_level', '*'), 'attributes')
afs.tag_subject_of(('SEDAContent', 'seda_description_level', '*'), 'main', 'attributes')
for rtype in ('seda_description',
              'seda_type',
              'seda_document_type',
              'seda_language_from',
              'seda_description_language_from',
              'seda_status',
              'seda_version',
              ):
    pvs.tag_object_of(('*', rtype, 'SEDAContent'), 'attributes')
    afs.tag_object_of(('*', 'seda_description_level', 'SEDAContent'), 'main', 'attributes')

Yann Voté's avatar
Yann Voté committed
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
# Tabs fields

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'),
]

96
97
98
99
100
101
102
103
104
105
106
gps_rtype_role = [
    ('seda_gps_version_id', 'object'),
    ('seda_gps_altitude', 'object'),
    ('seda_gps_altitude_ref', 'object'),
    ('seda_gps_latitude', 'object'),
    ('seda_gps_latitude_ref', 'object'),
    ('seda_gps_longitude', 'object'),
    ('seda_gps_longitude_ref', 'object'),
    ('seda_gps_date_stamp', 'object'),
]

Yann Voté's avatar
Yann Voté committed
107
108
109
110
keyword_rtype_role = [
    ('seda_keyword', 'object'),
]

111
112
113
114
115
116
117
118
relation_rtype_role = [
    ('seda_is_version_of', 'object'),
    ('seda_replaces', 'object'),
    ('seda_requires', 'object'),
    ('seda_is_part_of', 'object'),
    ('seda_references', 'object'),
]

Yann Voté's avatar
Yann Voté committed
119
120
121
122
123
event_rtype_role = [
    ('seda_event', 'object'),
]

history_rtype_role = [
Yann Voté's avatar
Yann Voté committed
124
    ('seda_custodial_history_item', 'object'),
Yann Voté's avatar
Yann Voté committed
125
126
127
]

# Remove from relations section and autoform what is shown in tabs
128
for rtype, role in (itertools.chain(identification_rtype_role,
Yann Voté's avatar
Yann Voté committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
                                    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_identification_tab'),
        _('seda_content_date_tab'),
151
        _('seda_content_gps_tab'),
Yann Voté's avatar
Yann Voté committed
152
153
154
155
        _('seda_content_service_tab'),
        _('seda_content_agent_tab'),
        _('seda_content_coverage_tab'),
        _('seda_content_keyword_tab'),
156
        _('seda_content_relation_tab'),
Yann Voté's avatar
Yann Voté committed
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
        _('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 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)


187
188
189
190
191
192
193
194
195
class ContentGpsTab(tabs.PrimaryTab):
    """Display GPS information about an archive unit content."""

    __regid__ = 'seda_content_gps_tab'

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


Yann Voté's avatar
Yann Voté committed
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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)')


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
class ContentRelationTab(viewlib.SubObjectsTab):
    """Display relation information about an archive unit content."""

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

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

    _('creating SEDAIsVersionOf (SEDAIsVersionOf seda_is_version_of SEDAContent %(linkto)s)')
    _('creating SEDAReplaces (SEDAReplaces seda_replaces SEDAContent %(linkto)s)')
    _('creating SEDARequires (SEDARequires seda_requires SEDAContent %(linkto)s)')
    _('creating SEDAIsPartOf (SEDAIsPartOf seda_is_part_of SEDAContent %(linkto)s)')
    _('creating SEDAReferences (SEDAReferences seda_references SEDAContent %(linkto)s)')


Yann Voté's avatar
Yann Voté committed
256
257
258
259
260
261
262
263
264
265
266
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)')


Yann Voté's avatar
Yann Voté committed
267
class ContentHistoryTab(viewlib.SubObjectsTab):
Yann Voté's avatar
Yann Voté committed
268
269
270
    """Display custodial history information about an archive unit content."""

    __regid__ = 'seda_content_history_tab'
Yann Voté's avatar
Yann Voté committed
271
    __select__ = viewlib.SubObjectsTab.__select__ & is_instance('SEDAContent')
Yann Voté's avatar
Yann Voté committed
272
273

    rtype_role_targets = [(rtype, role, None) for rtype, role in history_rtype_role]
Yann Voté's avatar
Yann Voté committed
274
275
276

    _('creating SEDACustodialHistoryItem (SEDACustodialHistoryItem seda_custodial_history_item '
      'SEDAContent %(linkto)s)')