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

20
21
from logilab.mtconverter import xml_escape

Yann Voté's avatar
Yann Voté committed
22
23
24
from cubicweb.predicates import is_instance
from cubicweb.web.views import tabs, uicfg

25
26
from cubes.seda.views import rtags_from_rtype_role_targets, rtags_from_xsd_element
from cubes.seda.views import viewlib, widgets
Yann Voté's avatar
Yann Voté committed
27
28
29
30
31

_ = unicode

pvs = uicfg.primaryview_section
afs = uicfg.autoform_section
32
33
34
35
36
37
38
39
40
41
42
43
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
44

45
46
47
48
49
50
51
52
53
54
55
56
57
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
58
59
# Tabs fields

60
61
62
63
64
65
66
67
identification_rtype_role_targets = [
    ('seda_source', 'object', None),
    ('seda_file_plan_position', 'object', None),
    ('seda_system_id', 'object', None),
    ('seda_originating_system_id', 'object', None),
    ('seda_archival_agency_archive_unit_identifier', 'object', None),
    ('seda_originating_agency_archive_unit_identifier', 'object', None),
    ('seda_transferring_agency_archive_unit_identifier', 'object', None),
Yann Voté's avatar
Yann Voté committed
68
69
]

70
71
72
73
service_rtype_role_targets = [
    ('seda_originating_agency_from', 'object', None),
    ('seda_submission_agency_from', 'object', None),
    ('seda_authorized_agent_from', 'object', None),
Yann Voté's avatar
Yann Voté committed
74
75
]

76
77
78
79
agent_rtype_role_targets = [
    ('seda_writer_from', 'object', None),
    ('seda_addressee_from', 'object', None),
    ('seda_recipient_from', 'object', None),
Yann Voté's avatar
Yann Voté committed
80
81
82
]


83
84
85
86
87
88
89
90
91
date_rtype_role_targets = [
    ('seda_created_date', 'object', None),
    ('seda_transacted_date', 'object', None),
    ('seda_acquired_date', 'object', None),
    ('seda_sent_date', 'object', None),
    ('seda_received_date', 'object', None),
    ('seda_registered_date', 'object', None),
    ('seda_start_date', 'object', None),
    ('seda_end_date', 'object', None),
92
93
]

94
95
keyword_rtype_role_targets = [
    ('seda_keyword', 'object', None),
Yann Voté's avatar
Yann Voté committed
96
97
]

98
99
event_rtype_role_targets = [
    ('seda_event', 'object', None),
Yann Voté's avatar
Yann Voté committed
100
101
102
]

# Remove from relations section and autoform what is shown in tabs
103
104
105
106
107
108
for rtype, role, __ in (itertools.chain(identification_rtype_role_targets,
                                        service_rtype_role_targets,
                                        agent_rtype_role_targets,
                                        date_rtype_role_targets,
                                        keyword_rtype_role_targets,
                                        event_rtype_role_targets)):
Yann Voté's avatar
Yann Voté committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    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'),
124
        _('seda_content_gps_tab'),
Yann Voté's avatar
Yann Voté committed
125
126
127
128
        _('seda_content_service_tab'),
        _('seda_content_agent_tab'),
        _('seda_content_coverage_tab'),
        _('seda_content_keyword_tab'),
129
        _('seda_content_relation_tab'),
