web/form.py
branchtls-sprint
changeset 1009 bcd0c3ae1935
parent 944 e9da555f19c5
child 1013 948a3882c94a
equal deleted inserted replaced
1008:f54b4309a3f5 1009:bcd0c3ae1935
   930             vocabfunc = getattr(self, '%s_relation_vocabulary' % role)
   930             vocabfunc = getattr(self, '%s_relation_vocabulary' % role)
   931         else:
   931         else:
   932             # XXX bw compat, default_<field name> on the entity
   932             # XXX bw compat, default_<field name> on the entity
   933             warn('found %s_%s_vocabulary on %s, should be set on a specific form'
   933             warn('found %s_%s_vocabulary on %s, should be set on a specific form'
   934                  % (role, rtype, self.entity.id), DeprecationWarning)
   934                  % (role, rtype, self.entity.id), DeprecationWarning)
       
   935         # NOTE: it is the responsibility of `vocabfunc` to sort the result
       
   936         #       (direclty through RQL or via a python sort). This is also
       
   937         #       important because `vocabfunc` might return a list with
       
   938         #       couples (label, None) which act as separators. In these
       
   939         #       cases, it doesn't make sense to sort results afterwards.
   935         return vocabfunc(rtype)
   940         return vocabfunc(rtype)
   936 ## XXX BACKPORT ME
   941 ## XXX BACKPORT ME
   937 ##         if self.sort:
   942 ##         if self.sort:
   938 ##             choices = sorted(choices)
   943 ##             choices = sorted(choices)
   939 ##         if self.rschema.rproperty(self.subjtype, self.objtype, 'internationalizable'):
   944 ##         if self.rschema.rproperty(self.subjtype, self.objtype, 'internationalizable'):
   984 
   989 
   985     def relation_vocabulary(self, rtype, targettype, role,
   990     def relation_vocabulary(self, rtype, targettype, role,
   986                             limit=None, done=None):
   991                             limit=None, done=None):
   987         if done is None:
   992         if done is None:
   988             done = set()
   993             done = set()
   989         req = self.req
   994         rset = self.entity.unrelated(rtype, targettype, role, limit)
   990         rset = entity.unrelated(rtype, targettype, role, limit)
       
   991         res = []
   995         res = []
   992         for entity in rset.entities():
   996         for entity in rset.entities():
   993             if entity.eid in done:
   997             if entity.eid in done:
   994                 continue
   998                 continue
   995             done.add(entity.eid)
   999             done.add(entity.eid)
  1049     def open_form(self, form):
  1053     def open_form(self, form):
  1050         if form.form_needs_multipart:
  1054         if form.form_needs_multipart:
  1051             enctype = 'multipart/form-data'
  1055             enctype = 'multipart/form-data'
  1052         else:
  1056         else:
  1053             enctype = 'application/x-www-form-urlencoded'
  1057             enctype = 'application/x-www-form-urlencoded'
  1054         tag = ('<form action="%s" methody="post" id="%s" enctype="%s"' % (
  1058         tag = ('<form action="%s" method="post" id="%s" enctype="%s"' % (
  1055             html_escape(form.action or '#'), form.domid, enctype))
  1059             html_escape(form.action or '#'), form.domid, enctype))
  1056         if form.onsubmit:
  1060         if form.onsubmit:
  1057             tag += ' onsubmit="%s"' % html_escape(form.onsubmit)
  1061             tag += ' onsubmit="%s"' % html_escape(form.onsubmit)
  1058         if form.cssstyle:
  1062         if form.cssstyle:
  1059             tag += ' style="%s"' % html_escape(form.cssstyle)
  1063             tag += ' style="%s"' % html_escape(form.cssstyle)