def save_existing(self, form, instance, commit=True):
     """
     NOTE: save_new method is completely overridden here, there's no
     other way to pretend double save otherwise. Just assign translated data
     to object  
     """
     self._prepare_multilingual_object(instance, form)
     return forms.save_instance(form, instance, exclude=[self._pk_field.name], commit=commit)
예제 #2
0
 def save_existing(self, form, instance, commit=True):
     """
     NOTE: save_new method is completely overridden here, there's no
     other way to pretend double save otherwise. Just assign translated data
     to object  
     """
     self._prepare_multilingual_object(instance, form)
     return forms.save_instance(form, instance, exclude=[self._pk_field.name], commit=commit)
예제 #3
0
 def save(self, commit=True):
     if self.instance.pk is None:
         fail_message = 'created'
     else:
         fail_message = 'changed'
     self.instance.user = self.user
     self.instance.enabled = self.should_enable
     return save_instance(self, self.instance, ['feature','user','enabled'],
                          fail_message, commit, construct=False)
예제 #4
0
 	def save(self, commit=True):

   		if self.instance.pk is None:
   			fail_message='created'
   		else:
   			fail_message = 'changed'
   		
   		return save_instance(self, self.instance, self._meta.fields,
                             fail_message, commit, construct=False,
                             )
 def save_new(self, form, commit=True):
     """
     NOTE: save_new method is completely overridden here, there's no
     other way to pretend double save otherwise. Just assign translated data
     to object  
     """
     kwargs = {self.fk.get_attname(): self.instance.pk}
     new_obj = self.model(**kwargs)
     self._prepare_multilingual_object(new_obj, form)
     return forms.save_instance(form, new_obj, exclude=[self._pk_field.name], commit=commit)
예제 #6
0
 def save_new(self, form, commit=True):
     """
     NOTE: save_new method is completely overridden here, there's no
     other way to pretend double save otherwise. Just assign translated data
     to object  
     """
     kwargs = {self.fk.get_attname(): self.instance.pk}
     new_obj = self.model(**kwargs)
     self._prepare_multilingual_object(new_obj, form)
     return forms.save_instance(form, new_obj, exclude=[self._pk_field.name], commit=commit)
예제 #7
0
파일: forms.py 프로젝트: faithNassiwa/lms
    def save(self, commit=True):

        if self.instance.pk is None:
            fail_message = 'created'
        else:
            fail_message = 'changed'

        return save_instance(
            self,
            self.instance,
            self._meta.fields,
            fail_message,
            commit,
            construct=False,
        )
예제 #8
0
 def save(self, commit=True):
     if self.instance.pk is None:
         fail_message = 'created'
     else:
         fail_message = 'changed'
     newinst = forms.save_instance(self, self.instance, self._meta.fields,
                                   fail_message, commit)
     # processim tagi
     tags = filter(
         None,
         map(lambda x: x.strip().lower(),
             self.cleaned_data['tags'].split(',')))
     tags = tuple(set(tags))
     newinst.tagstring = ', '.join(tags)
     if not newinst.published:
         # просто сохраняем строку
         hastags = newinst.tags.all()
         for tag in hastags:
             if tag.weight <= 1:
                 tag.delete()
             else:
                 tag.weight -= 1
                 tag.save()
                 tag.post_set.remove(newinst)
     else:
         hastags = map(lambda x: x.name, newinst.tags.all())
         tags_to_delete = list(set(hastags) - set(tags))
         for li in tags_to_delete:
             tag = Tag.objects.get(name=li)
             if tag.weight <= 1:
                 tag.delete()
             else:
                 tag.weight -= 1
                 tag.save()
                 tag.post_set.remove(newinst)
         for li in tags:
             if li not in hastags:
                 tag, cr = Tag.objects.get_or_create(name=li)
                 newinst.tags.add(tag)
                 if not cr:
                     tag.weight += 1
                     tag.save()
     newinst.save()
     return newinst