Yann Voté's avatar
Yann Voté committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
        _('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'

147
    rtype_role_targets = identification_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
148
149
150
151
152
153
154
155
    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'

156
    rtype_role_targets = date_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
157
158
159
    rsection, display_ctrl = rtags_from_rtype_role_targets('SEDAContent', rtype_role_targets)


160
161
162
163
164
class ContentGpsTab(tabs.PrimaryTab):
    """Display GPS information about an archive unit content."""

    __regid__ = 'seda_content_gps_tab'

165
    rsection, display_ctrl = rtags_from_xsd_element('SEDAContent', 'Gps')
166
167


Yann Voté's avatar
Yann Voté committed
168
169
170
171
172
class ContentServiceTab(tabs.PrimaryTab):
    """Display service information about an archive unit content."""

    __regid__ = 'seda_content_service_tab'

173
    rtype_role_targets = service_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
174
175
176
177
178
179
180
181
182
    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')

183
    rtype_role_targets = agent_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
184
185
186
187
188
189
190
191
192
193
194

    _('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'

195
196
197
    rtype_role_targets = [('seda_spatial', 'object', None),
                          ('seda_temporal', 'object', None),
                          ('seda_juridictional', 'object', None)]
Yann Voté's avatar
Yann Voté committed
198
199
200
201
202
203
204
205
206
207
208
209

    _('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')

210
    rtype_role_targets = keyword_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
211
212
213
214

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


215
216
217
218
219
220
class ContentRelationTab(viewlib.SubObjectsTab):
    """Display relation information about an archive unit content."""

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

221
222
223
224
225
    rtype_role_targets = [('seda_is_version_of', 'object', None),
                          ('seda_replaces', 'object', None),
                          ('seda_requires', 'object', None),
                          ('seda_is_part_of', 'object', None),
                          ('seda_references', 'object', None)]
226
227
228
229
230
231
232
233

    _('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
234
235
236
237
238
239
class ContentEventTab(viewlib.SubObjectsTab):
    """Display events about an archive unit content."""

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

240
    rtype_role_targets = event_rtype_role_targets
Yann Voté's avatar
Yann Voté committed
241
242
243
244

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


Yann Voté's avatar
Yann Voté committed
245
class ContentHistoryTab(viewlib.SubObjectsTab):
Yann Voté's avatar
Yann Voté committed
246
247
248
    """Display custodial history information about an archive unit content."""

    __regid__ = 'seda_content_history_tab'
Yann Voté's avatar
Yann Voté committed
249
    __select__ = viewlib.SubObjectsTab.__select__ & is_instance('SEDAContent')
Yann Voté's avatar
Yann Voté committed
250

251
    rtype_role_targets = [('seda_custodial_history_item', 'object', None)]
Yann Voté's avatar
Yann Voté committed
252
253
254

    _('creating SEDACustodialHistoryItem (SEDACustodialHistoryItem seda_custodial_history_item '
      'SEDAContent %(linkto)s)')
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285


class KeywordBusinessValueEntityView(viewlib.LinkMetaEntityView):
    __select__ = viewlib.BusinessValueEntityView.__select__ & is_instance('SEDAKeyword')

    def entity_call(self, entity):
        if entity.seda_keyword_content[0].keyword_content:
            content = entity.seda_keyword_content[0].keyword_content
        else:
            content = self._cw._('<no value specified>')
        msg = xml_escape(self._cw._('keyword: {0}').format(content))
        self.w(u'<span class="value">{0} {1}</span>'.format(msg, entity.view('seda.xsdmeta')))
        if entity.reverse_seda_keyword_type_from:
            kwt = entity.reverse_seda_keyword_type_from[0]
            if kwt.seda_keyword_type_to:
                kwt_value = kwt.seda_keyword_type_to[0].label()
            else:
                kwt_value = self._cw._('<no type specified>')
            msg = xml_escape(self._cw._('keyword type: {0}').format(kwt_value))
            self.w(u'<br/><span>{0} {1}</span>'.format(msg, kwt.view('seda.xsdmeta')))
        if entity.reverse_seda_keyword_reference_from:
            kwr = entity.reverse_seda_keyword_reference_from[0]
            if kwr.concept:
                kwr_value = kwr.concept.view('oneline')
                msg = xml_escape(self._cw._('keyword reference: {0}')).format(kwr_value)
            elif kwr.scheme:
                kwr_value = kwr.scheme.view('oneline')
                msg = xml_escape(self._cw._('keyword scheme: {0}')).format(kwr_value)
            else:
                msg = xml_escape(self._cw._('<no reference specified>'))
            self.w(u'<br/><span>{0} {1}</span>'.format(msg, kwr.view('seda.xsdmeta')))