Skip to content

Commit

Permalink
New hgtv with channels and playlists.
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Apr 5, 2012
1 parent 6959061 commit c36c6ce
Show file tree
Hide file tree
Showing 31 changed files with 266 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -12,4 +12,7 @@ build/
dist/
settings.py
.webassets-cache
.sass-cache
nosetests.xml
baseframe-packed.css
baseframe-packed.js
10 changes: 10 additions & 0 deletions config.rb
@@ -0,0 +1,10 @@
# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "hgtv/static/css"
sass_dir = "hgtv/static/sass"
images_dir = "hgtv/static/img"
javascripts_dir = "hgtv/static/js"
line_comments = false
# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true
25 changes: 6 additions & 19 deletions hgtv/__init__.py
Expand Up @@ -5,38 +5,25 @@
from flask import Flask
from flask.ext.assets import Environment, Bundle
from baseframe import baseframe, baseframe_js, baseframe_css
from coaster import configureapp
from coaster.app import configure

# First, make an app and config it

app = Flask(__name__, instance_relative_config=True)
configureapp(app, 'HGTV_SETTINGS')
configure(app, 'HGTV_ENV')

# Second, setup baseframe and assets

app.register_blueprint(baseframe)

assets = Environment(app)
js = Bundle(baseframe_js)
css = Bundle(baseframe_css)
css = Bundle(baseframe_css,
'css/hgtv.css')
assets.register('js_all', js)
assets.register('css_all', css)

# Third, after config, import the models and views

import hgtv.models
import hgtv.views

# Fourth, setup admin for the models

from flask.ext import admin
from sqlalchemy.orm import scoped_session, sessionmaker
from hgtv.views.login import lastuser

db_session = scoped_session(sessionmaker(
autocommit=False, autoflush=False,
bind=hgtv.models.db.engine))

admin_blueprint = admin.create_admin_blueprint(
hgtv.models, db_session,
view_decorator=lastuser.requires_permission('siteadmin'))

app.register_blueprint(admin_blueprint, url_prefix='/admin')
1 change: 1 addition & 0 deletions hgtv/forms/__init__.py
@@ -0,0 +1 @@
from hgtv.forms.playlist import *
10 changes: 10 additions & 0 deletions hgtv/forms/playlist.py
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from baseframe.forms import Form
import flask.ext.wtf as wtf

__all__ = ['PlaylistForm']


class PlaylistForm(Form):
title = wtf.TextField('Title', validators=[wtf.Required()])
5 changes: 2 additions & 3 deletions hgtv/models/__init__.py
Expand Up @@ -2,12 +2,11 @@

from flask.ext.sqlalchemy import SQLAlchemy
from hgtv import app
from coaster.sqlalchemy import IdMixin, TimestampMixin, BaseMixin, BaseNameMixin
from coaster.sqlalchemy import BaseMixin, BaseNameMixin

db = SQLAlchemy(app)

from hgtv.models.show import *
from hgtv.models.season import *
from hgtv.models.channel import *
from hgtv.models.tag import *
from hgtv.models.user import *
from hgtv.models.video import *
29 changes: 29 additions & 0 deletions hgtv/models/channel.py
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

from hgtv.models import db, BaseNameMixin


class Channel(db.Model, BaseNameMixin):
__tablename__ = 'channel'
userid = db.Column(db.Unicode(22), nullable=False, unique=True)
featured = db.Column(db.Boolean, default=False, nullable=False)


class Playlist(db.Model, BaseNameMixin):
__tablename__ = 'playlist'
channel_id = db.Column(db.Integer, db.ForeignKey('channel.id'), nullable=False)
channel = db.relationship(Channel, primaryjoin=channel_id == Channel.id,
backref=db.backref('playlists', cascade='all, delete-orphan'))
featured = db.Column(db.Boolean, default=False, nullable=False)


channels_videos = db.Table('channels_videos',
db.Column('channel_id', db.Integer, db.ForeignKey('channel.id'), nullable=False),
db.Column('video_id', db.Integer, db.ForeignKey('video.id'), nullable=False)
)


playlists_videos = db.Table('playlists_videos',
db.Column('playlist_id', db.Integer, db.ForeignKey('playlist.id'), nullable=False),
db.Column('video_id', db.Integer, db.ForeignKey('video.id'), nullable=False)
)
18 changes: 0 additions & 18 deletions hgtv/models/season.py

This file was deleted.

17 changes: 0 additions & 17 deletions hgtv/models/show.py

This file was deleted.

11 changes: 6 additions & 5 deletions hgtv/models/tag.py
@@ -1,25 +1,26 @@
# -*- coding: utf-8 -*-

from coaster import makename
from coaster import make_name
from hgtv.models import db, BaseMixin

__all__ = ['Tag']


class Tag(db.Model, BaseMixin):
__tablename__ = 'tag'
name = db.Column(db.Unicode(80), unique=True, nullable=False)
title = db.Column(db.Unicode(80), unique=True, nullable=False)

def __repr__(self):
return self.name

@classmethod
def get(cls, title):
tag = cls.query.filter_by(title=title).first()
if tag:
return tag
else:
name = makename(title)
name = make_name(title)
# Is this name already in use? If yes, return it
tag = cls.query.filter_by(name=name).first()
if tag:
Expand All @@ -30,9 +31,9 @@ def get(cls, title):
return tag

def rename(self, title):
name = makename(tagname)
name = make_name(title)
if self.query.filter_by(name=name).first() is not None:
raise ValueError, u"Name already in use"
raise ValueError(u"Name already in use")
else:
self.name = name
self.title = title
Expand Down
21 changes: 13 additions & 8 deletions hgtv/models/video.py
@@ -1,20 +1,25 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

