Created
August 18, 2014 13:24
-
-
Save SsonHJ/c7478fc778a7fcce968f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeTo(time){ | |
var times = new Date(); | |
var resultString; | |
var millisec; | |
millisec = (new Date(time)).getTime(); | |
times.setTime(millisec); | |
var month = times.getUTCMonth() + 1; | |
if(month < 10){ | |
month = "0"+ month; | |
} | |
var date = times.getUTCDate(); | |
if(date < 10){ | |
date = "0" + date; | |
} | |
resultString = | |
times.getYear()+1900 + "-" + month + "-" + date + " " | |
+times.getUTCHours() + ":" + times.getMinutes() + ":" + times.getSeconds(); | |
return resultString; | |
} | |
function getArticleAfterArticle(article_id) | |
{ | |
var EndArticle = false; | |
$.ajax({ | |
url: "/more", | |
dataType: 'JSON', | |
data: { | |
last_article_id : article_id | |
}, | |
success: function(data){ | |
if(data.count == 0){ | |
alert("마지막글입니다"); | |
$("#morebtn").hide(); | |
EndArticle =true; | |
}else{ | |
for (var article_idx in data.article_list) | |
{ | |
article = data.article_list[article_idx] | |
string = "<div class='well' id='article_"+ article.id | |
+"'><h1><a href='/article/detail/"+ article.id +"'>" | |
+ article.title +"</a></h1><h3>"+ article.author +"</h3><h6>" | |
+ timeTo(article.date_created) | |
+"</h6><p> " | |
+ article.content +" </p> </div>"; | |
$(string).insertAfter($(".well:last")) | |
} | |
} | |
}, | |
error: function(status){ | |
string = "<div class='well' id='article_"+ data.id | |
+"'><h1>에러가 발생했습니다..</h1></div>"; | |
$("#results").append(string); | |
} | |
}); | |
return true; | |
} | |
$(document).ready(function() { | |
var number = 0; | |
var string; | |
$.ajax({ | |
url: "/rows", | |
dataType: 'JSON', | |
success: function(data){ | |
number = data.rows - 4; | |
} | |
}); | |
$('#load_more_button').bind('click', function() { | |
var article_id = $(".well:last").attr("article_id"); | |
getArticleAfterArticle(article_id); | |
return false; | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/', methods=['GET']) | |
def article_list(): | |
context = {} | |
rows = max(Article.query.count() - 5, 5) | |
context['article_list'] = Article.query.order_by( | |
desc(Article.date_created)).limit(rows) | |
return render_template('home.html', context=context, active_tab='timeline') | |
@app.route('/more') | |
def article_more(): | |
last_article_id = request.args.get('last_article_id', 0, type=int) | |
article_list = Article.query.filter(Article.id < last_article_id).order_by( | |
desc(Article.date_created)).limit(5) | |
article_result = [] | |
for article in article_list: | |
article_result.append({'id': article.id, | |
'title': article.title, | |
'content': article.content, | |
'author': article.author, | |
'category': article.category, | |
'date_created': article.date_created, | |
}) | |
return jsonify(article_list=article_result, count=article_list.count()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment