Skip to content

Commit

Permalink
Project
Browse files Browse the repository at this point in the history
- Mural completo!
  • Loading branch information
Kaique Silva committed Nov 21, 2011
1 parent 8995787 commit 1b12d4e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
sessions/*
errors/*
uploads/*
databases/*
17 changes: 13 additions & 4 deletions controllers/wall.py
Expand Up @@ -3,13 +3,22 @@
import tools

def index():
args = request.args
table = tools.Table(db, 'wall')
wall = table.get_contents()
#Pagination
limit = 10
count_articles = 0
wall = table.get_contents([0, limit])
numeration = tools.Pagination().get_numeration(wall['count'], limit)

if args:
index = int(args[0])
start = limit*index-limit
end = limit*index
wall = table.get_contents([start, end])

return {'wall': wall, 'limit': limit, 'count_articles': count_articles}
return {'wall': wall,
'limit': limit,
'numeration': numeration,
'args': args}

def article():
args = request.args
Expand Down
52 changes: 42 additions & 10 deletions modules/tools.py
Expand Up @@ -11,18 +11,22 @@ def __init__(self, db='', tablename=''):
'wall': db.wall
}

def get_contents(self):
def get_contents(self, limit=[]):
if self.table_name and self.db:
db = self.db

if self.table_name in self.tables:
table = self.tables['wall']

count = db(table.id > 0).count()
selection = db(table.id > 0).select(orderby=~table.created_on)

if selection and count:
return {'selection': selection, 'count': count}
if not limit:
selection = db(table.id > 0).select(orderby=~table.created_on)
elif limit and len(limit) == 2:
selection = db(table.id > 0).select(orderby=~table.created_on, limitby=(limit[0], limit[1]))
else:
return False

return {'selection': selection, 'count': count}
else:
return False

Expand All @@ -38,9 +42,37 @@ def get_article(self, id=0):
return False

class Pagination(object):
def get_numeration(self):
def get_numeration(self, total_articles=0, limit_articles=0):
'''
>>> Pagination().get_numeration(20, 10)
2
>>> Pagination().get_numeration(20, 0)
False
>>> Pagination().get_numeration(10, 20)
1
>>> Pagination().get_numeration(27, 10)
3
'''
total = total_articles
limit = limit_articles

if total > 0 and limit > 0:
if total/limit == 0:
return (total/limit)+1
elif total%limit > 0:
return (total/limit)+1
else:
return (total/limit)
else:
return False
def skeleton():
pass

if __name__ == "__main__":
import doctest
doctest.testmod()


def _test():
import doctest
doctest.testmod()


if __name__ == '__main__':
_test()
22 changes: 22 additions & 0 deletions static/css/base.css
Expand Up @@ -775,4 +775,26 @@ section.article-profile div.inner span.article-date{
margin: 18px 0 0;
bottom: 0;
float: right;
}

div.pagination span{
float: left;
}

div.pagination span.index-numbers ul{
padding: 0 5px 0;
margin: 0;
}

div.pagination span.index-numbers ul li{
padding: 0 5px 0;
margin: 0 2px 0 0;
list-style: none;
float: left;
border: 1px solid gray;
}

div.pagination span.index-numbers ul li.marked{
background: #ccc;
text-decoration: underline;
}
30 changes: 20 additions & 10 deletions views/wall/index.html
Expand Up @@ -10,8 +10,6 @@ <h1>Mural</h1>
{{if wall:}}
<section>
{{for article in wall['selection']:}}
{{count_articles += 1}}
{{if count_articles <= limit:}}
<article class="wall">
<header>
<div class="inner">
Expand All @@ -36,25 +34,37 @@ <h4 style="float: left">
</div>
</article>
<hr />
{{pass}}
{{pass}}
</section>
{{pass}}

<footer>
<div class="wall-inner-foot">
<div class="pagination">
<span class="previous">
<a href="#previous">Anterior</a>
</span>
<span>Ir para a pagina:</span>
<span class="index-numbers">
<ul>
<li><a href="#">1</a></li>
{{for n in range(numeration+1):}}
{{if n > 0:}}
{{if not args and n == 1:}}
<li class="marked">
{{elif args:}}
{{if int(args[0]) == n:}}
<li class="marked">
{{else:}}
<li>
{{pass}}
{{else:}}
<li>
{{pass}}
<a href="{{=URL(c='wall', f='index', args=[n])}}">
{{=n}}
</a>
</li>
{{pass}}
{{pass}}
</ul>
</span>
<span class="next">
<a href="#next">Proximo</a>
</span>
</div>
</div>
</footer>

0 comments on commit 1b12d4e

Please sign in to comment.