##// END OF EJS Templates
Include poster IP in thead loading because it is shown for moderator
Include poster IP in thead loading because it is shown for moderator

File last commit:

r1603:0695b6a9 default
r1671:f5ce8715 default
Show More
export.py
57 lines | 1.5 KiB | text/x-python | PythonLexer
neko259
Do not pass over perms variable manually to the post template. Fixed thread...
r1390 from django.contrib.auth.context_processors import PermWrapper
neko259
Refactored post export
r1156 from boards import utils
PARAMETER_TRUNCATED = 'truncated'
DIFF_TYPE_HTML = 'html'
DIFF_TYPE_JSON = 'json'
class Exporter():
@staticmethod
def export(post, request, include_last_update) -> str:
pass
class HtmlExporter(Exporter):
@staticmethod
def export(post, request, include_last_update):
if request is not None and PARAMETER_TRUNCATED in request.GET:
truncated = True
reply_link = False
else:
truncated = False
reply_link = True
return post.get_view(truncated=truncated, reply_link=reply_link,
neko259
Do not pass over perms variable manually to the post template. Fixed thread...
r1390 perms=PermWrapper(request.user))
neko259
Refactored post export
r1156
class JsonExporter(Exporter):
@staticmethod
def export(post, request, include_last_update):
post_json = {
'id': post.id,
'title': post.title,
'text': post.get_raw_text(),
}
neko259
Fixed post deletion and export to JSON
r1603 if post.attachments.exists():
neko259
Refactored post export
r1156 post_image = post.get_first_image()
neko259
Fixed post deletion and export to JSON
r1603 post_json['image'] = post_image.file.url
post_json['image_preview'] = post_image.get_preview_url()
neko259
Refactored post export
r1156 if include_last_update:
post_json['bump_time'] = utils.datetime_to_epoch(
post.get_thread().bump_time)
return post_json
EXPORTERS = {
DIFF_TYPE_HTML: HtmlExporter,
DIFF_TYPE_JSON: JsonExporter,
}
def get_exporter(export_type: str) -> Exporter:
return EXPORTERS[export_type]()