From bcaf70e3f89ec677cf593aebff398549f1ed2901 Mon Sep 17 00:00:00 2001 From: RealMadrid <15989835@qq.com> Date: Mon, 1 May 2017 21:54:16 +1000 Subject: [PATCH] first commit --- __pycache__/config.cpython-35.pyc | Bin 0 -> 724 bytes app.db | Bin 0 -> 6144 bytes app/__init__.py | 8 ++++ app/__pycache__/__init__.cpython-35.pyc | Bin 0 -> 370 bytes app/__pycache__/forms.cpython-35.pyc | Bin 0 -> 580 bytes app/__pycache__/models.cpython-35.pyc | Bin 0 -> 657 bytes app/__pycache__/views.cpython-35.pyc | Bin 0 -> 1161 bytes app/forms.py | 8 ++++ app/models.py | 9 +++++ app/templates/base.html | 23 +++++++++++ app/templates/index.html | 7 ++++ app/templates/login.html | 35 +++++++++++++++++ app/views.py | 36 ++++++++++++++++++ config.py | 16 ++++++++ db_create.py | 12 ++++++ db_migrate.py | 15 ++++++++ db_repository/README | 4 ++ db_repository/__init__.py | 0 .../__pycache__/__init__.cpython-35.pyc | Bin 0 -> 181 bytes db_repository/manage.py | 5 +++ db_repository/migrate.cfg | 25 ++++++++++++ db_repository/versions/001_migration.py | 19 +++++++++ db_repository/versions/__init__.py | 0 .../__pycache__/001_migration.cpython-35.pyc | Bin 0 -> 595 bytes .../__pycache__/__init__.cpython-35.pyc | Bin 0 -> 190 bytes run.py | 3 ++ 26 files changed, 225 insertions(+) create mode 100644 __pycache__/config.cpython-35.pyc create mode 100644 app.db create mode 100644 app/__init__.py create mode 100644 app/__pycache__/__init__.cpython-35.pyc create mode 100644 app/__pycache__/forms.cpython-35.pyc create mode 100644 app/__pycache__/models.cpython-35.pyc create mode 100644 app/__pycache__/views.cpython-35.pyc create mode 100644 app/forms.py create mode 100644 app/models.py create mode 100644 app/templates/base.html create mode 100644 app/templates/index.html create mode 100644 app/templates/login.html create mode 100644 app/views.py create mode 100644 config.py create mode 100644 db_create.py create mode 100644 db_migrate.py create mode 100644 db_repository/README create mode 100644 db_repository/__init__.py create mode 100644 db_repository/__pycache__/__init__.cpython-35.pyc create mode 100644 db_repository/manage.py create mode 100644 db_repository/migrate.cfg create mode 100644 db_repository/versions/001_migration.py create mode 100644 db_repository/versions/__init__.py create mode 100644 db_repository/versions/__pycache__/001_migration.cpython-35.pyc create mode 100644 db_repository/versions/__pycache__/__init__.cpython-35.pyc create mode 100644 run.py diff --git a/__pycache__/config.cpython-35.pyc b/__pycache__/config.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fa474968bfaea1e06c96f314b77a75bc68c015c8 GIT binary patch literal 724 zcmZ9J&u*JQ5XJ|vF?H=GZPKQ_RK4_&i@8Qo6qOj9Sn5 zO&_6;(JR-U`U*XDA)#styQBHdeDe(wZ<@{e(U0ns$N)d#pGOnbhD#w+u6|)jJr$@iU=ffba^RK=a({o+dQ`HT_7MY_and69t zjC(PQl5wVmF6Vm|k*pH9TZ+_c##TPflwIVfAJ=glaxuT(?^~;)(OR&r?k*N=7sOm= zXSzpFb?UAeOOH$SmbQ|-l53G-414K^yd`{CNCS_wT;>-(7duX)eC;JtJHEHLi~cI} zjmx6+zf$WbLt)c3)3@cqT)a&l&BfBwMkX_!RYEsjXEk@u9}?mf%Q6k)rRP(OQEl#W zD#}@9!@K~UIG=k)uYF_nr`R;c#+Bh%_>0|r(&%@uZDVX<+Zqi~qwUxoYz>U7o@Hir z$7+s)?1uV2 s>-a9en=M$d^j57f$+U|tBRij7N@AKHi_nnX%kQMuiYlqff%NeH0p=gW5C8xG literal 0 HcmV?d00001 diff --git a/app.db b/app.db new file mode 100644 index 0000000000000000000000000000000000000000..2a6300d673db2175ece1e3730afe92cf8691bfc7 GIT binary patch literal 6144 zcmeI0K~LK-6oBm}4QeNjU9L~sfkqt?&}|2#Nz14i6bMChcD=4h>zZsTa6(vSr8i^YhEg_v|F{QP1KjgHKUBqA9eIiZDiR01!gj zv}9GD)a)usk#NyiP-|%Y*OS%CPgKPdqp7IvE@^rWE;)9Ee0o>t+AeuV93eV%y6;Wr1op`ZG)v}Ae<4JoMR3 z@;S&Br$?{SDDQi7{&|~o0%r zDI|BE)N2|1DZ>)?!q|OeUcE2`*^+Q*moG%GT0!u@n zEFc{ Gm&G4zq2OZx literal 0 HcmV?d00001 diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..f558b5f --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,8 @@ +from flask import Flask +from flask.ext.sqlalchemy import SQLAlchemy + +app = Flask(__name__) +app.config.from_object('config') +db = SQLAlchemy(app) + +from app import views, models \ No newline at end of file diff --git a/app/__pycache__/__init__.cpython-35.pyc b/app/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dafde6825250f2d1adb38c75f3b15d3429627223 GIT binary patch literal 370 zcmX|5%Sr<=6g|l_V>@l33-KRjQ}-fbL5rXirBE;oglQ+WQX5cmib-Gop{RibL~P~X4=$~xGTld2P(g?+~4t`erbmFgGv9=RX~<&D^;Xc zE9HW8v#DCXy}PVRtIGLWFB-|Sc_m1#LV|Zx9nU@d9G)E|*V|@Q7RmT(G`&=_^T{l^ o(8iRzWfK~hD3up^qttM-b?swX@6qTJM)5i#7_b5Fu>tGxU+FMcR{#J2 literal 0 HcmV?d00001 diff --git a/app/__pycache__/forms.cpython-35.pyc b/app/__pycache__/forms.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d242271a537be0f2b2fceafc175f349932df869c GIT binary patch literal 580 zcmYk4-D(su6vt2IbKUNi;zjipR%9QbNNGzu3YJn_C>RDp+MHd7CX;PuR_%3t86Uw{ z$*otuf>)liW33_ibMikQ^9#)WbUJ?ZBmek90Q`jiRz~p=o$ivv&=z0;oB%06@I3*W zfJ;H9;4+Ze;HF@6a0SQ$#9Nbr$>AFn=YRqpsJH}Ez+zVZqNy+wF{^xVvn1{;`p~qi zszGbwVbO+a(Qosa7ulM&(8g-X_+P#evNHosW-N-E@q=RQmWMs zm5O7foHrZG@kFV+jkZH3q(m2TmXd|3!-(WNgek`?zh9po)R*`DC*Ri9`SIetx;neK zs^6itzOuTzt@V0cFA1=lukS-aEqpp2HW4qy)*&D{U2^ptzxMMl{W2t!mnB8qIgoIR keE!#(KfQ85M4_QhWM2L;1|wEzGB literal 0 HcmV?d00001 diff --git a/app/__pycache__/models.cpython-35.pyc b/app/__pycache__/models.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4d6a6bb5ad289a6f033366ddf36e7ad75d0f0ad3 GIT binary patch literal 657 zcmZutOG_g`5U%cdIC;UIWRD*7Fo$^9;}S%1jV`WXAu2cwG_&d6I7!cB?8!hP-r}Fx zeh*n9yPZyR{NmkxV*szP^<4Ci(aJ7@#E*dn$QVQn*tz5& z9eBpD1B$_f!^(lk0qMdp^w!t{A+ucm8Ik+`d~}Y{$|nQ`Gzuq29FzkSw?>bMaQcd| z$lr?Z5Yq}%E@dT_Q4NoRk2U^hH4Tv19+2Fq39^9_o7TN4m9eeDq*-E?Vyc$cYtm-D zG?!{&{VGo%Dz#o%n@!MtEC&4umfM}5`CN_h2t1Y6 zAI?phk4=LrJe4J>HXZb9#aqy(n1eu8lA<>I%J$hlucL#|wGPVPFnL$BM4i|gK{qfo Q#|FKP&Lg^Oz1bK3AI1WVhX4Qo literal 0 HcmV?d00001 diff --git a/app/__pycache__/views.cpython-35.pyc b/app/__pycache__/views.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..01f0e49dd860547d8c9f7ae5fc19bf22c2024c24 GIT binary patch literal 1161 zcmYjQ&2HO95S|r(M9GpRBtV@8LBZry0YP#vnxaK*CvIHXh+Lx~1PHWtC9ljS)!mg7 z3&|;YfjmZ^rEjp;obn1e^Gu)l|<{N(3?Y2Mv7rlNR5`CsyR|NZ4i1`G? z@h~cg6r+rhYEaf76;Kus^RWgMA*qnE5bJ<=NJT^{rYt5VLRvJ5NA!WwwHWtHJ5l$0MiyIcfq92zm)?1_!Dz5O%#u=0FUnkrEE-KKYqL0C z+4D+g@!@JJOX0$^ieIho{dtw1354WqRityNi3_P_@Xy@i+VK>bU)i`Uo3 zyFZPOuTWJv-aq_p^m1~#H#{A`5Jge#qt6#(w03+c#T)ZvdF7%yTa1n74ip8Qpu<{_ zUeIDOZry_yT`xQduBil0=Eeoj_fA}Rd^9@wp9xP_3sN(&fPrp)AWsAOxIhz8=yS3l zfYqLW79s6`s~sEFj@UaeSUV7AF>HZfjcno>+|Y*+^rR$YTeQH;wdnhroAz-1pdOP{ zi+@(aSi#d-rPHIOC=Yg@JzDo3Jw`|gb%x1P;@Qm{t=l!Qy4||%p*BZyUZw}73vqzT zT1#DBO3bTq{iEZ(;lb|Y_|?(r!S3Fx(O^qAu_e26nHQ2{lqXd=F{?8rtqy!3u8?1H z7b2Luz*wDa-Ks+47p9s>?SEbuPpfh!=OFj44|qB^YTHMny3+eFO&^LHE!JT_vNpRW z>K=T1t&~O|SM_Z>6gf*Ey4)RmE3@_{EcJe19IW LKI>yXez^M$AA|@p literal 0 HcmV?d00001 diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..3ea2d7e --- /dev/null +++ b/app/forms.py @@ -0,0 +1,8 @@ +from flask.ext.wtf import Form +from wtforms import StringField, BooleanField +from wtforms.validators import DataRequired + + +class LoginForm(Form): + openid = StringField('openid', validators=[DataRequired()]) + remember_me = BooleanField('remember_me', default=False) diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..a2690ac --- /dev/null +++ b/app/models.py @@ -0,0 +1,9 @@ +from app import db + +class User(db.Model): + id = db.Column(db.Integer, primary_key = True) + nickname = db.Column(db.String(64), index = True, unique = True) + email = db.Column(db.String(120), index = True, unique = True) + + def __repr__(self): + return '' % (self.nickname) \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..1540718 --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,23 @@ + + + {% if title %} + {{title}} - microblog + {% else %} + microblog + {% endif %} + + +
HelloFlask: Home
+
+ {% with messages = get_flashed_messages() %} + {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} + {% endwith %} + {% block content %}{% endblock %} + + diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..eea3bb6 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} +{% block content %} +

Hi, {{user.nickname}}!

+{% for post in posts %} +

{{post.author.nickname}} says: {{post.body}}

+{% endfor %} +{% endblock %} \ No newline at end of file diff --git a/app/templates/login.html b/app/templates/login.html new file mode 100644 index 0000000..567a9ed --- /dev/null +++ b/app/templates/login.html @@ -0,0 +1,35 @@ + +{% extends "base.html" %} + +{% block content %} + +

Sign In

+
+ {{ form.hidden_tag() }} +

+ Please enter your OpenID, or select one of the providers below:
+ {{ form.openid(size=80) }} + {% for error in form.openid.errors %} + [{{error}}] + {% endfor %}
+ |{% for pr in providers %} + {{ pr.name }} | + {% endfor %} +

+

{{ form.remember_me }} Remember Me

+

+
+{% endblock %} + diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..e5f433e --- /dev/null +++ b/app/views.py @@ -0,0 +1,36 @@ +from flask import render_template, flash, redirect +from app import app +from .forms import LoginForm + + +@app.route('/') +@app.route('/index') +def index(): + user = {'nickname': 'Scott'} + posts = [ # fake array of posts + { + 'author': {'nickname': 'Lucine'}, + 'body': 'My beautiful girlfriend!' + }, + { + 'author': {'nickname': 'James'}, + 'body': 'The manager of Unigardens!' + } + ] + return render_template("index.html", + title='Home', + user=user, + posts=posts) + + +@app.route('/login', methods = ['GET', 'POST']) +def login(): + form = LoginForm() + if form.validate_on_submit(): + flash('Login requested for OpenID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data)) + return redirect('/index') + return render_template('login.html', + title='Sign In', + form=form, + providers=app.config['OPENID_PROVIDERS']) + diff --git a/config.py b/config.py new file mode 100644 index 0000000..ecfa23e --- /dev/null +++ b/config.py @@ -0,0 +1,16 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db') +SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository') + + +CSRF_ENABLED = True +SECRET_KEY = 'password' + +OPENID_PROVIDERS = [ + { 'name': 'Google', 'url': 'https://www.google.com/accounts/o8/id' }, + { 'name': 'Yahoo', 'url': 'https://me.yahoo.com' }, + { 'name': 'AOL', 'url': 'http://openid.aol.com/' }, + { 'name': 'Flickr', 'url': 'http://www.flickr.com/' }, + { 'name': 'MyOpenID', 'url': 'https://www.myopenid.com' }] \ No newline at end of file diff --git a/db_create.py b/db_create.py new file mode 100644 index 0000000..b0850f8 --- /dev/null +++ b/db_create.py @@ -0,0 +1,12 @@ +#!flask/bin/python +from migrate.versioning import api +from config import SQLALCHEMY_DATABASE_URI +from config import SQLALCHEMY_MIGRATE_REPO +from app import db +import os.path +db.create_all() +if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): + api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository') + api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) +else: + api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO)) \ No newline at end of file diff --git a/db_migrate.py b/db_migrate.py new file mode 100644 index 0000000..61dd068 --- /dev/null +++ b/db_migrate.py @@ -0,0 +1,15 @@ +#!flask/bin/python +import imp +from migrate.versioning import api +from app import db +from config import SQLALCHEMY_DATABASE_URI +from config import SQLALCHEMY_MIGRATE_REPO +migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1) +tmp_module = imp.new_module('old_model') +old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) +exec(old_model, tmp_module.__dict__) +script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta, db.metadata) +open(migration, "wt").write(script) +api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) +print('New migration saved as ' + migration) +print('Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))) diff --git a/db_repository/README b/db_repository/README new file mode 100644 index 0000000..6218f8c --- /dev/null +++ b/db_repository/README @@ -0,0 +1,4 @@ +This is a database migration repository. + +More information at +http://code.google.com/p/sqlalchemy-migrate/ diff --git a/db_repository/__init__.py b/db_repository/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/db_repository/__pycache__/__init__.cpython-35.pyc b/db_repository/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5d7327b872c82484a9e76b4a186b3d6237f2aaf4 GIT binary patch literal 181 zcmWgR<>fNHvMquE2p)q77+?f49Dul(1xTbYFa&Ed`mJOr0tq9CUr8xeF$I++8TolJ zX*r3-+3{tmd1Wy^nMpClnI);Z1&PVoiRr1uF}a!PMTsS;F=eSm#hLkenR)3kC8@au zIY6=En4;8ze4z6DqRN<*)U?FXoRXOM_{_Y_lK6PNg34PQHo5sJr8%i~AiIl!m;nI4 C@idnJ literal 0 HcmV?d00001 diff --git a/db_repository/manage.py b/db_repository/manage.py new file mode 100644 index 0000000..554f89c --- /dev/null +++ b/db_repository/manage.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +from migrate.versioning.shell import main + +if __name__ == '__main__': + main() diff --git a/db_repository/migrate.cfg b/db_repository/migrate.cfg new file mode 100644 index 0000000..ec2db66 --- /dev/null +++ b/db_repository/migrate.cfg @@ -0,0 +1,25 @@ +[db_settings] +# Used to identify which repository this database is versioned under. +# You can use the name of your project. +repository_id=database repository + +# The name of the database table used to track the schema version. +# This name shouldn't already be used by your project. +# If this is changed once a database is under version control, you'll need to +# change the table name in each database too. +version_table=migrate_version + +# When committing a change script, Migrate will attempt to generate the +# sql for all supported databases; normally, if one of them fails - probably +# because you don't have that database installed - it is ignored and the +# commit continues, perhaps ending successfully. +# Databases in this list MUST compile successfully during a commit, or the +# entire commit will fail. List the databases your application will actually +# be using to ensure your updates to that database work properly. +# This must be a list; example: ['postgres','sqlite'] +required_dbs=[] + +# When creating new change scripts, Migrate will stamp the new script with +# a version number. By default this is latest_version + 1. You can set this +# to 'true' to tell Migrate to use the UTC timestamp instead. +use_timestamp_numbering=False diff --git a/db_repository/versions/001_migration.py b/db_repository/versions/001_migration.py new file mode 100644 index 0000000..96092d7 --- /dev/null +++ b/db_repository/versions/001_migration.py @@ -0,0 +1,19 @@ +from sqlalchemy import * +from migrate import * + + +from migrate.changeset import schema +pre_meta = MetaData() +post_meta = MetaData() + +def upgrade(migrate_engine): + # Upgrade operations go here. Don't create your own engine; bind + # migrate_engine to your metadata + pre_meta.bind = migrate_engine + post_meta.bind = migrate_engine + + +def downgrade(migrate_engine): + # Operations to reverse the above upgrade go here. + pre_meta.bind = migrate_engine + post_meta.bind = migrate_engine diff --git a/db_repository/versions/__init__.py b/db_repository/versions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/db_repository/versions/__pycache__/001_migration.cpython-35.pyc b/db_repository/versions/__pycache__/001_migration.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a4515705b9232fb988e09e116257ecd861f7e8e GIT binary patch literal 595 zcmbVJ%Sr<=6up^8=V2=qq5m*0O5KWxVy%Ke<3Fr-ar2j^vyDg}4?Gyc+mD_8!4 zD{p3I(X}BtIrlEkIl1X|I{yBb{b(Bi->|i?hEqK99)aN|kN`Y1jMU74#DLU0`CNK*=u;~D^fwd~`0&`#zxId^10V&A=LQ5`IJf#bwo4E9?6P)9bJ%l#^ z1rU*n7@A;`NkGPdS-OSbQOXr9t$CcW(kpVQss<|Wrtwlx#Uq|A5#i(gug3^2A#4pTgn$S~bDg;c?NfRzf6Xe}E|#^efwntXjRUXr<#R$4 zJyHzV44~X=NPn@S*^*1HgsH{cTO8exDq4GM+bVyhw&h%9sO;V2G-vCCpXhIrZ3LhA LW|w%xGuqA{ZWwyl literal 0 HcmV?d00001 diff --git a/db_repository/versions/__pycache__/__init__.cpython-35.pyc b/db_repository/versions/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8349185db6c19562550058d0ff85d9abd27f0852 GIT binary patch literal 190 zcmWgR<>fNHvMquE2p)q77+?f49Dul(1xTbYFa&Ed`mJOr0tq9CU)d>EF$I++8TolJ zX*r3-+3{tmd1Wy^nMpClnI);Z1&PVoiRr1uF}a!PMTsS;F=eSm#hLkenR)3kC8@au zIY6=En4;8ze4z6DqRN<*)U?FXoD!J2;+XjO%)HE!_;|g7%3B;Zx%nxjIjMFaM-&4w F0|3^!ICTI3 literal 0 HcmV?d00001 diff --git a/run.py b/run.py new file mode 100644 index 0000000..178fd8a --- /dev/null +++ b/run.py @@ -0,0 +1,3 @@ +#!flask/bin/python +from app import app +app.run(debug=True)