Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Video AG Infrastruktur
website
Commits
30a210b6
Commit
30a210b6
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Added sqlite support and made query compatible
parent
db535aca
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+25
-7
25 additions, 7 deletions
server.py
with
25 additions
and
7 deletions
server.py
+
25
−
7
View file @
30a210b6
#!/bin/python
#!/bin/python
from
flask
import
Flask
,
render_template
,
g
from
flask
import
Flask
,
render_template
,
g
import
mysql.connector
import
mysql.connector
import
sqlite3
import
config
import
config
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
# Row wrapper for sqlite
def
dict_factory
(
cursor
,
row
):
d
=
{}
for
idx
,
col
in
enumerate
(
cursor
.
description
):
if
type
(
row
[
idx
])
==
str
:
d
[
col
[
0
].
split
(
'
.
'
)[
-
1
]]
=
row
[
idx
].
replace
(
'
\\
n
'
,
'
\n
'
)
else
:
d
[
col
[
0
].
split
(
'
.
'
)[
-
1
]]
=
row
[
idx
]
return
d
def
query
(
operation
,
*
params
):
def
query
(
operation
,
*
params
):
if
config
.
db_engine
==
'
mysql
'
:
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
g
.
db
=
mysql
.
connector
.
connect
(
user
=
config
.
db_user
,
password
=
config
.
db_passwd
,
host
=
config
.
db_host
,
database
=
config
.
db_db
)
g
.
db
=
mysql
.
connector
.
connect
(
user
=
config
.
db_user
,
password
=
config
.
db_passwd
,
host
=
config
.
db_host
,
database
=
config
.
db_db
)
cur
=
g
.
db
.
cursor
(
dictionary
=
True
)
cur
=
g
.
db
.
cursor
(
dictionary
=
True
)
cur
.
execute
(
operation
.
replace
(
'
?
'
,
'
%s
'
),
params
)
return
cur
.
fetchall
()
else
:
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
g
.
db
=
sqlite3
.
connect
(
config
.
db_file
)
g
.
db
.
row_factory
=
dict_factory
cur
=
g
.
db
.
cursor
()
cur
.
execute
(
operation
,
params
)
cur
.
execute
(
operation
,
params
)
return
cur
.
fetchall
()
return
cur
.
fetchall
()
...
@@ -19,8 +38,7 @@ def index():
...
@@ -19,8 +38,7 @@ def index():
FROM lectures
FROM lectures
LEFT JOIN videos ON (videos.lecture_id = lectures.id)
LEFT JOIN videos ON (videos.lecture_id = lectures.id)
LEFT JOIN courses on (courses.id = lectures.course_id)
LEFT JOIN courses on (courses.id = lectures.course_id)
WHERE (videos.time_updated >= SUBDATE(NOW(), 14))
WHERE (? OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
AND (%s OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
GROUP BY videos.lecture_id
GROUP BY videos.lecture_id
ORDER BY lastvidtime DESC
ORDER BY lastvidtime DESC
LIMIT 5
LIMIT 5
...
...
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