def test_user_csv_export(self): videos = [fileobj_video() for i in range(10)] for video in videos: video.uploaded_by = self.user video.save() with tempfile.NamedTemporaryFile(suffix=".csv") as tempf: write_user_csv(self.user, path=tempf.name) with open(tempf.name, 'rb') as csv_file: reader = csv.reader(csv_file, delimiter=',') for index, row in enumerate(reader): if index == 0: self.assertEqual(row, [ 'Channel', 'Title', 'Kind', 'Filename', 'File Size', 'URL', 'Description', 'Author', 'Language', 'License', 'License Description', 'Copyright Holder' ]) else: self.assertIn(videos[index - 1].original_filename, row) self.assertIn( _format_size(videos[index - 1].file_size), row) self.assertEqual(index, len(videos))
def test_user_csv_export(self): videos = [fileobj_video() for i in range(10)] for video in videos: video.uploaded_by = self.user video.save() with tempfile.NamedTemporaryFile(suffix=".csv") as tempf: write_user_csv(self.user, path=tempf.name) with open(tempf.name, 'rb') as csv_file: reader = csv.reader(csv_file, delimiter=',') for index, row in enumerate(reader): if index == 0: self.assertEqual(row, ['Channel', 'Title', 'Kind', 'Filename', 'File Size', 'URL', 'Description', 'Author', 'Language', 'License', 'License Description', 'Copyright Holder']) else: self.assertIn(videos[index-1].original_filename, row) self.assertIn(_format_size(videos[index-1].file_size), row) self.assertEqual(index, len(videos))
def generateusercsv_task(email): user = User.objects.get(email=email) csv_path = write_user_csv(user) subject = render_to_string('export/user_csv_email_subject.txt', {}) message = render_to_string('export/user_csv_email.txt', { 'legal_email': settings.POLICY_EMAIL, 'user': user, 'edit_channels': user.editable_channels.values('name', 'id'), 'view_channels': user.view_only_channels.values('name', 'id'), }) email = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email]) email.attach_file(csv_path) email.send()
def generateusercsv_task(email): user = User.objects.get(email=email) csv_path = write_user_csv(user) subject = render_to_string('export/user_csv_email_subject.txt', {}) message = render_to_string( 'export/user_csv_email.txt', { 'legal_email': settings.POLICY_EMAIL, 'user': user, 'edit_channels': user.editable_channels.values('name', 'id'), 'view_channels': user.view_only_channels.values('name', 'id'), }) email = EmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email]) email.attach_file(csv_path) email.send()
def generateusercsv_task(user_id, language=settings.LANGUAGE_CODE): with translation.override(language): user = User.objects.get(pk=user_id) csv_path = write_user_csv(user) subject = render_to_string("export/user_csv_email_subject.txt", {}) message = render_to_string( "export/user_csv_email.txt", { "legal_email": settings.POLICY_EMAIL, "user": user, "edit_channels": user.editable_channels.values("name", "id"), "view_channels": user.view_only_channels.values("name", "id"), }, ) email = CustomEmailMessage(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email]) email.encoding = 'utf-8' email.attach_file(csv_path, mimetype="text/csv") email.send()