Example #1
0
 def save(self, *args, **kwargs):
     self._set_title()
     old_id_string = self.id_string
     self._set_id_string()
     self._set_encrypted_field()
     # check if we have an existing id_string,
     # if so, the one must match but only if xform is NOT new
     if self.pk and old_id_string and old_id_string != self.id_string:
         raise XLSFormError(
             _(u"Your updated form's id_string '%(new_id)s' must match "
               "the existing forms' id_string '%(old_id)s'." % {
                   'new_id': self.id_string,
                   'old_id': old_id_string
               }))
     if getattr(settings, 'STRICT', True) and \
             not re.search(r"^[\w-]+$", self.id_string):
         raise XLSFormError(
             _(u'In strict mode, the XForm ID must be a '
               'valid slug and contain no spaces.'))
     if not self.sms_id_string:
         try:
             # try to guess the form's wanted sms_id_string
             # from it's json rep (from XLSForm)
             # otherwise, use id_string to ensure uniqueness
             self.sms_id_string = json.loads(self.json).get(
                 'sms_keyword', self.id_string)
         except:
             self.sms_id_string = self.id_string
     super(XForm, self).save(*args, **kwargs)
     for perm in get_perms_for_model(XForm):
         assign_perm(perm.codename, self.user, self)
Example #2
0
 def _set_id_string(self):
     matches = self.instance_id_regex.findall(self.xml)
     if len(matches) != 1:
         raise XLSFormError(_("There should be a single id string."))
     self.id_string = matches[0]
Example #3
0
 def _set_title(self):
     text = re.sub(r"\s+", " ", self.xml)
     matches = re.findall(r"<h:title>([^<]+)</h:title>", text)
     if len(matches) != 1:
         raise XLSFormError(_("There should be a single title."), matches)
     self.title = u"" if not matches else matches[0]