From d6a68cab7ff30700dee0d65417158644a34fe6b0 Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Fri, 28 Apr 2017 22:39:34 +0200 Subject: [PATCH] Show HTML-version of the protocol directly ref #94 --- migrations/versions/0686095ee9dd_.py | 30 ++++++++++++++++++++++++++++ models/database.py | 4 +++- parser.py | 27 +++++++++++++++++-------- server.py | 5 ++++- tasks.py | 4 ++++ templates/protocol-show.html | 6 ++++++ templates/protocol.html | 6 ++++++ 7 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 migrations/versions/0686095ee9dd_.py create mode 100644 templates/protocol.html diff --git a/migrations/versions/0686095ee9dd_.py b/migrations/versions/0686095ee9dd_.py new file mode 100644 index 0000000..59aefad --- /dev/null +++ b/migrations/versions/0686095ee9dd_.py @@ -0,0 +1,30 @@ +"""empty message + +Revision ID: 0686095ee9dd +Revises: 60a730d37c9a +Create Date: 2017-04-28 22:24:35.628585 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '0686095ee9dd' +down_revision = '60a730d37c9a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('protocols', sa.Column('content_html_private', sa.String(), nullable=True)) + op.add_column('protocols', sa.Column('content_html_public', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('protocols', 'content_html_public') + op.drop_column('protocols', 'content_html_private') + # ### end Alembic commands ### diff --git a/models/database.py b/models/database.py index 0646ff7..fb15a80 100644 --- a/models/database.py +++ b/models/database.py @@ -143,6 +143,8 @@ class Protocol(DatabaseModel): source = db.Column(db.String) content_public = db.Column(db.String) content_private = db.Column(db.String) + content_html_public = db.Column(db.String) + content_html_private = db.Column(db.String) date = db.Column(db.Date) start_time = db.Column(db.Time) end_time = db.Column(db.Time) @@ -568,7 +570,7 @@ class Todo(DatabaseModel): return self.get_first_protocol() == current_protocol return len(self.protocols) == 1 - def render_html(self): + def render_html(self, current_protocol=None): parts = [ self.get_state(), "<strong>{}:</strong>".format(self.who), diff --git a/parser.py b/parser.py index 369b302..9e7285a 100644 --- a/parser.py +++ b/parser.py @@ -429,14 +429,25 @@ class Fork(Element): else: return content_lines elif render_type == RenderType.html: - title_line = "<h{depth}>{content}</h{depth}>".format(depth=level+1, content=name_line) - content_parts = [] - for child in self.children: - part = child.render(render_type, show_private, level=level+1, protocol=protocol) - if len(part.strip()) == 0: - continue - content_parts.append("<p>{}</p>".format(part)) - content_lines = "{}\n\n{}".format(title_line, "\n".join(content_parts)) + depth = level + 1 + getattr(config, "HTML_LEVEL_OFFSET", 0) + content_lines = "" + if depth < 5: + title_line = "<h{depth}>{content}</h{depth}>".format(depth=depth, content=name_line) + content_parts = [] + for child in self.children: + part = child.render(render_type, show_private, level=level+1, protocol=protocol) + if len(part.strip()) == 0: + continue + content_parts.append("<p>{}</p>".format(part)) + content_lines = "{}\n\n{}".format(title_line, "\n".join(content_parts)) + else: + content_parts = [] + for child in self.children: + part = child.render(render_type, show_private, level=level+1, protocol=protocol) + if len(part.strip()) == 0: + continue + content_parts.append("<li>{}</li>".format(part)) + content_lines = "{}\n<ul>\n{}\n</ul>".format(name_line, "\n".join(content_parts)) if self.test_private(self.name) and not show_private: return "" else: diff --git a/server.py b/server.py index 43f8af3..17a6b71 100755 --- a/server.py +++ b/server.py @@ -528,7 +528,10 @@ def show_protocol(protocol): source_upload_form = KnownProtocolSourceUploadForm() time_diff = protocol.date - datetime.now().date() large_time_diff = not protocol.is_done() and time_diff.days > 0 - return render_template("protocol-show.html", protocol=protocol, errors_table=errors_table, documents_table=documents_table, document_upload_form=document_upload_form, source_upload_form=source_upload_form, time_diff=time_diff, large_time_diff=large_time_diff) + content_html = (protocol.content_html_private + if protocol.has_private_view_right(user) + else protocol.content_html_public) + return render_template("protocol-show.html", protocol=protocol, errors_table=errors_table, documents_table=documents_table, document_upload_form=document_upload_form, source_upload_form=source_upload_form, time_diff=time_diff, large_time_diff=large_time_diff, content_html=Markup(content_html)) @app.route("/protocol/delete/<int:protocol_id>") @login_required diff --git a/tasks.py b/tasks.py index b9ba248..4fd92a6 100644 --- a/tasks.py +++ b/tasks.py @@ -371,6 +371,10 @@ def parse_protocol_async_inner(protocol, encoded_kwargs): privacy_states.append(True) protocol.content_private = content_private protocol.content_public = content_public + protocol.content_html_private = render_template("protocol.html", + render_type=RenderType.html, show_private=True, **render_kwargs) + protocol.content_html_public = render_template("protocol.html", + render_type=RenderType.html, show_private=False, **render_kwargs) for show_private in privacy_states: latex_source = texenv.get_template("protocol.tex").render(render_type=RenderType.latex, show_private=show_private, **render_kwargs) diff --git a/templates/protocol-show.html b/templates/protocol-show.html index 2314e88..d38b074 100644 --- a/templates/protocol-show.html +++ b/templates/protocol-show.html @@ -153,5 +153,11 @@ {% endif %} </div> </div> + {% if content_html %} + <div> + <h3>Protokollinhalt</h3> + {{content_html|safe}} + </div> + {% endif %} </div> {% endblock %} diff --git a/templates/protocol.html b/templates/protocol.html new file mode 100644 index 0000000..08a54d2 --- /dev/null +++ b/templates/protocol.html @@ -0,0 +1,6 @@ +{% for top in tree.children %} +{% if top|class == "Fork" %} +{{top.render(render_type=render_type, level=0, show_private=show_private, protocol=protocol)|safe}} + +{% endif %} +{% endfor %} -- GitLab