Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
protokollsystem
proto3
Commits
151641e8
Commit
151641e8
authored
Feb 26, 2017
by
Robin Sonnabend
Browse files
Create protocol from any file
parent
12259818
Changes
3
Hide whitespace changes
Inline
Side-by-side
server.py
View file @
151641e8
...
...
@@ -22,7 +22,7 @@ import config
from
shared
import
db
,
date_filter
,
datetime_filter
,
date_filter_long
,
time_filter
,
ldap_manager
,
security_manager
,
current_user
,
check_login
,
login_required
,
group_required
,
class_filter
from
utils
import
is_past
,
mail_manager
,
url_manager
,
get_first_unused_int
,
set_etherpad_text
,
get_etherpad_text
,
split_terms
from
models.database
import
ProtocolType
,
Protocol
,
DefaultTOP
,
TOP
,
Document
,
Todo
,
Decision
,
MeetingReminder
,
Error
from
views.forms
import
LoginForm
,
ProtocolTypeForm
,
DefaultTopForm
,
MeetingReminderForm
,
NewProtocolForm
,
DocumentUploadForm
,
KnownProtocolSourceUploadForm
,
NewProtocolSourceUploadForm
,
ProtocolForm
,
TopForm
,
SearchForm
from
views.forms
import
LoginForm
,
ProtocolTypeForm
,
DefaultTopForm
,
MeetingReminderForm
,
NewProtocolForm
,
DocumentUploadForm
,
KnownProtocolSourceUploadForm
,
NewProtocolSourceUploadForm
,
ProtocolForm
,
TopForm
,
SearchForm
,
NewProtocolFileUploadForm
from
views.tables
import
ProtocolsTable
,
ProtocolTypesTable
,
ProtocolTypeTable
,
DefaultTOPsTable
,
MeetingRemindersTable
,
ErrorsTable
,
TodosTable
,
DocumentsTable
,
DecisionsTable
app
=
Flask
(
__name__
)
...
...
@@ -398,6 +398,7 @@ def new_protocol():
protocoltypes
=
ProtocolType
.
get_modifiable_protocoltypes
(
user
)
form
=
NewProtocolForm
(
protocoltypes
)
upload_form
=
NewProtocolSourceUploadForm
(
protocoltypes
)
file_upload_form
=
NewProtocolFileUploadForm
(
protocoltypes
)
if
form
.
validate_on_submit
():
protocoltype
=
ProtocolType
.
query
.
filter_by
(
id
=
form
.
protocoltype
.
data
).
first
()
if
protocoltype
is
None
or
not
protocoltype
.
has_modify_right
(
user
):
...
...
@@ -410,7 +411,8 @@ def new_protocol():
type_id
=
request
.
args
.
get
(
"type_id"
)
if
type_id
is
not
None
:
form
.
protocoltype
.
data
=
type_id
return
render_template
(
"protocol-new.html"
,
form
=
form
,
upload_form
=
upload_form
,
protocoltypes
=
protocoltypes
)
upload_form
.
protocoltype
.
data
=
type_id
return
render_template
(
"protocol-new.html"
,
form
=
form
,
upload_form
=
upload_form
,
file_upload_form
=
file_upload_form
,
protocoltypes
=
protocoltypes
)
@
app
.
route
(
"/protocol/show/<int:protocol_id>"
)
def
show_protocol
(
protocol_id
):
...
...
@@ -488,31 +490,62 @@ def upload_source_to_known_protocol(protocol_id):
@
login_required
def
upload_new_protocol
():
user
=
current_user
()
available_types
=
[
protocoltype
for
protocoltype
in
ProtocolType
.
query
.
all
()
if
protocoltype
.
has_modify_right
(
user
)
]
available_types
=
ProtocolType
.
get_modifiable_protocoltypes
()
form
=
NewProtocolSourceUploadForm
(
protocoltypes
=
available_types
)
if
form
.
validate_on_submit
():
if
form
.
source
.
data
is
None
:
flash
(
"Es wurde keine Datei ausgewählt."
,
"alert-error"
)
else
:
file
=
form
.
source
.
data
if
file
.
filename
==
""
:
flash
(
"Es wurde keine Datei ausgewählt."
,
"alert-error"
)
else
:
source
=
file
.
stream
.
read
().
decode
(
"utf-8"
)
protocoltype
=
ProtocolType
.
query
.
filter_by
(
id
=
form
.
protocoltype
.
data
).
first
()
if
protocoltype
is
None
or
not
protocoltype
.
has_modify_right
(
user
):
flash
(
"Invalider Protokolltyp oder keine Rechte."
,
"alert-error"
)
else
:
protocol
=
Protocol
(
protocoltype
.
id
,
None
,
source
)
db
.
session
.
add
(
protocol
)
db
.
session
.
commit
()
tasks
.
parse_protocol
(
protocol
)
return
redirect
(
request
.
args
.
get
(
"next"
)
or
url_for
(
"show_protocol"
,
protocol_id
=
protocol
.
id
))
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
file
=
form
.
source
.
data
if
file
.
filename
==
""
:
flash
(
"Es wurde keine Datei ausgewählt."
,
"alert-error"
)
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
source
=
file
.
stream
.
read
().
decode
(
"utf-8"
)
protocoltype
=
ProtocolType
.
query
.
filter_by
(
id
=
form
.
protocoltype
.
data
).
first
()
if
protocoltype
is
None
or
not
protocoltype
.
has_modify_right
(
user
):
flash
(
"Invalider Protokolltyp oder keine Rechte."
,
"alert-error"
)
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
protocol
=
Protocol
(
protocoltype
.
id
,
None
,
source
)
db
.
session
.
add
(
protocol
)
db
.
session
.
commit
()
tasks
.
parse_protocol
(
protocol
)
return
redirect
(
request
.
args
.
get
(
"next"
)
or
url_for
(
"show_protocol"
,
protocol_id
=
protocol
.
id
))
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
@
app
.
route
(
"/protocol/upload/new/file/"
,
methods
=
[
"POST"
])
@
login_required
def
upload_new_protocol_by_file
():
user
=
current_user
()
available_types
=
ProtocolType
.
get_modifiable_protocoltypes
(
user
)
form
=
NewProtocolFileUploadForm
(
protocoltypes
=
available_types
)
if
form
.
validate_on_submit
():
if
form
.
file
.
data
is
None
:
flash
(
"Es wurde keine Datei ausgewählt."
,
"alert-error"
)
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
file
=
form
.
file
.
data
if
file
.
filename
==
""
:
flash
(
"Es wurde keine Datei ausgewählt."
,
"alert-error"
)
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
filename
=
secure_filename
(
file
.
filename
)
protocoltype
=
ProtocolType
.
query
.
filter_by
(
id
=
form
.
protocoltype
.
data
).
first
()
if
protocoltype
is
None
or
not
protocoltype
.
has_modify_right
(
user
):
flash
(
"Invalider Protokolltyp oder keine Rechte."
,
"alert-error"
)
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
protocol
=
Protocol
(
protocoltype
.
id
,
datetime
.
now
().
date
(),
done
=
True
)
db
.
session
.
add
(
protocol
)
db
.
session
.
commit
()
document
=
Document
(
protocol
.
id
,
filename
,
""
,
False
,
form
.
private
.
data
)
db
.
session
.
add
(
document
)
db
.
session
.
commit
()
internal_filename
=
"{}-{}-{}"
.
format
(
protocol
.
id
,
document
.
id
,
filename
)
document
.
filename
=
internal_filename
file
.
save
(
os
.
path
.
join
(
config
.
DOCUMENTS_PATH
,
internal_filename
))
db
.
session
.
commit
()
return
redirect
(
request
.
args
.
get
(
"next"
)
or
url_for
(
"show_protocol"
,
protocol_id
=
protocol
.
id
))
return
redirect
(
request
.
args
.
get
(
"fail"
)
or
url_for
(
"new_protocol"
))
@
app
.
route
(
"/protocol/source/<int:protocol_id>"
)
@
login_required
def
get_protocol_source
(
protocol_id
):
...
...
templates/protocol-new.html
View file @
151641e8
...
...
@@ -10,8 +10,10 @@
{{render_form(form, action_url=url_for("new_protocol"), action_text="Anlegen")}}
</div>
<div
id=
"left-column"
class=
"col-lg-6"
>
<h3>
Neues Protokoll
hochladen
</h3>
<h3>
Quellcode
hochladen
</h3>
{{render_form(upload_form, action_url=url_for("upload_new_protocol", fail=url_for("new_protocol")), action_text="Hochladen", enctype="multipart/form-data")}}
<h3>
Datei hochladen
</h3>
{{render_form(file_upload_form, action_url=url_for("upload_new_protocol_by_file", fail=url_for("new_protocol")), action_text="Hochladen", enctype="multipart/form-data")}}
</div>
</div>
</div>
...
...
views/forms.py
View file @
151641e8
...
...
@@ -56,6 +56,15 @@ class NewProtocolSourceUploadForm(FlaskForm):
super
().
__init__
(
**
kwargs
)
self
.
protocoltype
.
choices
=
[(
protocoltype
.
id
,
protocoltype
.
short_name
)
for
protocoltype
in
protocoltypes
]
class
NewProtocolFileUploadForm
(
FlaskForm
):
file
=
FileField
(
"Datei"
)
protocoltype
=
SelectField
(
"Typ"
,
choices
=
[],
coerce
=
int
)
private
=
BooleanField
(
"Intern"
)
def
__init__
(
self
,
protocoltypes
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
self
.
protocoltype
.
choices
=
[(
protocoltype
.
id
,
protocoltype
.
short_name
)
for
protocoltype
in
protocoltypes
]
class
ProtocolForm
(
FlaskForm
):
date
=
DateField
(
"Datum"
,
validators
=
[
InputRequired
(
"Bitte gib das Datum des Protkolls an."
)],
format
=
"%d.%m.%Y"
)
start_time
=
DateTimeField
(
"Beginn"
,
format
=
"%H:%M"
,
validators
=
[
Optional
()])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment