예제 #1
0
 def save(self):
     changed_keys = map(lambda x: smart_str(x), self.changed_data)
     for k in changed_keys:
         # Ignore fields that did not appear in the POST at all
         if k not in self.data and k not in MULTICHOICE_FIELDS:
             continue
         # If value is empty, we assume it is to be removed
         value = self.cleaned_data[k]
         if value == '':
             value = None
         # Sometimes attributes slide in changed_data without having
         # been modified, lets ignore those
         if self.pynag_object[k] == value:
             continue
         # Multichoice fields have a special restriction, sometimes they contain
         # the same values as before but in a different order.
         if k in MULTICHOICE_FIELDS:
             original = AttributeList(self.pynag_object[k])
             new = AttributeList(value)
             if sorted(original.fields) == sorted(new.fields):
                 continue
         # If we reach here, it is save to modify our pynag object.
         self.pynag_object[k] = value
         # Additionally, update the field for the return form
         self.fields[k] = self.get_pynagField(k, css_tag="defined")
         self.fields[k].value = value
     self.pynag_object.save()
     adagios.misc.rest.add_notification(message="Object successfully saved",
                                        level="success",
                                        notification_type="show_once")
예제 #2
0
파일: forms.py 프로젝트: ppepos/adagios
 def prepare_value(self, value):
     """
     Takes a comma separated string, removes + if it is prefixed so. Returns a comma seperated string
     """
     if value == 'null':
         return value
     elif isinstance(value, basestring):
         a = AttributeList(value)
         self.__prefix = a.operator
         a.operator = ''
         a = str(a)
         value = a
     return value
예제 #3
0
파일: forms.py 프로젝트: wz3763/adagios
 def prepare_value(self, value):
     """
     Takes a comma separated string, removes + if it is prefixed so. Returns a comma seperated string
     """
     if value == 'null':
         return value
     elif isinstance(value, basestring):
         a = AttributeList(value)
         self.__prefix = a.operator
         a.operator = ''
         a = str(a)
         value = a
     return value
예제 #4
0
 def prepare_value(self, value):
     """
     Takes a comma separated string, removes + if it is prefixed so. Returns a list
     """
     if isinstance(value, str):
         self.attributelist = AttributeList(value)
         self.__prefix = self.attributelist.operator
         return self.attributelist.fields
     return value
예제 #5
0
    def save(self):
        changed_keys = map(lambda x: smart_str(x), self.changed_data)
        for k in changed_keys:

            # Ignore fields that did not appear in the POST at all EXCEPT
            # If it it a pynagchoicefield. That is because multichoicefield that
            # does not appear in the post, means that the user removed every attribute
            # in the multichoice field
            if k not in self.data and not isinstance(self.fields.get(k, None),
                                                     PynagChoiceField):
                continue

            value = self.cleaned_data[k]

            # Sometimes attributes slide in changed_data without having
            # been modified, lets ignore those
            if self.pynag_object[k] == value:
                continue

            # Multichoice fields have a special restriction, sometimes they contain
            # the same values as before but in a different order.
            if k in MULTICHOICE_FIELDS:
                original = AttributeList(self.pynag_object[k])
                new = AttributeList(value)
                if sorted(original.fields) == sorted(new.fields):
                    continue  # If we reach here, it is save to modify our pynag object.

            # Here we actually make a change to our pynag object
            self.pynag_object[k] = value
            # Additionally, update the field for the return form
            self.fields[k] = self.get_pynagField(k, css_tag="defined")
            self.fields[k].value = value

        try:
            self.pynag_object.save()
            adagios.misc.rest.add_notification(
                message=_("Object successfully saved"),
                level="success",
                notification_type="show_once")
        except IOError:
            adagios.misc.rest.add_notification(message=_(
                "Object cannot be saved : Permission denied on file system"),
                                               level="danger",
                                               notification_type="show_once")
예제 #6
0
파일: forms.py 프로젝트: ppepos/adagios
 def prepare_value(self, value):
     """
     Takes a comma separated string, removes + if it is prefixed so. Returns a list
     """
     if value is None:
         return []
     if isinstance(value, str):
         self.attributelist = AttributeList(value)
         self.__prefix = self.attributelist.operator
         return self.attributelist.fields
     else:
         raise ValueError("Expected string. Got %s" % type(value))
예제 #7
0
파일: forms.py 프로젝트: ppepos/adagios
    def clean(self):
        cleaned_data = super(PynagForm, self).clean()
        for k, v in cleaned_data.items():
            # change from unicode to str
            v = cleaned_data[k] = smart_str(v)

            # Empty string, or the string None, means remove the field
            if v in ('', 'None'):
                cleaned_data[k] = v = None

            # Maintain operator (+,-, !) for multichoice fields
            if k in MULTICHOICE_FIELDS and v and v != "null":
                operator = AttributeList(self.pynag_object.get(
                    k, '')).operator or ''
                cleaned_data[k] = "%s%s" % (operator, v)
        return cleaned_data