Skip to content

Commit 6b26935

Browse files
committed
first commit
0 parents  commit 6b26935

13 files changed

+196
-0
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
*.pyc
3+
test.db
4+
*.wpr
5+
.project
6+
.pydevproject
7+
.settings
8+
*.egg-info
9+
.coverage
10+
docs/_build
11+
build/
12+
dist/
13+
settings.py

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HasGeek.tv
2+
==========
3+
4+
Source for [HasGeek.tv](http://hasgeek.tv).

hgtv/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from flask import Flask
4+
app = Flask(__name__, instance_relative_config=True)
5+
6+
app.config.from_pyfile('settings.py')
7+
8+
import hgtv.models
9+
import hgtv.views

hgtv/models/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from flaskext.sqlalchemy import SQLAlchemy
4+
from hgtv import app
5+
from coaster.sqlalchemy import IdMixin, TimestampMixin, BaseMixin, BaseNameMixin
6+
7+
db = SQLAlchemy(app)
8+
9+
from hgtv.models.user import *
10+
from hgtv.models.tag import *

hgtv/models/tag.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from coaster import makename
4+
from hgtv.models import db, BaseMixin
5+
6+
__all__ = ['Tag']
7+
8+
class Tag(db.Model, BaseMixin):
9+
__tablename__ = 'tag'
10+
name = db.Column(db.Unicode(80), unique=True, nullable=False)
11+
title = db.Column(db.Unicode(80), unique=True, nullable=False)
12+
13+
@classmethod
14+
def get(cls, title):
15+
tag = cls.query.filter_by(title=title).first()
16+
if tag:
17+
return tag
18+
else:
19+
name = makename(title)
20+
# Is this name already in use? If yes, return it
21+
tag = cls.query.filter_by(name=name).first()
22+
if tag:
23+
return tag
24+
else:
25+
tag = cls(name=name, title=title)
26+
db.session.add(tag)
27+
return tag
28+
29+
def rename(self, title):
30+
name = makename(tagname)
31+
if self.query.filter_by(name=name).first() is not None:
32+
raise ValueError, u"Name already in use"
33+
else:
34+
self.name = name
35+
self.title = title

hgtv/models/user.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from flask import g
4+
from flaskext.lastuser.sqlalchemy import UserBase
5+
from hgtv.models import db
6+
7+
__all__ = ['User']
8+
9+
class User(db.Model, UserBase):
10+
__tablename__ = 'user'
11+
12+
def default_user(context):
13+
return g.user.id if g.user else None

hgtv/static/favicon.ico

31.3 KB
Binary file not shown.

hgtv/views/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
from flask import send_from_directory
5+
from hgtv import app
6+
7+
import hgtv.views.index
8+
import hgtv.views.login

hgtv/views/index.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
from flask import g, send_from_directory, Response, get_flashed_messages, flash
5+
from hgtv import app
6+
7+
@app.route('/')
8+
def index():
9+
resp = []
10+
for category, msg in get_flashed_messages(with_categories=True):
11+
resp.append(u'-- %s: %s --' % (category, msg))
12+
if g.user:
13+
resp.append(u'User: %s' % g.user)
14+
resp.append(u"HasGeek.tv. Come back later.")
15+
return Response(u'\n'.join(resp), mimetype="text/plain")
16+
17+
18+
@app.route('/favicon.ico')
19+
def favicon():
20+
return send_from_directory(os.path.join(app.root_path, 'static'),
21+
'favicon.ico', mimetype='image/vnd.microsoft.icon')

hgtv/views/login.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from flask import Response, redirect, get_flashed_messages, flash
4+
from flaskext.lastuser import LastUser
5+
from flaskext.lastuser.sqlalchemy import UserManager
6+
from coaster.views import get_next_url
7+
8+
from hgtv import app
9+
from hgtv.models import db, User
10+
11+
lastuser = LastUser(app)
12+
lastuser.init_usermanager(UserManager(db, User))
13+
14+
15+
@app.route('/login')
16+
@lastuser.login_handler
17+
def login():
18+
return {'scope': 'id'}
19+
20+
21+
@app.route('/logout')
22+
@lastuser.logout_handler
23+
def logout():
24+
flash(u"You are now logged out", category='info')
25+
return get_next_url()
26+
27+
28+
@app.route('/login/redirect')
29+
@lastuser.auth_handler
30+
def lastuserauth():
31+
# Save the user object
32+
db.session.commit()
33+
return redirect(get_next_url())
34+
35+
36+
@lastuser.auth_error_handler
37+
def lastuser_error(error, error_description=None, error_uri=None):
38+
if error == 'access_denied':
39+
flash("You denied the request to login", category='error')
40+
return redirect(get_next_url())
41+
return Response(u"Error: %s\n"
42+
u"Description: %s\n"
43+
u"URI: %s" % (error, error_description, error_uri),
44+
mimetype="text/plain")

instance/settings-sample.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
3+
#: Database backend
4+
SQLALCHEMY_DATABASE_URI = 'sqlite:///test.db'
5+
#: Secret key
6+
SECRET_KEY = 'make this something random'
7+
#: Timezone
8+
TIMEZONE = 'Asia/Calcutta'
9+
#: LastUser server
10+
LASTUSER_SERVER = 'https://login.hasgeek.com/'
11+
#: LastUser client id
12+
LASTUSER_CLIENT_ID = ''
13+
#: LastUser client secret
14+
LASTUSER_CLIENT_SECRET = ''
15+
#: Mail settings
16+
#: MAIL_FAIL_SILENTLY : default True
17+
#: MAIL_SERVER : default 'localhost'
18+
#: MAIL_PORT : default 25
19+
#: MAIL_USE_TLS : default False
20+
#: MAIL_USE_SSL : default False
21+
#: MAIL_USERNAME : default None
22+
#: MAIL_PASSWORD : default None
23+
#: DEFAULT_MAIL_SENDER : default None
24+
MAIL_FAIL_SILENTLY = False
25+
MAIL_SERVER = 'localhost'
26+
DEFAULT_MAIL_SENDER = ('HasGeek.tv', '[email protected]')
27+
#: Logging: recipients of error emails
28+
ADMINS=[]
29+
#: Log file
30+
LOGFILE='error.log'

runserver.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
from hgtv import app
3+
from hgtv.models import db
4+
db.create_all()
5+
app.run(debug=True, port=8000)

website.wsgi

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
import os.path
3+
sys.path.insert(0, os.path.dirname(__file__))
4+
from hgtv import app as application

0 commit comments

Comments
 (0)