user 'set' method instead of direct assignment on many to many relationship (#49189)

This commit is contained in:
Emmanuel Cazenave 2020-12-01 16:07:50 +01:00
parent f068578330
commit ca7a948c2b
6 changed files with 21 additions and 21 deletions

View File

@ -72,8 +72,8 @@ class Command(BaseCommand):
'recipient using --to-list and --to-user.')
document = Document(sender=sender, filetype=filetype)
document.save()
document.to_user = to_users
document.to_list = to_lists
document.to_user.set(to_users)
document.to_list.set(to_lists)
for arg in options['file_tosend']:
if not os.path.isfile(arg):
raise CommandError('file %r does not exist')

View File

@ -361,8 +361,8 @@ class Document(Model):
document = Document.objects.create(sender=new_sender,
filetype=self.filetype,
comment=self.comment)
document.to_user = users
document.to_list = lists
document.to_user.set(users)
document.to_list.set(lists)
attached_files = [ AttachedFile(name=attached_file.name,
content=attached_file.content,
document=document) for attached_file in self.attached_files.all()]

View File

@ -218,8 +218,8 @@ def send_file(request, file_type_id):
to_user.append(int(i))
new_send.save()
form.save_attachments()
new_send.to_user = to_user
new_send.to_list = to_list
new_send.to_user.set(to_user)
new_send.to_list.set(to_list)
recipients_count = new_send.post()
request.record('create-document', 'sent document {document} '
'delivered to {recipients_count}', document=new_send,

View File

@ -269,8 +269,8 @@ In case of failure the following return value is returned:
document = models.Document(sender=sender,
comment=description, filetype=filetype)
document.save()
document.to_user = recipients
document.to_list = mailing_list_recipients
document.to_user.set(recipients)
document.to_list.set(mailing_list_recipients)
for filename, payload in attachments:
content = ContentFile(payload)
attached_file = models.AttachedFile(document=document,

View File

@ -244,8 +244,8 @@ In case of failure the following return value is returned:
comment=description, filetype=filetype,
private=self.private)
document.save()
document.to_user = recipients
document.to_list = mailing_list_recipients
document.to_user.set(recipients)
document.to_list.set(mailing_list_recipients)
for filename, payload in attachments:
content = ContentFile(payload)
attached_file = models.AttachedFile(document=document,

View File

@ -92,8 +92,8 @@ class MailingListTreeTestCase(TestCase):
for i in range(19, -1, -1):
self.mls.insert(0, MailingList.objects.create(
name='%s' % i))
self.mls[0].members = [self.users[i]]
self.mls[0].mailing_list_members = sublist
self.mls[0].members.set([self.users[i]])
self.mls[0].mailing_list_members.set(sublist)
sublist = [ self.mls[0] ]
def test_mailing_list_recursive(self):
@ -126,10 +126,10 @@ class MailingListCycle(TestCase):
for i in range(19, -1, -1):
self.mls.insert(0, MailingList.objects.create(
name='%s' % i))
self.mls[0].members = [self.users[i]]
self.mls[0].mailing_list_members = sublist
self.mls[0].members.set([self.users[i]])
self.mls[0].mailing_list_members.set(sublist)
sublist = [ self.mls[0] ]
self.mls[19].mailing_list_members = [ self.mls[0] ]
self.mls[19].mailing_list_members.set([self.mls[0]])
def test_mailing_list_recursive(self):
"""
@ -168,8 +168,8 @@ class BaseTestCase(TestCase):
self.documents.append(
Document.objects.create(sender=self.users[(i+2) % self.COUNT],
filetype=self.filetypes[i]))
self.documents[-1].to_user = [self.users[i % self.COUNT],
self.users[(i+1) % self.COUNT]]
self.documents[-1].to_user.set([self.users[i % self.COUNT],
self.users[(i+1) % self.COUNT]])
for j in range(2):
attached_file = AttachedFile(name='file%s' % j,
document=self.documents[-1],
@ -261,7 +261,7 @@ class DelegatesTestCase(BaseTestCase):
def test_inbox_by_document(self):
document = Document.objects.create(
sender=self.users[0], filetype=self.filetypes[0])
document.to_user = [self.users[1]]
document.to_user.set([self.users[1]])
attached_file = AttachedFile(name='file-private-flag.pdf', document=document, kind=None)
attached_file.content.save('file-private-flag.pdf', ContentFile('coucou'))
attached_file.save()
@ -273,7 +273,7 @@ class DelegatesTestCase(BaseTestCase):
def test_private_flag(self):
document = Document.objects.create(sender=self.users[0], filetype=self.filetypes[0], private=True)
document.to_user = [self.users[1]]
document.to_user.set([self.users[1]])
attached_file = AttachedFile(name='file-private-flag.pdf', document=document, kind=None)
attached_file.content.save('file-private-flag.pdf', ContentFile('coucou'))
attached_file.save()
@ -379,8 +379,8 @@ class NotificationToDelegatesTestCase(TestCase):
filetype, created = FileType.objects.get_or_create(name=filetype_name)
document = Document.objects.create(sender=sender, filetype=filetype)
document.to_user = user_recipients
document.to_list = list_recipients
document.to_user.set(user_recipients)
document.to_list.set(list_recipients)
attached_files = []
for name, content in names_and_contents:
attached_file = AttachedFile(name=name,