Use comments instead of a cutoff line.

As per request of michael
This commit is contained in:
noah morrison
2015-03-24 19:42:52 -04:00
parent 98c820fe4f
commit 32fd689544
2 changed files with 21 additions and 20 deletions

View File

@@ -45,15 +45,11 @@ Submission Mode
""" """
COMMENT_FILE = """ COMMENT_FILE = """
--% {0} %-- # All lines starting with a # will be ignored
Do not edit the line above. #
Type your comment above the line. # If there is only whitespace left then the comment
All text below the line will be discarded. # will not be posted.
#
If there is nothing but whitespace above the line # Replying to {author}'s {type}
then the comment will be discarded. {content}
Replying to {1}'s {2}
{3}
""" """

View File

@@ -2,7 +2,6 @@ import curses
import sys import sys
import time import time
import os import os
from uuid import uuid4
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from subprocess import Popen from subprocess import Popen
@@ -248,13 +247,19 @@ class SubmissionPage(BasePage):
curses.flash() curses.flash()
return return
if data['type'] is 'Submission':
cid = str(uuid4()) content = data['text']
if data['type'] == 'Submission':
info = (data['author'], 'submission', data['text'])
else: else:
info = (data['author'], 'comment', data['body']) content = data['body']
comment_info = COMMENT_FILE.format(cid, *info)
# Comment out every line of the content
content = '\n'.join(['#|' + line for line in content.split('\n')])
info = {'author': data['author'],
'type': data['type'],
'content': content}
comment_info = COMMENT_FILE.format(**info)
with NamedTemporaryFile(prefix='rtv-comment-', mode='w+') as fp: with NamedTemporaryFile(prefix='rtv-comment-', mode='w+') as fp:
fp.write(comment_info) fp.write(comment_info)
@@ -270,8 +275,8 @@ class SubmissionPage(BasePage):
curses.doupdate() curses.doupdate()
fp.seek(0) fp.seek(0)
comment_text = fp.read().split('--% ' + cid + ' %--')[0] comment_text = '\n'.join([line for line in fp.read().split('\n')
if not line.startswith("#")])
if comment_text is None or comment_text.isspace(): if comment_text is None or comment_text.isspace():
return return