Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Tag browsing

Added attachments to data model and API returns
Added video element to Track view
  • Loading branch information...
commit e46bb04fdb022f36e6ee1dd696117be9e5c0e5f8 1 parent a6bfb5f
@calaldees authored
View
2  website/development.ini
@@ -18,8 +18,10 @@ text.title = KaraKara (dev)
# Static Assets ----------------------------------------------------------------
static.assets = static
+static.media = ../../mediaserver/www/files
#static.assets = http://staticserver.com/
+
# Database ---------------------------------------------------------------------
sqlalchemy.url = sqlite:///%(here)s/KaraKara.db
View
7 website/karakara/__init__.py
@@ -51,7 +51,12 @@ def main(global_config, **settings):
# Routes -------------------------------------------------------------------
# Static Routes
- config.add_static_view(settings["static.assets"], "karakara:static") #cache_max_age=3600
+ config.add_static_view(name=settings["static.assets"], path="karakara:static") #cache_max_age=3600
+
+ # AllanC - it's official ... static route setup and generation is a mess in pyramid
+ #config.add_static_view(name=settings["static.media" ], path="karakara:media" )
+ config.add_static_view(name='media', path=settings["static.media"])
+
# Routes
def append_format_pattern(route):
View
1  website/karakara/lib/pyramid_helpers.py
@@ -12,3 +12,4 @@ def get_setting(key, request=None, return_type=None):
if return_type=='int' or return_type==int:
value = int(value)
return value
+
View
15 website/karakara/model/model_tracks.py
@@ -53,7 +53,8 @@ class Track(Base):
__to_dict__.update({'full': copy.deepcopy(__to_dict__['default'])})
__to_dict__['full'].update({
#Base.to_dict_setup(self, list_type='full', clone_list='default', filed_processors={
- 'attachments' : lambda track: [attachment.to_dict() for attachments in track.attachments] ,
+ 'description' : None ,
+ 'attachments' : lambda track: [attachment.to_dict() for attachment in track.attachments] ,
'tags' : lambda track: [tag.name for tag in track.tags],
})
@@ -100,3 +101,15 @@ class Attachment(Base):
id = Column(Integer(), primary_key=True)
location = Column(Unicode(250), nullable=False)
type = Column(_attachment_types, nullable=False)
+
+ __to_dict__ = copy.deepcopy(Base.__to_dict__)
+ __to_dict__.update({
+ 'default': {
+ 'id' : None ,
+ 'location' : None ,
+ 'type' : None ,
+ },
+ })
+ __to_dict__.update({'full': copy.deepcopy(__to_dict__['default'])})
+ __to_dict__['full'].update({
+ })
View
4 website/karakara/templates/html/home.mako
@@ -1,7 +1,9 @@
<%inherit file="_base.mako"/>
-<a href="track_list" data-role="button">Tracks </a>
+<a href="track_list" data-role="button">All Tracks</a>
+## AllanC - ****! I need the slash here because of the broken routing ... rarararar
+<a href="tags/" data-role="button">Tag Browser</a>
<a href="queue" data-role="button">Queue </a>
<a href="fave" data-role="button">Fave's </a>
View
44 website/karakara/templates/html/tags.mako
@@ -1,7 +1,43 @@
<%inherit file="_base.mako"/>
-<h2>Tracks from Tags</h2>
+<%
+ def media_url(file):
+ return '/media/%s' % file
+%>
-% for track in data.get('tracks'):
-<p>${track.get('title')}:${track.get('duration')}</p>
-% endfor
+
+% if data['tags']:
+ <!-- back -->
+ <a href="${request.route_path('tags', tags="/".join(data['tags'][0:-1]))}" data-role="button" data-icon="back">Back</a>
+% endif
+
+% if data['tracks']:
+ <!-- tracks -->
+ <h2>Tracks</h2>
+ <ul data-role="listview" data-inset="true">
+ % for track in data['tracks']:
+ <li>
+ <a href="${request.route_path('track', id=track['id'], spacer='', format='')}">
+ <%
+ try : img_url = media_url([attachment['location'] for attachment in track['attachments'] if attachment['type']=='image'][0])
+ except: img_url = None
+ %>
+ % if img_url:
+ <img src="${img_url}" />
+ % endif
+ ${track.get('title')}
+ </a>
+ </li>
+ % endfor
+ </ul>
+% endif
+
+% if not data['tracks']:
+ <!-- sub tags -->
+ <h2>Sub Tags</h2>
+ <ul data-role="listview" data-inset="true">
+ % for tag in data.get('sub_tags'):
+ <li><a href="${request.route_path('tags', tags="/".join(data['tags'] + [tag['name']]))}">${tag['name']} <span class="ui-li-count">${tag['count']}</span></a></li>
+ % endfor
+ </ul>
+% endif
View
42 website/karakara/templates/html/track.mako
@@ -1,7 +1,41 @@
<%inherit file="_base.mako"/>
-<h2>Track</h2>
-% for key,value in data.items():
-<p>${key}:${value}</p>
+<%
+ def media_url(file):
+ return '/media/%s' % file
+
+ def get_loc(attachment_type):
+ return [media_url(attatchment['location']) for attatchment in data['attachments'] if attatchment['type']==attachment_type]
+
+ video_files = [
+ ('.mp4','mp4'),
+ ('.ogv','ogg'),
+ ('.mpg','mpg'),
+ ('.3gp','3gp'),
+ ]
+%>
+
+<h2>${data['title']}</h2>
+
+<!-- video -->
+<video poster="${get_loc('image')[0]}" controls>
+ % for attachment in data['attachments']:
+ % for extension, video_type in video_files:
+ % if extension in attachment['location']:
+ <source src="${attachment['location']}" type="video/${video_type}" />
+ % endif
+ % endfor
+ % endfor
+ ##<a href="${preview_url}">preview</a>
+</video>
+
+<!-- details -->
+<p>${data['description']}</p>
+
+
+<%doc>
+<!-- images -->
+% for image_url in get_loc('image'):
+ <img src="${image_url}" />
% endfor
-##from . import DBSession
+</%doc>
View
29 website/karakara/tests/init_data.py
@@ -5,19 +5,43 @@
from ..lib.misc import random_string
from ..model.actions import get_tag
-from ..model.model_tracks import Track, Tag
+from ..model.model_tracks import Track, Tag, Attachment
import logging
log = logging.getLogger(__name__)
def init_random_data(num_tracks=100):
+
+ # Attachment generation ----------------------------------------------------
+ attachments_meta = [
+ ('preview1.3gp' , 'preview' ),
+ ('preview2.flv' , 'preview' ),
+ ('image1.jpg' , 'image' ),
+ ('image2.jpg' , 'image' ),
+ ('image3.png' , 'image' ),
+ ('processed.mpg', 'processed'),
+ ('subtitles.ssa', 'subtitle' ),
+ ]
+ attachments = []
+ for location, type in attachments_meta:
+ attachment = Attachment()
+ attachment.location = location
+ attachment.type = type
+ DBSession.add(attachment)
+ attachments.append(attachment)
+
+ # Random Tag generation ----------------------------------------------------
parent_tag = get_tag('series')
for series_num in range(10):
DBSession.add(Tag('Series %s'%random_string(1), parent_tag))
+
transaction.commit()
+
+ # --------------------------------------------------------------------------
+
tags = DBSession.query(Tag).all()
def get_random_tags(num_tags=None):
@@ -35,6 +59,8 @@ def get_random_description(words=None, word_size=None):
word_size = random.randint(2,16)
return " ".join([random_string(word_size) for word in range(words)])
+
+ # Track generation ---------------------------------------------------------
for track_number in range(num_tracks):
track = Track()
track.id = "track_%d" % track_number
@@ -42,6 +68,7 @@ def get_random_description(words=None, word_size=None):
track.description = get_random_description()
track.duration = random.randint(60,360)
track.tags = list(set(get_random_tags()))
+ track.attachments = attachments
DBSession.add(track)
transaction.commit()
View
14 website/karakara/views/tags.py
@@ -15,9 +15,10 @@
@auto_format_output
def tags(request):
# Hack - remove any format tags from route match - idealy this would be done at the route level
- request.matchdict['tags'] = re.sub('|'.join(['\.'+f for f in registered_formats()]),'',request.matchdict['tags'])
-
- tag_strings = request.matchdict['tags'].split('/')
+ tag_string = re.sub('|'.join(['\.'+f for f in registered_formats()]),'',request.matchdict['tags'])
+ tag_strings = []
+ if tag_string:
+ tag_strings = tag_string.split('/')
#tags_single = []
#tags_parents = []
@@ -35,9 +36,14 @@ def tags(request):
tracks = DBSession.query(Track).filter(Track.id.in_(trackids)).options(joinedload(Track.tags),joinedload(Track.attachments))
sub_tags = DBSession.query(Tag ,func.count(TrackTagMapping.tag_id)).join(TrackTagMapping).filter(TrackTagMapping.track_id.in_(trackids)).group_by(Tag.id).options(joinedload(Tag.parent))
+ # Don't return tracks if there are too many returns, force the user to select more subtags
+ if tracks.count() > 10:
+ tracks = []
+
return action_ok(
data={
'tracks' : [track.to_dict('full') for track in tracks],
- 'sub_tags': [update_dict(tag.to_dict(),{'count':count}) for tag,count in sub_tags],
+ 'sub_tags': [update_dict(tag.to_dict(),{'count':count}) for tag,count in sub_tags if tag not in tags],
+ 'tags' : tag_strings,
}
)
Please sign in to comment.
Something went wrong with that request. Please try again.