Skip to content

Commit

Permalink
Re #2. Filters 'view playlist' based on start and end time/date.
Browse files Browse the repository at this point in the history
Adds new view to view all assets.
  • Loading branch information
vpetersson committed Aug 1, 2012
1 parent 0fa752d commit 8b98aca
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 10 deletions.
73 changes: 67 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = "Viktor Petersson"
__copyright__ = "Copyright 2012, WireLoad Inc"
__license__ = "Dual License: GPLv2 and Commercial License"
__version__ = "0.1"
__version__ = "0.1.1"
__email__ = "vpetersson@wireload.net"

import json, hashlib, os, requests, mimetypes, sys, sqlite3, socket, netifaces
Expand All @@ -21,13 +21,55 @@
database = configdir + "screenly.db"
nodetype = "standalone"

def time_lookup():
if nodetype == "standalone":
return datetime.now()
elif nodetype == "managed":
return datetime.utcnow()

def get_playlist():

conn = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES)
c = conn.cursor()
c.execute("SELECT * FROM assets ORDER BY name")
assets = c.fetchall()

playlist = []
for asset in assets:
# Match variables with database
asset_id = asset[0]
name = asset[1]
filename = asset[2]
uri = asset[3] # Path in local database
input_start_date = asset[5]
input_end_date = asset[6]

try:
start_date = datestring.date_to_string(asset[5])
except:
start_date = None

try:
end_date = datestring.date_to_string(asset[6])
except:
end_date = None

duration = asset[7]
mimetype = asset[8]

playlistitem = { "name" : name, "uri" : uri, "duration" : duration, "mimetype" : mimetype, "asset_id" : asset_id, "start_date" : start_date, "end_date" : end_date}
if (start_date and end_date) and (input_start_date < time_lookup() and input_end_date > time_lookup()):
playlist.append(playlistitem)

return json.dumps(playlist)

def get_assets():

conn = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES)
c = conn.cursor()
c.execute("SELECT * FROM assets ORDER BY name")
assets = c.fetchall()

playlist = []
for asset in assets:
# Match variables with database
Expand All @@ -50,10 +92,12 @@ def get_playlist():
mimetype = asset[8]

playlistitem = { "name" : name, "uri" : uri, "duration" : duration, "mimetype" : mimetype, "asset_id" : asset_id, "start_date" : start_date, "end_date" : end_date}
playlist.append(playlistitem)
playlist.append(playlistitem)

return json.dumps(playlist)



def initiate_db():

# Create config dir if it doesn't exist
Expand Down Expand Up @@ -218,7 +262,7 @@ def update_asset():


@route('/delete_asset/:asset_id')
def edit_asset(asset_id):
def delete_asset(asset_id):
conn = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES)
c = conn.cursor()

Expand Down Expand Up @@ -277,6 +321,14 @@ def view_node_playlist():

return template('templates/server_standalone/view_playlist', nodeplaylist=nodeplaylist)

@route('/view_assets')
def view_assets():

nodeplaylist = json.loads(get_assets())

return template('templates/server_standalone/view_assets', nodeplaylist=nodeplaylist)


@route('/add_asset')
def add_asset():
return template('templates/server_standalone/add_asset')
Expand Down Expand Up @@ -307,8 +359,17 @@ def edit_asset(asset_id):
filename = asset[2]
uri = asset[3]
md5 = asset[4]
start_date = datestring.date_to_string(asset[5])
end_date = datestring.date_to_string(asset[6])

if asset[5]:
start_date = datestring.date_to_string(asset[5])
else:
start_date = None

if asset[6]:
end_date = datestring.date_to_string(asset[6])
else:
end_date = None

duration = asset[7]
mimetype = asset[8]

Expand All @@ -329,4 +390,4 @@ def mistake403(code):
def mistake404(code):
return 'Sorry, this page does not exist!'

run(host='0.0.0.0', port=8080, reloader=True)
run(host='0.0.0.0', port=8080, reloader=True)
19 changes: 15 additions & 4 deletions templates/server_standalone/edit_asset.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
% start_date = asset["start_date"].split("T")[0]
% start_time = asset["start_date"].split("T")[1]
% end_date = asset["end_date"].split("T")[0]
% end_time = asset["end_date"].split("T")[1]
% if asset["start_date"]:
% start_date = asset["start_date"].split("T")[0]
% start_time = asset["start_date"].split("T")[1]
% else:
% start_date = ""
% start_time = ""
% end

% if asset["end_date"]:
% end_date = asset["end_date"].split("T")[0]
% end_time = asset["end_date"].split("T")[1]
% else:
% end_date = ""
% end_time = ""
% end

<head>
<title>Screenly Edit Asset</title>
Expand Down
1 change: 1 addition & 0 deletions templates/server_standalone/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<h2>View</h2>
<p>
<a href="/view_playlist">View playlist</a><br />
<a href="/view_assets">View assets</a><br />
<a href="/system_info">View system info</a><br />
<p>

Expand Down
43 changes: 43 additions & 0 deletions templates/server_standalone/view_assets.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
% from datetime import datetime
<head>
<title>Screenly - View Assets</title>
<link type="text/css" href="/static/css/style.css" rel="Stylesheet" />
</head>
<body>
<div class="main">
<h1>Screenly :: View Assets</h1>
<table class="center">
<tr><th>Name</th><th>Start date</th><th>End date</th><th>Duration</th><th>URI</th><th>Edit</th></tr>
% for asset in nodeplaylist:
% if len(asset["uri"]) > 30:
% uri=asset["uri"][0:30] + "..."
% else:
% uri=asset["uri"]
% end

% if asset["start_date"]:
% input_start_date=asset["start_date"].split("T")
% start_date=input_start_date[0]
% start_time=input_start_date[1]
% else:
% start_date = "None"
% start_time = ""
% end

% if asset["end_date"]:
% input_end_date=asset["end_date"].split("T")
% end_date=input_end_date[0]
% end_time=input_end_date[1]
% else:
% end_date = "None"
% end_time = ""
% end

<tr><td>{{asset["name"]}}</td><td>{{start_date}} {{start_time}}</td><td>{{end_date}} {{end_time}}</td><td>{{asset['duration']}}</td><td><a href="{{asset['uri']}}">{{uri}}</a></td><td><a href="/edit_asset/{{asset['asset_id']}}">Edit</a></td></tr>
%end
</table>
</div>
<div class="footer">
<a href="/">Back</a>
</div>
</body>

0 comments on commit 8b98aca

Please sign in to comment.