IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit dafac211 authored by Emi Simpson's avatar Emi Simpson
Browse files

Added support for long descriptions

parent cc6d13fb
Pipeline #314 passed with stages
in 2 minutes and 17 seconds
......@@ -23,6 +23,8 @@ from typing import Any, List, Optional, Dict, Tuple, Type, Union, cast
from pymysql.cursors import Cursor
from pymysql.err import IntegrityError
import markdown
import bleach
_alphabet = 'abcdefghijklmnopqrstuvwxyz'
......@@ -556,6 +558,42 @@ class Project:
self.load(c)
return self._description #type: ignore
def get_short_description(self, c: Cursor) -> str:
"""
Retrieve first paragraph of the description of the project
This MAY trigger a database query if the project has not yet been loaded
Raises:
sqlite3.OperationalError: The project was initialized with a
cursor that points to a database that was not properly set up
mystic.database.NonexistantId: The project was initialized with an ID
that was not found
"""
full_desc = self.get_description(c)
for line in full_desc.split('\n'):
line = line.strip()
if len(line) > 0 and not line.startswith('#'):
return line
return full_desc
def get_rendered_description(self, c: Cursor) -> str:
raw_desc = self.get_description(c)
sanitary_desc = bleach.clean(raw_desc)
return markdown.markdown(
sanitary_desc,
extensions=[
'codehilite',
'def_list',
'fenced_code',
'footnotes',
'nl2br',
'sane_lists',
'smarty',
'tables',
],
)
def set_description(self, description: str) -> None:
"""
Change the description of a project
......
......@@ -19,7 +19,7 @@ def setup_database(c: Cursor) -> None:
CREATE TABLE IF NOT EXISTS projects (
project_id INTEGER PRIMARY KEY AUTO_INCREMENT,
display_name VARCHAR(50) NOT NULL,
description VARCHAR(500) NOT NULL,
description TEXT NOT NULL,
draft_owner INTEGER UNIQUE,
FOREIGN KEY (draft_owner)
REFERENCES users(user_id)
......
/*
* This is automatically generated by pygments using the following command:
* pygmentize -S default -f html -a .codehilite > styles.css
*/
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.codehilite .hll { background-color: #ffffcc }
.codehilite { background: #f8f8f8; }
.codehilite .c { color: #408080; font-style: italic } /* Comment */
.codehilite .err { border: 1px solid #FF0000 } /* Error */
.codehilite .k { color: #008000; font-weight: bold } /* Keyword */
.codehilite .o { color: #666666 } /* Operator */
.codehilite .ch { color: #408080; font-style: italic } /* Comment.Hashbang */
.codehilite .cm { color: #408080; font-style: italic } /* Comment.Multiline */
.codehilite .cp { color: #BC7A00 } /* Comment.Preproc */
.codehilite .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */
.codehilite .c1 { color: #408080; font-style: italic } /* Comment.Single */
.codehilite .cs { color: #408080; font-style: italic } /* Comment.Special */
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
.codehilite .ge { font-style: italic } /* Generic.Emph */
.codehilite .gr { color: #FF0000 } /* Generic.Error */
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
.codehilite .go { color: #888888 } /* Generic.Output */
.codehilite .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
.codehilite .gs { font-weight: bold } /* Generic.Strong */
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.codehilite .gt { color: #0044DD } /* Generic.Traceback */
.codehilite .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
.codehilite .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
.codehilite .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
.codehilite .kp { color: #008000 } /* Keyword.Pseudo */
.codehilite .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
.codehilite .kt { color: #B00040 } /* Keyword.Type */
.codehilite .m { color: #666666 } /* Literal.Number */
.codehilite .s { color: #BA2121 } /* Literal.String */
.codehilite .na { color: #7D9029 } /* Name.Attribute */
.codehilite .nb { color: #008000 } /* Name.Builtin */
.codehilite .nc { color: #0000FF; font-weight: bold } /* Name.Class */
.codehilite .no { color: #880000 } /* Name.Constant */
.codehilite .nd { color: #AA22FF } /* Name.Decorator */
.codehilite .ni { color: #999999; font-weight: bold } /* Name.Entity */
.codehilite .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
.codehilite .nf { color: #0000FF } /* Name.Function */
.codehilite .nl { color: #A0A000 } /* Name.Label */
.codehilite .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
.codehilite .nt { color: #008000; font-weight: bold } /* Name.Tag */
.codehilite .nv { color: #19177C } /* Name.Variable */
.codehilite .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
.codehilite .mb { color: #666666 } /* Literal.Number.Bin */
.codehilite .mf { color: #666666 } /* Literal.Number.Float */
.codehilite .mh { color: #666666 } /* Literal.Number.Hex */
.codehilite .mi { color: #666666 } /* Literal.Number.Integer */
.codehilite .mo { color: #666666 } /* Literal.Number.Oct */
.codehilite .sa { color: #BA2121 } /* Literal.String.Affix */
.codehilite .sb { color: #BA2121 } /* Literal.String.Backtick */
.codehilite .sc { color: #BA2121 } /* Literal.String.Char */
.codehilite .dl { color: #BA2121 } /* Literal.String.Delimiter */
.codehilite .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */
.codehilite .s2 { color: #BA2121 } /* Literal.String.Double */
.codehilite .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
.codehilite .sh { color: #BA2121 } /* Literal.String.Heredoc */
.codehilite .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
.codehilite .sx { color: #008000 } /* Literal.String.Other */
.codehilite .sr { color: #BB6688 } /* Literal.String.Regex */
.codehilite .s1 { color: #BA2121 } /* Literal.String.Single */
.codehilite .ss { color: #19177C } /* Literal.String.Symbol */
.codehilite .bp { color: #008000 } /* Name.Builtin.Pseudo */
.codehilite .fm { color: #0000FF } /* Name.Function.Magic */
.codehilite .vc { color: #19177C } /* Name.Variable.Class */
.codehilite .vg { color: #19177C } /* Name.Variable.Global */
.codehilite .vi { color: #19177C } /* Name.Variable.Instance */
.codehilite .vm { color: #19177C } /* Name.Variable.Magic */
.codehilite .il { color: #666666 } /* Literal.Number.Integer.Long */
......@@ -23,6 +23,7 @@
}
</style>
<link rel=stylesheet href={{static_versioned("styles.css")}}/>
<link rel=stylesheet href={{static_versioned("pygments.css")}}/>
<title>{% block title %}{% endblock %} - Mystic</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{% endblock %}
......
......@@ -86,7 +86,7 @@
<a href="/{{id}}"> {{project.get_display_name(cursor)}}</a>
</h6>
<p class="small">
{{project.get_description(cursor)}}
{{project.get_short_description(cursor)}}
</p>
<div class="project-spacer"></div>
<div class="owners">
......
......@@ -143,7 +143,7 @@
</div>
</section>
<section>
<p> {{project.get_description(cursor)}} </p>
<p> {{project.get_rendered_description(cursor) | safe}} </p>
</section>
<div id=links-and-jobs>
<section>
......
......@@ -47,7 +47,7 @@ header {
<a href="/{{id}}"> {{project.get_display_name(cursor)}}</a>
</h6>
<p class="small">
{{project.get_description(cursor)}}
{{project.get_short_description(cursor)}}
</p>
{% set sources_empty = project.get_data_sources(cursor)|length == 0 %}
<div class="sources{% if sources_empty %} empty{% endif %}">
......
......@@ -11,6 +11,9 @@ setup(
'flask-saml2 @ git+https://github.com/Alch-Emi/flask-saml2@timestamps#egg=flask-saml2',
'msgpack==1.0.2',
'msgpack-types',
'argon2-cffi'
'argon2-cffi',
'markdown',
'bleach',
'Pygments',
],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment