# Path: seoul_serenity/utils.py
# def admin_required(func):
# 	@wraps(func)
# 	def decorated_view(*args, **kwargs):
# 		if current_user.get_id() == 1 :
# 			return func(*args, **kwargs)
# 		# return current_app.login_manager.unauthorized()
# 		return 'error'
# 	return decorated_view
# 
# Path: seoul_serenity/project/models.py
# class Project(SurrogatePK, Model):
#     __tablename__ = 'projects'
#     name = Column(db.String(80), unique=False, nullable=False)
#     start_date = Column(db.DateTime, nullable=True)
#     end_date = Column(db.DateTime, nullable=True)
#     description = Column(db.Text, nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     created_user_id = Column(db.Integer,nullable=True)
#     modified_at = Column(db.DateTime, nullable=True)
#     modified_user_id = Column(db.Integer,nullable=True)
#     display_yn = Column(db.Boolean, default=True)
# 
#     def __init__(self, name, **kwargs):
#         db.Model.__init__(self, name=name, **kwargs)
# 
#     def __repr__(self):
#         return '<Project({name})>'.format(name=self.name)
# 
#     def datetimeformat(value, format='%d-%m-%Y'):
#         return value.strftime(format,vlaue.gmtime())    
# 
# Path: seoul_serenity/project/forms.py
# class RegisterProjectForm(Form):
# 	name = TextField('Project', validators=[DataRequired(), Length(min=3)])
# 
# 	start_date = DateField('Start Date', validators=[DataRequired()])
# 	end_date = DateField('End Date', validators=[DataRequired()])
# 	description = TextField('Description', validators=[Length(min=0)])
# 
# 	## TODO : session id ( users.id )  
# 	# created_user_id = session['username']
# 
# 	def __init__(self, *args, **kwargs):
# 		super(RegisterProjectForm, self).__init__(*args, **kwargs)
#         # self.user = None
# 
# 	def validate(self):
# 		return True


from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask.ext.login import login_user, login_required, logout_user, current_user
from seoul_serenity.utils import admin_required
from .models import Project
from .forms import RegisterProjectForm
from seoul_serenity.database import (
    Column,
    db,
    Model,
    ReferenceCol,
    relationship,
    SurrogatePK,
)
# -*- coding: utf-8 -*-
# from flask.ext.login import login_required

blueprint = Blueprint("project", __name__, url_prefix='/projects',
                        static_folder="../static")


# / (GET) : Project List Page
# / (POST) : Project ADD
# /<PID> (GET) : 특정 프로젝트 정보
# /<PID> (POST) : 특정 프로젝트 정보 입력

@blueprint.route("/test")
# @login_required
def ttt():
    if current_user == None:
        return current_user.username
    else:
        return "....."

# TODO 서영태 : Pagination 적용 (MUST)
@blueprint.route("/")
@login_required
def projects():
    query = request.args.get('project')
    if query:

# Path: seoul_serenity/utils.py
# def admin_required(func):
# 	@wraps(func)
# 	def decorated_view(*args, **kwargs):
# 		if current_user.get_id() == 1 :
# 			return func(*args, **kwargs)
# 		# return current_app.login_manager.unauthorized()
# 		return 'error'
# 	return decorated_view
# 
# Path: seoul_serenity/project/models.py
# class Project(SurrogatePK, Model):
#     __tablename__ = 'projects'
#     name = Column(db.String(80), unique=False, nullable=False)
#     start_date = Column(db.DateTime, nullable=True)
#     end_date = Column(db.DateTime, nullable=True)
#     description = Column(db.Text, nullable=True)
#     created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
#     created_user_id = Column(db.Integer,nullable=True)
#     modified_at = Column(db.DateTime, nullable=True)
#     modified_user_id = Column(db.Integer,nullable=True)
#     display_yn = Column(db.Boolean, default=True)
# 
#     def __init__(self, name, **kwargs):
#         db.Model.__init__(self, name=name, **kwargs)
# 
#     def __repr__(self):
#         return '<Project({name})>'.format(name=self.name)
# 
#     def datetimeformat(value, format='%d-%m-%Y'):
#         return value.strftime(format,vlaue.gmtime())    
# 
# Path: seoul_serenity/project/forms.py
# class RegisterProjectForm(Form):
# 	name = TextField('Project', validators=[DataRequired(), Length(min=3)])
# 
# 	start_date = DateField('Start Date', validators=[DataRequired()])
# 	end_date = DateField('End Date', validators=[DataRequired()])
# 	description = TextField('Description', validators=[Length(min=0)])
# 
# 	## TODO : session id ( users.id )  
# 	# created_user_id = session['username']
# 
# 	def __init__(self, *args, **kwargs):
# 		super(RegisterProjectForm, self).__init__(*args, **kwargs)
#         # self.user = None
# 
# 	def validate(self):
# 		return True


# Path: seoul_serenity/project/views.py
from flask import Blueprint, render_template, request, redirect, url_for, flash
from flask.ext.login import login_user, login_required, logout_user, current_user
from seoul_serenity.utils import admin_required
from .models import Project
from .forms import RegisterProjectForm
from seoul_serenity.database import (
    Column,
    db,
    Model,
    ReferenceCol,
    relationship,
    SurrogatePK,
)

# -*- coding: utf-8 -*-
# from flask.ext.login import login_required

blueprint = Blueprint("project", __name__, url_prefix='/projects',
                        static_folder="../static")


# / (GET) : Project List Page
# / (POST) : Project ADD
# /<PID> (GET) : 특정 프로젝트 정보
# /<PID> (POST) : 특정 프로젝트 정보 입력

@blueprint.route("/test")
# @login_required
def ttt():
    if current_user == None:
        return current_user.username
    else:
        return "....."

# TODO 서영태 : Pagination 적용 (MUST)
@blueprint.route("/")
@login_required
def projects():
    query = request.args.get('project')
    if query:

        projects = Project.query.filter(Project.name.like(unicode('%' + query + '%')))