Skip to content

Instantly share code, notes, and snippets.

@kimdwkimdw
Forked from SsonHJ/base.js
Last active August 29, 2015 14:05
Show Gist options
  • Save kimdwkimdw/54d9ca0b741a6cabc37f to your computer and use it in GitHub Desktop.
Save kimdwkimdw/54d9ca0b741a6cabc37f to your computer and use it in GitHub Desktop.

Revisions

  1. kimdwkimdw renamed this gist Aug 20, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion a.html → home.html
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,5 @@
    로 접근 가능하도록..
    -->
    -->
    <div class="well" id="article_{{ article.id }}" article_id="{{ article.id }}">
  2. kimdwkimdw revised this gist Aug 20, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions a.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <!-- DOM을 만들때 항상 article_id 를 넣어준다.
    $(".well:last").attr("article_id")
    로 접근 가능하도록..
    -->
  3. kimdwkimdw revised this gist Aug 20, 2014. 1 changed file with 0 additions and 30 deletions.
    30 changes: 0 additions & 30 deletions base.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,3 @@
    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;
    @@ -67,13 +44,6 @@ $(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);
  4. @SsonHJ SsonHJ created this gist Aug 18, 2014.
    82 changes: 82 additions & 0 deletions base.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    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;
    });
    });
    28 changes: 28 additions & 0 deletions views.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    @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())