Beispiel #1
0
    def save_related(self, obj):
        model_id = getattr(obj, self._pk)

        attr = getattr(self.model, self.prop)
        values = self.model.select().where(attr == model_id).execute()

        pk_map = dict((str(getattr(v, self._pk)), v) for v in values)

        # Handle request data
        for field in self.entries:
            field_id = field.get_pk()

            is_created = field_id not in pk_map
            if not is_created:
                model = pk_map[field_id]

                if self.should_delete(field):
                    model.delete_instance(recursive=True)
                    continue
            else:
                model = self.model()

            field.populate_obj(model, None)

            # Force relation
            setattr(model, self.prop, model_id)

            self.inline_view._on_model_change(field, model, is_created)

            model.save()

            # Recurse, to save multi-level nested inlines
            for f in itervalues(field.form._fields):
                if f.type == 'InlineModelFormList':
                    f.save_related(model)
Beispiel #2
0
    def save_related(self, obj):
        model_id = getattr(obj, self._pk)

        attr = getattr(self.model, self.prop)
        values = self.model.select().where(attr == model_id).execute()

        pk_map = dict((str(getattr(v, self._pk)), v) for v in values)

        # Handle request data
        for field in self.entries:
            field_id = field.get_pk()

            is_created = field_id not in pk_map
            if not is_created:
                model = pk_map[field_id]

                if self.should_delete(field):
                    model.delete_instance(recursive=True)
                    continue
            else:
                model = self.model()

            field.populate_obj(model, None)

            # Force relation
            setattr(model, self.prop, model_id)

            self.inline_view._on_model_change(field, model, is_created)

            model.save()

            # Recurse, to save multi-level nested inlines
            for f in itervalues(field.form._fields):
                if f.type == 'InlineModelFormList':
                    f.save_related(model)
Beispiel #3
0
def format_error(error):
    if isinstance(error, ValidationError):
        return as_unicode(error)

    if isinstance(error, wtfValidationError):
        return '. '.join(itervalues(error.to_dict()))

    return as_unicode(error)
Beispiel #4
0
def format_error(error):
    if isinstance(error, ValidationError):
        return as_unicode(error)

    if isinstance(error, wtfValidationError):
        return '. '.join(itervalues(error.to_dict()))

    return as_unicode(error)
Beispiel #5
0
 def get_list(self,
              page,
              sort_field,
              sort_desc,
              search,
              filters,
              page_size=None):
     self.search_arguments.append(
         (page, sort_field, sort_desc, search, filters))
     return len(self.all_models), itervalues(self.all_models)
Beispiel #6
0
 def get_list(self,
              page,
              sort_field,
              sort_desc,
              search,
              filters,
              page_size=None):
     self.search_arguments.append(
         (page, sort_field, sort_desc, search, filters))
     count = len(self.all_models)
     data = islice(itervalues(self.all_models), 0, page_size)
     return count, data
Beispiel #7
0
def format_error(error):
    if isinstance(error, ValidationError):
        return as_unicode(error)

    if isinstance(error, wtfValidationError):
        try:
            return '. '.join(itervalues(error.to_dict()))
        except Exception:
            resp = ''
            for v in error.to_dict().values():
                if isinstance(v, dict):
                    resp += str(v.values())
                else:
                    resp += str(v)
            return resp

    return as_unicode(error)
Beispiel #8
0
def save_inline(form, model):
    for f in itervalues(form._fields):
        if f.type == 'InlineModelFormList':
            f.save_related(model)
Beispiel #9
0
def save_inline(form, model):
    for f in itervalues(form._fields):
        if f.type == 'InlineModelFormList':
            f.save_related(model)
Beispiel #10
0
 def get_list(self, page, sort_field, sort_desc, search, filters,
              page_size=None):
     self.search_arguments.append((page, sort_field, sort_desc, search, filters))
     return len(self.all_models), itervalues(self.all_models)
Beispiel #11
0
 def get_list(self, page, sort_field, sort_desc, search, filters,
              page_size=None):
     self.search_arguments.append((page, sort_field, sort_desc, search, filters))
     count = len(self.all_models)
     data = islice(itervalues(self.all_models), 0, page_size)
     return count, data