from hgtv.models import db, BaseMixin
from hgtv.models import db, BaseNameMixin
from hgtv.models.tag import tags_videos
from hgtv.models.channel import Channel, channels_videos, playlists_videos

__all__ = ['Video']

class Video(db.Model, BaseMixin):

class Video(db.Model, BaseNameMixin):
__tablename__ = 'video'
name = db.Column(db.Unicode(80), unique=True, nullable=False)
title = db.Column(db.Unicode(80), unique=True, nullable=False)
description = db.Column(db.Text(), nullable=False)
url = db.Column(db.Unicode(80), unique=True, nullable=False)
season_id = db.Column(db.Integer, db.ForeignKey('season.id'), nullable=False)
channel_id = db.Column(db.Integer, db.ForeignKey('channel.id'), nullable=False)
channel = db.relationship(Channel, primaryjoin=channel_id == Channel.id,
backref=db.backref('videos', cascade='all, delete-orphan'))
description = db.Column(db.UnicodeText, nullable=False, default=u'')
url = db.Column(db.Unicode(250), nullable=False)
slides = db.Column(db.Unicode(250), nullable=False, default=u'')

tags = db.relationship('Tag', secondary=tags_videos, backref=db.backref('videos'))
channels = db.relationship('Channel', secondary=channels_videos, backref=db.backref('tagged_videos'))
playlists = db.relationship('Playlist', secondary=playlists_videos, backref=db.backref('videos'))

def __repr__(self):
return self.name
return u'<Video %s>' % self.name
17 changes: 17 additions & 0 deletions hgtv/static/css/hgtv.css
@@ -0,0 +1,17 @@
#logo {
text-indent: -119988px;
overflow: hidden;
text-align: left;
background-image: url('../img/logo.png?1328964434');
background-repeat: no-repeat;
background-position: 50% 50%;
width: 137px;
height: 75px;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) {
#logo {
background-image: url('../img/logo@2x.png?1328994417');
-webkit-background-size: 137px 75px;
}
}
1 change: 1 addition & 0 deletions hgtv/static/css/packed.css

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes
Binary file added hgtv/static/img/logo@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions hgtv/static/sass/hgtv.sass
@@ -0,0 +1,9 @@
@import "compass/typography/text/replacement"

#logo
@include replace-text-with-dimensions('logo.png')

@media only screen and (-webkit-min-device-pixel-ratio: 2)
#logo
background-image: image-url('logo@2x.png')
-webkit-background-size: image-width('logo.png') image-height('logo.png')
2 changes: 2 additions & 0 deletions hgtv/templates/channel.html
@@ -0,0 +1,2 @@
{% extends "layout.html" %}
{% block title %}{{ channel.title }}{% endblock %}
12 changes: 4 additions & 8 deletions hgtv/templates/index.html
Expand Up @@ -3,13 +3,9 @@
<title>{% block title %}{{ config['SITE_TITLE'] }}{% endblock %}</title>
<meta name="DC.title" content="{{ config['SITE_TITLE'] }}"/>
{%- endblock %}

{% block content %}
<p>
HasGeek.tv is coming soon.
</p>
{% if g.user %}
<p>
You are logged in!
</p>
{% endif %}

Coming soon.

{% endblock %}
2 changes: 2 additions & 0 deletions hgtv/templates/playlist.html
@@ -0,0 +1,2 @@
{% extends "layout.html" %}
{% block title %}Playlist: {{ playlist.title }}{% endblock %}
2 changes: 2 additions & 0 deletions hgtv/templates/tag.html
@@ -0,0 +1,2 @@
{% extends "layout.html" %}
{% block title %}Videos tagged with {{ channel.title }}{% endblock %}
22 changes: 22 additions & 0 deletions hgtv/templates/video.html
@@ -0,0 +1,22 @@
{% extends "layout.html" %}
{% block headline %}
<h1><a href="/diogo">Diogo Ferreira on CyanogenMod</a> <small>&laquo; <a href="/droidcon">Droidcon</a> <a href="/droidcon/2011">2011</a></small></h1>
<p>Recorded November 2011</p>
{% endblock %}

{% block content %}

<div class="row">
<div class="span6">
<div class="video169">
<iframe src="http://www.youtube.com/embed/rTcFk4L7ux0?wmode=transparent" frameborder="0" allowfullscreen></iframe>
</div>
</div>
<div class="span6">
<div class="video169">
<iframe src="http://www.slideshare.net/slideshow/embed_code/9303960" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div>
</div>
</div>

{% endblock %}
8 changes: 4 additions & 4 deletions hgtv/views/__init__.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

import os
from flask import send_from_directory
from hgtv import app

import hgtv.views.index
import hgtv.views.login
import hgtv.views.channel
import hgtv.views.playlist
import hgtv.views.video
import hgtv.views.tag
13 changes: 13 additions & 0 deletions hgtv/views/channel.py
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-

from flask import render_template
from coaster.views import load_model

from hgtv import app
from hgtv.models import Channel


@app.route('/<channel>/')
@load_model(Channel, {'name': 'channel'}, 'channel')
def channel_view(channel):
return render_template('channel.html', channel=channel)
16 changes: 8 additions & 8 deletions hgtv/views/index.py
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-

import os
from flask import g, send_from_directory, Response, get_flashed_messages, flash, render_template
from flask import send_from_directory, render_template
from hgtv import app


@app.route('/')
def index():
return render_template('index.html')
resp = []
for category, msg in get_flashed_messages(with_categories=True):
resp.append(u'-- %s: %s --' % (category, msg))
if g.user:
resp.append(u'User: %s' % g.user)
resp.append(u"HasGeek.tv. Come back later.")
return Response(u'\n'.join(resp), mimetype="text/plain")


@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static', 'img'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')

0 comments on commit c36c6ce

Please sign in to comment.