##// END OF EJS Templates
Add any number of files and URLs to post, not just one
neko259 -
r1753:22f62124 default
parent child Browse files
Show More
@@ -187,7 +187,7 b' class PostForm(NeboardForm):'
187 187
188 188 def _update_file_extension(self, file):
189 189 if file:
190 mimetype = get_file_mimetype(file)
190 mimetype =get_file_mimetype(file)
191 191 extension = MIMETYPE_EXTENSIONS.get(mimetype)
192 192 if extension:
193 193 filename = file.name.split(FILE_EXTENSION_DELIMITER, 1)[0]
@@ -292,19 +292,23 b' class PostForm(NeboardForm):'
292 292
293 293 return cleaned_data
294 294
295 def get_file(self):
295 def get_files(self):
296 296 """
297 297 Gets file from form or URL.
298 298 """
299 299
300 300 file = self.cleaned_data['file']
301 301 if isinstance(file, UploadedFile):
302 return file
302 return [file]
303 else:
304 return []
303 305
304 def get_file_url(self):
306 def get_file_urls(self):
305 307 file = self.cleaned_data['file']
306 308 if type(file) == str:
307 return file
309 return [file]
310 else:
311 return []
308 312
309 313 def get_tripcode(self):
310 314 title = self.cleaned_data['title']
@@ -333,8 +337,8 b' class PostForm(NeboardForm):'
333 337
334 338 def _clean_text_file(self):
335 339 text = self.cleaned_data.get('text')
336 file = self.get_file()
337 file_url = self.get_file_url()
340 file = self.get_files()
341 file_url = self.get_file_urls()
338 342 images = self.get_images()
339 343
340 344 if (not text) and (not file) and (not file_url) and len(images) == 0:
@@ -26,10 +26,10 b' post_import_deps = Signal()'
26 26
27 27 class PostManager(models.Manager):
28 28 @transaction.atomic
29 def create_post(self, title: str, text: str, file=None, thread=None,
29 def create_post(self, title: str, text: str, files=[], thread=None,
30 30 ip=NO_IP, tags: list=None,
31 31 tripcode='', monochrome=False, images=[],
32 file_url=None):
32 file_urls=[]):
33 33 """
34 34 Creates new post
35 35 """
@@ -73,11 +73,11 b' class PostManager(models.Manager):'
73 73 logger.info('Created post [{}] with text [{}] by {}'.format(post,
74 74 post.get_text(),post.poster_ip))
75 75
76 if file:
76 for file in files:
77 77 self._add_file_to_post(file, post)
78 78 for image in images:
79 79 post.attachments.add(image)
80 if file_url:
80 for file_url in file_urls:
81 81 post.attachments.add(Attachment.objects.create_from_url(file_url))
82 82
83 83 post.set_global_id()
@@ -142,8 +142,8 b' class AllThreadsView(PostMixin, FileUplo'
142 142
143 143 title = form.get_title()
144 144 text = data[FORM_TEXT]
145 file = form.get_file()
146 file_url = form.get_file_url()
145 files = form.get_files()
146 file_urls = form.get_file_urls()
147 147 images = form.get_images()
148 148
149 149 text = self._remove_invalid_links(text)
@@ -151,11 +151,11 b' class AllThreadsView(PostMixin, FileUplo'
151 151 tags = data[FORM_TAGS]
152 152 monochrome = form.is_monochrome()
153 153
154 post = Post.objects.create_post(title=title, text=text, file=file,
154 post = Post.objects.create_post(title=title, text=text, files=files,
155 155 ip=ip, tags=tags,
156 156 tripcode=form.get_tripcode(),
157 157 monochrome=monochrome, images=images,
158 file_url = file_url)
158 file_urls = file_urls)
159 159
160 160 # This is required to update the threads to which posts we have replied
161 161 # when creating this one
@@ -127,18 +127,18 b' class ThreadView(BaseBoardView, PostMixi'
127 127
128 128 title = form.get_title()
129 129 text = data[FORM_TEXT]
130 file = form.get_file()
131 file_url = form.get_file_url()
130 files = form.get_files()
131 file_urls = form.get_file_urls()
132 132 images = form.get_images()
133 133
134 134 text = self._remove_invalid_links(text)
135 135
136 136 post_thread = opening_post.get_thread()
137 137
138 post = Post.objects.create_post(title=title, text=text, file=file,
138 post = Post.objects.create_post(title=title, text=text, files=files,
139 139 thread=post_thread, ip=ip,
140 140 tripcode=form.get_tripcode(),
141 images=images, file_url=file_url)
141 images=images, file_urls=file_urls)
142 142 post.notify_clients()
143 143
144 144 if form.is_subscribe():
General Comments 0
You need to be logged in to leave comments. Login now