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

Improve server.py code quality

Also fixes some latent bugs
parent 4bd3d253
...@@ -48,6 +48,10 @@ class DatabaseModel(db.Model): ...@@ -48,6 +48,10 @@ class DatabaseModel(db.Model):
columns.append("{}={}".format(column_name, value)) columns.append("{}={}".format(column_name, value))
return "{}({})".format(self.__class__.__name__, ", ".join(columns)) return "{}({})".format(self.__class__.__name__, ", ".join(columns))
@classmethod
def first_by_id(cls, instance_id):
return cls.query.filter_by(id=instance_id).first()
class ProtocolType(DatabaseModel): class ProtocolType(DatabaseModel):
__tablename__ = "protocoltypes" __tablename__ = "protocoltypes"
__model_name__ = "protocoltype" __model_name__ = "protocoltype"
...@@ -235,6 +239,11 @@ class Protocol(DatabaseModel): ...@@ -235,6 +239,11 @@ class Protocol(DatabaseModel):
or self.protocoltype.has_private_view_right(user) 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): def is_done(self):
return self.done return self.done
......
This diff is collapsed.
...@@ -14,6 +14,7 @@ from io import BytesIO ...@@ -14,6 +14,7 @@ from io import BytesIO
import ipaddress import ipaddress
from socket import getfqdn from socket import getfqdn
from uuid import uuid4 from uuid import uuid4
import subprocess
import config import config
...@@ -223,3 +224,28 @@ def parse_datetime_from_string(text): ...@@ -223,3 +224,28 @@ def parse_datetime_from_string(text):
except ValueError as exc: except ValueError as exc:
print(exc) print(exc)
raise ValueError("Date '{}' does not match any known format!".format(text)) raise ValueError("Date '{}' does not match any known format!".format(text))
def get_git_revision():
try:
gitlab_url = "https://git.fsmpi.rwth-aachen.de/protokollsystem/proto3"
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:
pass
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(protocol.id, document.id, 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