Commit 6a5ac9df authored by Vincent Michel's avatar Vincent Michel
Browse files

[views] Add startup view

parent cb19dea70703
......@@ -17,7 +17,92 @@
"""cubicweb-accidents views/forms/actions/components for web ui"""
from cubicweb.web import facet
from cubicweb.selectors import is_instance
from cubicweb.selectors import is_instance, match_user_groups
from cubicweb.web.views import uicfg
from cubicweb.web.views.boxes import EditBox
from cubicweb.web.views.bookmark import BookmarksBox
from cubicweb.web.views.startup import IndexView
from cubes.bootstrap.views.basecomponents import BSRQLInputForm
# Always make RQL input form visible for the main page
BSRQLInputForm.visible = True
# Avoid empty left column for anon
BookmarksBox.__select__ = BookmarksBox.__select__ & match_user_groups('users', 'managers')
EditBox.__select__ = EditBox.__select__ & match_user_groups('users', 'managers')
_pvs = uicfg.primaryview_section
_pvdc = uicfg.primaryview_display_ctrl
_pvs.tag_subject_of(('Accident', 'implique', '*'), 'relations')
_pvdc.tag_subject_of(('Accident', 'implique', '*'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'implique', 'Vehicule'), 'attributes')
_pvs.tag_object_of(('*', 'organisme', 'Organisme'), 'relations')
_pvdc.tag_object_of(('*', 'organisme', 'Organisme'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'luminosite', 'Luminosite'), 'relations')
_pvdc.tag_object_of(('*', 'luminosite', 'Luminosite'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'agglomeration', 'Agglomeration'), 'relations')
_pvdc.tag_object_of(('*', 'agglomeration', 'Agglomeration'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'intersection', 'Intersection'), 'relations')
_pvdc.tag_object_of(('*', 'intersection', 'Intersection'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'meteo', 'Meteo'), 'relations')
_pvdc.tag_object_of(('*', 'meteo', 'Meteo'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'collision', 'Collision'), 'relations')
_pvdc.tag_object_of(('*', 'collision', 'Collision'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'route', 'Route'), 'relations')
_pvdc.tag_object_of(('*', 'route', 'Route'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'situation', 'Situation'), 'relations')
_pvdc.tag_object_of(('*', 'situation', 'Situation'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'infrastructure', 'Infrastructure'), 'relations')
_pvdc.tag_object_of(('*', 'infrastructure', 'Infrastructure'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'voie_speciale', 'VoieSpeciale'), 'relations')
_pvdc.tag_object_of(('*', 'voie_speciale', 'VoieSpeciale'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'profil', 'Profil'), 'relations')
_pvdc.tag_object_of(('*', 'profil', 'Profil'), {'limit': None, 'vid': 'table'})
_pvs.tag_object_of(('*', 'trace_plan', 'TracePlan'), 'relations')
_pvdc.tag_object_of(('*', 'trace_plan', 'TracePlan'), {'limit': None, 'vid': 'table'})
class AccidentsIndexView(IndexView):
def call(self, **kwargs):
w = self.w
# Presentation
w(u'<h2>%s</h2>' % self._cw.property_value('ui.site-title'))
rset = self._cw.execute('Any X WHERE X is Card, X wikiid %(t)s', {'t': 'index'})
if rset:
w(u'<p>%s</p>' % rset.get_entity(0, 0).printable_value('content'))
# Browse
self.w(u'<div class="row">')
for etype in ('Accident', 'Vehicule'):
self.w(u'<div class="col-md-offset-1 col-md-4">')
self.w(u'<div class="panel panel-primary">')
self.w(u'<div class="panel-heading"><h3 class="panel-title">%s</h3></div>'
% self._cw._(etype))
content = self._cw._('Voir les %(t)s disponibles en base' % {'t': self._cw._(etype)})
url = self._cw.build_url(rql='Any X WHERE X is %s' % etype)
content = u'<a href="%s">%s</a>' % (url, content)
self.w(u'<div class="panel-body">%s</div>' % content)
self.w(u'</div>')
self.w(u'</div>')
self.w(u'</div>')
# Search
self.w(u'<div class="row">')
# RQL
self.w(u'<div class="col-md-offset-1 col-md-9">')
self.w(u'<div class="panel panel-info">')
self.w(u'<div class="panel-heading"><h3 class="panel-title">%s</h3></div>'
% self._cw._('Explorez en RQL'))
self.w(u'<div class="panel-body">')
self.w(self._cw._("RQL est un language de requete semantic permettant une recherche en profondeur des donnees avec une reelle simplicite d'utilisation. Vous pouvez consulter la <a href='%(doc)s'>documentation</a> ou voir le <a href='%(schema)s'>modele de donnees</a>")
% {'doc': self._cw.build_url('doc/tut_rql'),
'schema': self._cw.build_url('schema')})
rset = self._cw.execute('Any X WHERE X is Card, X wikiid %(t)s', {'t': 'examples'})
if rset:
w(u'<p>%s</p>' % rset.get_entity(0, 0).printable_value('content'))
self.w(u'</div></div></div>')
self.w(u'</div>')# Row
# Facets - Vehicules
......@@ -115,3 +200,8 @@ class AccidentAffectationFacet(facet.RQLPathFacet):
filter_variable = 'AP'
label_variable = 'N'
title = 'Affectation'
def registration_callback(vreg):
vreg.register_all(globals().values(), __name__, (AccidentsIndexView,))
vreg.register_and_replace(AccidentsIndexView, IndexView)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment