Commit 32bfe777 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Improve code quality

Also fixes some latent bugs
parent 4bd3d253
......@@ -48,6 +48,10 @@ class DatabaseModel(db.Model):
columns.append("{}={}".format(column_name, value))
return "{}({})".format(self.__class__.__name__, ", ".join(columns))
def first_by_id(cls, instance_id):
return cls.query.filter_by(id=instance_id).first()
class ProtocolType(DatabaseModel):
__tablename__ = "protocoltypes"
__model_name__ = "protocoltype"
......@@ -235,6 +239,11 @@ class Protocol(DatabaseModel):
or self.protocoltype.has_private_view_right(user)
def get_visible_content(self, user):
if self.has_private_view_right(user):
return self.content_private
return self.content_public
def is_done(self):
return self.done
This diff is collapsed.
......@@ -14,6 +14,7 @@ from io import BytesIO
import ipaddress
from socket import getfqdn
from uuid import uuid4
import subprocess
import config
......@@ -223,3 +224,28 @@ def parse_datetime_from_string(text):
except ValueError as exc:
raise ValueError("Date '{}' does not match any known format!".format(text))
def get_git_revision():
gitlab_url = ""
commit_hash = subprocess.check_output(
["git", "log", "-g", "-1", "--pretty=%H"]).decode("UTF-8").strip()
timestamp = int(subprocess.check_output(
["git", "log", "-g", "-1", "--pretty=%at"]).strip())
commit_date = datetime.fromtimestamp(timestamp)
return {"url": gitlab_url, "hash": commit_hash, "date": commit_date}
except subprocess.SubprocessError:
def get_max_page_length_exp(objects):
length = len(objects)
if length > 0:
return math.ceil(math.log10(length))
return 1
def get_internal_filename(protocol, document, filename):
return "{}-{}-{}".format(,, filename)
Supports Markdown
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