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