def save(self, *args, **kwargs): instance = self.instance entity = self.related_entity.get_real_entity() user = self.cleaned_data['user'] category = self.folder_category get_or_create_folder = Folder.objects.get_or_create model_folder = get_or_create_folder( title=str(entity.entity_type), parent_folder=self.root_folder, category=category, defaults={'user': user}, )[0] # instance.folder = get_or_create_folder( instance.linked_folder = get_or_create_folder( title=ellipsis(u'{}_{}'.format(entity.id, entity), _TITLE_MAX_LEN), # Meh parent_folder=model_folder, category=category, defaults={'user': user}, )[0] # super(RelatedDocumentCreateForm, self).save(*args, **kwargs) super().save(*args, **kwargs) Relation.objects.create( subject_entity=entity, type_id=constants.REL_SUB_RELATED_2_DOC, object_entity=instance, user=user, ) return instance
def _connect(cls, sending): ws = SamoussaBackEnd() try: ws.connect() except WSException as err: msg = ellipsis( str(err), length=cls._meta.get_field('status_message').max_length, ) sending.messages.filter(status=MESSAGE_STATUS_NOTSENT).update( status_message=msg) return None return ws
def _get_folder(self): entity = self.related_entity.get_real_entity() get_or_create_folder = partial( Folder.objects.get_or_create, category=self.folder_category, defaults={'user': self.cleaned_data['user']}, ) model_folder = get_or_create_folder( title=str(entity.entity_type), parent_folder=self.root_folder, )[0] return get_or_create_folder( title=ellipsis('{}_{}'.format(entity.id, entity), _TITLE_MAX_LEN), # Meh parent_folder=model_folder, )[0]
def _get_folder(this): entity = this.related_entity.get_real_entity() get_or_create_folder = partial( Folder.objects.get_or_create, category=this.folder_category, defaults={'user': this.cleaned_data['user']}, ) model_folder = get_or_create_folder( title=str(entity.entity_type), parent_folder=this.root_folder, )[0] return get_or_create_folder( title=ellipsis( f'{entity.id}_{entity}', length=Folder._meta.get_field('title').max_length, ), # Meh parent_folder=model_folder, )[0]
def test_ellipsis(self): self.assertEqual('123456789', ellipsis('123456789', 9)) self.assertEqual('1234567…', ellipsis('123456789', 8))
def __str__(self): # NB: translate for unicode can not take 2 arguments... return ellipsis(self.content.strip().replace('\n', ''), 25)