Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
proto3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
protokollsystem
proto3
Commits
32bfe777
Commit
32bfe777
authored
7 years ago
by
Robin Sonnabend
Browse files
Options
Downloads
Patches
Plain Diff
Improve server.py code quality
Also fixes some latent bugs
parent
4bd3d253
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
models/database.py
+9
-0
9 additions, 0 deletions
models/database.py
server.py
+455
-224
455 additions, 224 deletions
server.py
utils.py
+26
-0
26 additions, 0 deletions
utils.py
with
490 additions
and
224 deletions
models/database.py
+
9
−
0
View file @
32bfe777
...
@@ -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.
Click to expand it.
server.py
+
455
−
224
View file @
32bfe777
This diff is collapsed.
Click to expand it.
utils.py
+
26
−
0
View file @
32bfe777
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment