diff --git a/migrations/versions/0686095ee9dd_.py b/migrations/versions/0686095ee9dd_.py new file mode 100644 index 0000000000000000000000000000000000000000..59aefad798583b0344ee5f2a273396329482aa0c --- /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 0646ff709cf0851a576b9958402540e883cf9bbe..fb15a8010bd13f8b26566bf7555f1f9cb864d188 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 369b3021b733d94bfa5ce38e9afbc5e696bcb91d..9e7285a5a6e7c76bfe4beabc654fb348b1a19e01 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 43f8af3258a37ace69ce0c1f7f201d0c9fba01f3..17a6b71eac760af586220551e0006b980d58be8a 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 b9ba24860d0d8ca431f3feda74ee3a0aefec2e5a..4fd92a621cc397e03e09f9c6ab9b87a6c88f8bbd 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 2314e88ba27ad3466aef95bd12dd0d3cbd898263..d38b074b5d2cd6fcaa9f7a6f665b0c2adf153c95 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 0000000000000000000000000000000000000000..08a54d2465edd79707d0a47aa5ab8c07dd4ab8a6 --- /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 %}