Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c3rater
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
content
c3rater
Commits
8bcbcea5
Commit
8bcbcea5
authored
Oct 30, 2019
by
User Erdgeist
Browse files
Options
Downloads
Patches
Plain Diff
standardize config access
parent
e8b020e2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rater.py
+17
-17
17 additions, 17 deletions
rater.py
templates/index.html
+7
-7
7 additions, 7 deletions
templates/index.html
with
24 additions
and
24 deletions
rater.py
+
17
−
17
View file @
8bcbcea5
...
...
@@ -17,10 +17,10 @@ parser.add_argument("-c", "--config", help="Config file location", default="./co
args
=
parser
.
parse_args
()
with
open
(
args
.
config
,
mode
=
"
r
"
,
encoding
=
"
utf-8
"
)
as
json_file
:
config
_data
=
json
.
load
(
json_file
)
config
=
json
.
load
(
json_file
)
app
=
Flask
(
__name__
)
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///
'
+
config
_data
.
get
(
'
frab-conference
'
)
+
'
-
'
+
config_data
.
get
(
'
track
'
)
+
'
.db
'
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///
'
+
config
[
'
frab-conference
'
]
+
'
-
'
+
config
[
'
track
'
]
+
'
.db
'
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
False
app
.
config
[
'
SECRET_KEY
'
]
=
'
Silence is golden. Gerd Eist.
'
app
.
jinja_env
.
trim_blocks
=
True
...
...
@@ -28,6 +28,8 @@ app.jinja_env.lstrip_blocks = True
db
=
SQLAlchemy
(
app
)
config
[
'
frab-conf-url
'
]
=
config
[
'
frab-url
'
]
+
config
[
'
frab-conference
'
]
class
Event
(
db
.
Model
):
"""
An event as dumped from frab
"""
frab_id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
...
...
@@ -53,7 +55,7 @@ class EventRating(db.Model):
@app.route
(
"
/
"
)
def
root
():
events
=
Event
.
query
.
all
()
return
render_template
(
'
index.html
'
,
events
=
events
,
json
=
json
,
config
=
config
_data
,
cat
=
config_data
.
get
(
'
categories
'
)
)
return
render_template
(
'
index.html
'
,
events
=
events
,
json
=
json
,
config
=
config
)
@app.route
(
'
/api/ratings
'
)
def
get_ratings
():
...
...
@@ -111,23 +113,19 @@ def add_rating(eventid):
db
.
session
.
commit
()
return
jsonify
({
"
result
"
:
"
ok
"
})
def
fetch_talks
(
config
):
def
fetch_talks
():
sess
=
requests
.
Session
()
new_session_page
=
sess
.
get
(
config
.
get
(
'
frab-url
'
)
)
new_session_page
=
sess
.
get
(
config
[
'
frab-url
'
]
)
tree
=
etree
.
HTML
(
new_session_page
.
text
)
auth_token
=
tree
.
xpath
(
"
//meta[@name=
'
csrf-token
'
]
"
)[
0
].
get
(
"
content
"
)
login_data
=
dict
()
login_data
[
'
user[email]
'
]
=
config
.
get
(
'
frab-user
'
)
login_data
[
'
user[password]
'
]
=
config
.
get
(
'
frab-password
'
)
login_data
[
'
user[email]
'
]
=
config
[
'
frab-user
'
]
login_data
[
'
user[password]
'
]
=
config
[
'
frab-password
'
]
login_data
[
'
user[remember_me]
'
]
=
1
login_data
[
'
authenticity_token
'
]
=
auth_token
frab
=
config
.
get
(
'
frab-url
'
)
conf
=
config
.
get
(
'
frab-conference
'
)
track
=
config
.
get
(
'
track-name
'
)
sess
.
post
(
frab
+
'
users/sign_in?conference_acronym=
'
+
conf
+
'
&locale=en
'
,
login_data
,
verify
=
False
)
response
=
sess
.
get
(
frab
+
'
en/
'
+
conf
+
'
/events?track_name=
'
+
track
+
'
&format=json
'
,
verify
=
False
,
stream
=
True
)
sess
.
post
(
config
[
'
frab-url
'
]
+
'
users/sign_in?conference_acronym=
'
+
config
[
'
frab-conference
'
]
+
'
&locale=en
'
,
login_data
,
verify
=
False
)
response
=
sess
.
get
(
config
[
'
frab-conf-url
'
]
+
'
/events?track_name=
'
+
config
[
'
track-name
'
]
+
'
&format=json
'
,
verify
=
False
,
stream
=
True
)
talks_json
=
json
.
loads
(
response
.
text
)
...
...
@@ -137,7 +135,7 @@ def fetch_talks(config):
imported
=
0
for
json_event
in
talks_json
[
'
events
'
]:
# print (json_event)
rawhtml
=
sess
.
get
(
frab
+
'
en/
'
+
conf
+
'
/events/
'
+
str
(
json_event
[
'
id
'
]),
verify
=
False
,
stream
=
True
)
rawhtml
=
sess
.
get
(
config
[
'
frab-conf-url
'
]
+
'
/events/
'
+
str
(
json_event
[
'
id
'
]),
verify
=
False
,
stream
=
True
)
tree
=
etree
.
HTML
(
rawhtml
.
text
)
submission_notes
=
tree
.
xpath
(
'
//b[text()=
"
Submission Notes(user and admin):
"
]
'
)[
0
].
tail
.
strip
()
...
...
@@ -157,16 +155,18 @@ def fetch_talks(config):
else
:
db
.
session
.
add
(
Event
(
frab_id
=
json_event
[
'
id
'
],
title
=
json_event
[
'
title
'
],
subtitle
=
json_event
[
'
subtitle
'
],
abstract
=
json_event
[
'
abstract
'
],
description
=
json_event
[
'
description
'
],
speakers
=
json
.
dumps
(
speakers
),
state
=
json_event
.
get
(
'
state
'
,
'
new
'
),
event_type
=
json_event
[
'
type
'
],
notes
=
submission_notes
)
)
imported
+=
1
for
goner
in
Event
.
query
.
filter
(
Event
.
frab_id
.
notin_
([
ev
[
'
id
'
]
for
ev
in
talks_json
[
'
events
'
]
])).
all
():
goner
.
state
=
'
gone
'
db
.
session
.
commit
()
print
(
'
Conference:
'
+
conf
+
'
, track:
'
+
track
+
'
, imported
'
+
str
(
len
(
talks_json
[
'
events
'
]))
+
'
events,
'
+
str
(
imported
)
+
'
new.
'
)
print
(
'
Conference:
'
+
conf
ig
[
'
track
'
]
+
'
, track:
'
+
config
[
'
track
'
]
+
'
, imported
'
+
str
(
len
(
talks_json
[
'
events
'
]))
+
'
events,
'
+
str
(
imported
)
+
'
new.
'
)
if
__name__
==
"
__main__
"
:
db
.
create_all
()
if
args
.
frab_import
:
fetch_talks
(
config_data
)
fetch_talks
()
else
:
app
.
run
(
host
=
config
_data
.
get
(
'
host
'
),
port
=
int
(
config
_data
.
get
(
'
port
'
)))
app
.
run
(
host
=
config
.
get
(
'
host
'
,
'
127.0.0.1
'
),
port
=
int
(
config
.
get
(
'
port
'
,
'
8080
'
)))
This diff is collapsed.
Click to expand it.
templates/index.html
+
7
−
7
View file @
8bcbcea5
...
...
@@ -2,7 +2,7 @@
<title>
{{ config.get('frab-conference') }} {{ config.get('track') }} rating helper
</title>
<head>
<script
type=
"text/javascript"
>
categories
=
{
{
%-
for
category
in
c
at
-%
}
{
%-
for
category
in
c
onfig
[
'
categories
'
]
-%
}
'
category{{ loop.index }}
'
:
'
{{ category }}
'
,
{
%-
endfor
-%
}
};
...
...
@@ -45,7 +45,7 @@
<div
class=
"event-rating hidden"
id=
"event-rating-new"
>
<div
class=
"event-rating-submitter"
></div>
{%- for category in c
at
-%}
{%- for category in c
onfig['categories']
-%}
<div><meter
category=
"category{{loop.index}}"
value=
"0"
min=
"0"
max=
"100"
></meter><span
class=
"event-rating-category-output"
category=
"category{{loop.index}}"
>
{{ category + " 0 %" }}
</span></div>
{%- endfor -%}
<div
class=
"event-rating-comment"
></div>
...
...
@@ -54,7 +54,7 @@
<div
id=
"event-own-rating"
>
<hr/>
<div
class=
"label"
>
comment
</div><textarea
rows=
"8"
id=
"event-comment"
></textarea>
{%- for category in c
at
-%}
{%- for category in c
onfig['categories']
-%}
<div
class=
"category-slider"
id=
"event-category{{loop.index}}-slider"
>
<div
class=
"label"
>
{{category}}:
</div>
<div
class=
"slider"
><input
category=
"category{{loop.index}}"
type=
"range"
min=
"0"
max=
"100"
step=
"5"
oninput=
"changeVal('event-category{{loop.index}}-output', this.value)"
></div>
...
...
@@ -71,7 +71,7 @@
{% for ev in events -%}
<li
class=
"event-list-item"
event_state=
"{{ev.state}}"
event_type=
"{{ev.event_type}}"
id=
"event-{{ev.frab_id}}"
>
<div
class=
"event-meter-bar"
>
{%- for m in range(1+c
at
|length) -%}
{%- for m in range(1+c
onfig['categories']
|length) -%}
<meter
class=
"top-meter meter-{{m}}"
id=
"event-{{ev.frab_id}}-meter-{{m}}"
value=
"0"
min=
"0"
max=
"100"
></meter>
{%- endfor -%}
</div>
...
...
@@ -80,7 +80,7 @@
{%- else -%}
<button
onclick=
"do_remove_event('{{ev.frab_id}}')"
title=
"remove this event"
class=
"mini-button remove-button"
>
del
</button>
{%- endif -%}
<div
class=
"event-title"
><a
href=
"{{ config
.get(
'frab-
url') }}en/{{ config.get('frab-conference')
}}/events/{{ ev.frab_id }}/"
>
{{ ev.title }}
</a></div>
<div
class=
"event-title"
><a
href=
"{{ config
[
'frab-
conf-url']
}}/events/{{ ev.frab_id }}/"
>
{{ ev.title }}
</a></div>
{%- if ev.subtitle -%}
<div
class=
"event-subtitle"
>
{{ ev.subtitle }}
</div>
{%- endif -%}
...
...
@@ -90,7 +90,7 @@
{%- endif -%}
<div
class=
"event-speaker"
><em>
speakers:
</em>
{%- for speaker_id, speaker_name in json.loads(ev.speakers or '{}').items() -%}
<a
href=
"{{ config
.get(
'frab-
url') }}en/{{ config.get('frab-conference')
}}/people/{{speaker_id}}"
>
{{speaker_name}}
</a>
<a
href=
"{{ config
[
'frab-
conf-url']
}}/people/{{speaker_id}}"
>
{{speaker_name}}
</a>
{%- endfor -%}
</div>
</div>
...
...
@@ -106,7 +106,7 @@
<div
class=
"event-rating"
id=
"event-rating-{{ev.frab_id}}"
submitter=
"{{rating.submitter}}"
>
<div
class=
"event-rating-submitter"
>
{{rating.submitter}}:
</div>
{%- for category, value in json.loads(rating.rating_dict or '{}').items()|sort -%}
<div><meter
category=
"{{category}}"
value=
"{{value}}"
min=
"0"
max=
"100"
></meter><span
class=
"event-rating-category-output"
category=
"{{category}}"
>
{{ c
at
[loop.index-1] + " " + value|string + " %" }}
</span></div>
<div><meter
category=
"{{category}}"
value=
"{{value}}"
min=
"0"
max=
"100"
></meter><span
class=
"event-rating-category-output"
category=
"{{category}}"
>
{{ c
onfig['categories']
[loop.index-1] + " " + value|string + " %" }}
</span></div>
{%- endfor -%}
<div
class=
"event-rating-comment"
>
{{rating.comment}}
</div>
</div>
...
...
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
sign in
to comment