예제 #1
0
파일: tabs.py 프로젝트: zogzog/cubicweb
 def active_tab(self, default):
     if 'tab' in self._cw.form:
         return self._cw.form['tab']
     cookies = self._cw.get_cookie()
     cookiename = self.cookie_name
     activetab = cookies.get(cookiename)
     if activetab is None:
         domid = uilib.domid(default)
         self._cw.set_cookie(cookiename, domid)
         return domid
     return activetab.value
예제 #2
0
파일: tabs.py 프로젝트: zogzog/cubicweb
 def prune_tabs(self, tabs, default_tab):
     selected_tabs = []
     may_be_active_tab = self.active_tab(default_tab)
     active_tab = uilib.domid(default_tab)
     viewsvreg = self._cw.vreg['views']
     for tab in tabs:
         if isinstance(tab, str):
             tabid, tabkwargs = tab, {}
         else:
             tabid, tabkwargs = tab
             tabkwargs = tabkwargs.copy()
         tabkwargs.setdefault('rset', self.cw_rset)
         vid = tabkwargs.get('vid', tabid)
         domid = uilib.domid(tabid)
         try:
             viewsvreg.select(vid, self._cw, tabid=domid, **tabkwargs)
         except NoSelectableObject:
             continue
         selected_tabs.append((tabid, domid, tabkwargs))
         if domid == may_be_active_tab:
             active_tab = domid
     return selected_tabs, active_tab
예제 #3
0
파일: tabs.py 프로젝트: zogzog/cubicweb
 def lazyview(self,
              vid,
              rql=None,
              eid=None,
              rset=None,
              tabid=None,
              reloadable=False,
              show_spinbox=True,
              w=None):
     """a lazy version of wview"""
     w = w or self.w
     self._cw.add_js('cubicweb.ajax.js')
     # the form is copied into urlparams to please the inner views
     # that might want to take params from it
     # beware of already present rql or eid elements
     # to be safe of collision a proper argument passing protocol
     # (with namespaces) should be used instead of the current
     # ad-hockery
     urlparams = self._cw.form.copy()
     urlparams.pop('rql', None)
     urlparams.pop('eid', None)
     urlparams.update({'vid': vid, 'fname': 'view'})
     if rql:
         urlparams['rql'] = rql
     elif eid:
         urlparams['eid'] = eid
     elif rset:
         urlparams['rql'] = rset.printable_rql()
     if tabid is None:
         tabid = uilib.domid(vid)
     w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' %
       (tabid, xml_escape(self._cw.build_url('ajax', **urlparams))))
     if show_spinbox:
         # Don't use ``alt`` since image is a *visual* helper for ajax
         w(u'<img style="display: none" src="%s" alt="" id="%s-hole"/>' %
           (xml_escape(self._cw.data_url('loading.gif')), tabid))
     else:
         w(u'<div id="%s-hole"></div>' % tabid)
     w(u'<noscript><p>%s <a id="seo-%s" href="%s">%s</a></p></noscript>' %
       (xml_escape(self._cw._('Link:')), tabid,
        xml_escape(self._cw.build_url(**urlparams)),
        xml_escape(self._cw._(tabid))))
     w(u'</div>')
     self._prepare_bindings(tabid, reloadable)
예제 #4
0
 def domid(self):
     return domid(self.__regid__) + str(self.entity.eid)
예제 #5
0
 def domid(self):
     """return the HTML DOM identifier for this component"""
     return domid(self.__regid__)
예제 #6
0
 def cssclass(self):
     """return the CSS class name for this component"""
     return domid(self.__regid__)
예제 #7
0
파일: view.py 프로젝트: gurneyalex/cubicweb
 def domid(self):
     return '%sComponent' % domid(self.__regid__)
예제 #8
0
파일: view.py 프로젝트: gurneyalex/cubicweb
 def cssclass(self):
     return '%s %s' % (self.htmlclass, domid(self.__regid__))
예제 #9
0
파일: view.py 프로젝트: gurneyalex/cubicweb
 def domid(self):
     return domid(self.__regid__)
예제 #10
0
class SimpleReqRewriter(URLRewriter):
    """The SimpleReqRewriters uses a `rules` dict that maps input URI
    (regexp or plain string) to a dictionary to update the request's
    form.

    If the input uri is a regexp, group substitution is allowed.
    """
    __regid__ = 'simple'

    rules = [
        ('/_', dict(vid='manage')),
        ('/_registry', dict(vid='registry')),
        #        (rgx('/_([^/]+?)/?'), dict(vid=r'\1')),
        ('/schema', dict(vid='schema')),
        ('/index', dict(vid='index')),
        ('/myprefs', dict(vid='propertiesform')),
        ('/siteconfig', dict(vid='systempropertiesform')),
        ('/siteinfo', dict(vid='siteinfo')),
        ('/manage', dict(vid='manage')),
        ('/notfound', dict(vid='404')),
        ('/error', dict(vid='error')),
        ('/sparql', dict(vid='sparql')),
        ('/processinfo', dict(vid='processinfo')),
        (rgx('/cwuser', re.I),
         dict(vid='cw.users-and-groups-management',
              tab=domid('cw.users-management'))),
        (rgx('/cwgroup', re.I),
         dict(vid='cw.users-and-groups-management',
              tab=domid('cw.groups-management'))),
        (rgx('/cwsource', re.I), dict(vid='cw.sources-management')),
        # XXX should be case insensitive as 'create', but I would like to find another way than
        # relying on the etype_selector
        (rgx('/schema/([^/]+?)/?'),
         dict(vid='primary', rql=r'Any X WHERE X is CWEType, X name "\1"')),
        (rgx('/add/([^/]+?)/?'), dict(vid='creation', etype=r'\1')),
        (rgx('/doc/images/(.+?)/?'), dict(vid='wdocimages', fid=r'\1')),
        (rgx('/doc/?'), dict(vid='wdoc', fid=r'main')),
        (rgx('/doc/(.+?)/?'), dict(vid='wdoc', fid=r'\1')),
    ]

    def rewrite(self, req, uri):
        """for each `input`, `output `in rules, if `uri` matches `input`,
        req's form is updated with `output`
        """
        for data in self.rules:
            try:
                inputurl, infos, required_groups = data
            except ValueError:
                inputurl, infos = data
                required_groups = None
            if required_groups and not req.user.matching_groups(
                    required_groups):
                continue
            if isinstance(inputurl, str):
                if inputurl == uri:
                    req.form.update(infos)
                    break
            elif inputurl.match(uri):  # it's a regexp
                # XXX what about i18n? (vtitle for instance)
                for param, value in infos.items():
                    if isinstance(value, str):
                        req.form[param] = inputurl.sub(value, uri)
                    else:
                        req.form[param] = value
                break
        else:
            self.debug("no simple rewrite rule found for %s", uri)
            raise KeyError(uri)
        return None, None
예제 #11
0
 def domid(self):
     return self._cw.form.get('divid') or domid(
         '%s-%s' % (self.__regid__, make_uid()))