예제 #9
0
파일: forms.py 프로젝트: deenseth/patchwork
    def save(self, instance, commit = True):
        opts = instance.__class__._meta
        if self.errors:
            raise ValueError("The %s could not be changed because the data "
                    "didn't validate." % opts.object_name)
        data = self.cleaned_data
        # remove 'no change fields' from the data
        for f in opts.fields:
            if not f.name in data:
                continue

            field = self.fields.get(f.name, None)
            if not field:
                continue

            if field.is_no_change(data[f.name]):
                del data[f.name]

        return forms.save_instance(self, instance,
                self._meta.fields, 'changed', commit)
예제 #10
0
파일: forms.py 프로젝트: HiPiH/life
 def save(self, commit=True):
     if self.instance.pk is None:
         fail_message = 'created'
     else:
         fail_message = 'changed'
     newinst = forms.save_instance(self, self.instance, self._meta.fields, fail_message, commit)
     # processim tagi
     tags = filter(None, map(lambda x: x.strip().lower(), self.cleaned_data['tags'].split(',')))
     tags = tuple(set(tags))
     newinst.tagstring = ', '.join(tags)
     if not newinst.published:
         # просто сохраняем строку
         hastags = newinst.tags.all()
         for tag in hastags:
             if tag.weight <= 1:
                 tag.delete()
             else:
                 tag.weight -= 1
                 tag.save()
                 tag.post_set.remove(newinst)
     else:
         hastags = map(lambda x: x.name, newinst.tags.all())
         tags_to_delete = list(set(hastags) - set(tags))
         for li in tags_to_delete:
             tag = Tag.objects.get(name=li)
             if tag.weight <= 1:
                 tag.delete()
             else:
                 tag.weight -= 1
                 tag.save()
                 tag.post_set.remove(newinst)
         for li in tags:
             if li not in hastags:
                 tag, cr = Tag.objects.get_or_create(name=li)
                 newinst.tags.add(tag)
                 if not cr:
                     tag.weight += 1
                     tag.save()
     newinst.save()
     return newinst
예제 #11
0
 def save(self, commit=True):
     return forms.save_instance(self, self.job, commit=commit)
예제 #12
0
 def save(self, commit=True):
     return forms.save_instance(self, Job(), self.fields, commit=commit)
예제 #13
0
파일: data_edit.py 프로젝트: RockyLiys/erp
 def save(self, commit=True):
     return forms.save_instance(self, instance, fields, fail_message,
                                commit)
예제 #14
0
파일: jobs.py 프로젝트: insin/djangoffice
 def save(self, commit=True):
     return forms.save_instance(self, Job(), self.fields, commit=commit)
예제 #15
0
 def save(self, commit=True):
         return forms.save_instance(self, instance, fields, fail_message, commit)
예제 #16
0
파일: jobs.py 프로젝트: insin/djangoffice
 def save(self, commit=True):
     return forms.save_instance(self, self.job, commit=commit)
예제 #17
0
 def save(self, commit=True):
     self.instance.data = self.data
     self.instance.info_hash = sha1(bencode(self.data['info'])).hexdigest()
     del self.instance.data['info']['pieces'] # get rid of piece data
     fail_message = 'created' if self.instance.pk is None else 'changed'
     return forms.save_instance(self, self.instance, self._meta.fields, fail_message, commit)
예제 #18
0
파일: forms.py 프로젝트: lite/djsite
 def save(self):
     pm = PrivateMessage(src_user=self.user, dst_user=self.cleaned_data['recipient'])
     pm = forms.save_instance(self, pm)
     return pm
예제 #19
0
파일: forms.py 프로젝트: kron4eg/django-btt
 def save(self, commit=True):
     self.instance.torrent = pickle.dumps(self.decoded)
     self.instance.info_hash = sha1(encode(self.decoded['info'])).hexdigest()
     fail_message = 'created' if self.instance.pk is None else 'changed'
     return forms.save_instance(self, self.instance, self._meta.fields, fail_message, commit)