summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--cgi-bin/config.py1
-rw-r--r--cgi-bin/display.py42
-rwxr-xr-xcgi-bin/index.py14
-rw-r--r--cgi-bin/link.py17
-rw-r--r--style/style.css51
6 files changed, 107 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 741ff7f..cda0f00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.kate-swp
*.pyc
+img
diff --git a/cgi-bin/config.py b/cgi-bin/config.py
index 9c1426f..607ddec 100644
--- a/cgi-bin/config.py
+++ b/cgi-bin/config.py
@@ -1,2 +1,3 @@
datadir='img/'
special = ('index', 'latest')
+pagination = 30
diff --git a/cgi-bin/display.py b/cgi-bin/display.py
index 18f1cf8..b94caa2 100644
--- a/cgi-bin/display.py
+++ b/cgi-bin/display.py
@@ -1,11 +1,13 @@
# -*- coding: utf8 -*-
import link, os, config
+from datetime import datetime
class Body:
- def __init__(self, site):
+ def __init__(self, site, page):
self.site=site
self.a=link.Link(site)
self.datadir=config.datadir
+ self.part=page
def menu(self):
print (self.a.link(self.a.delta('+w'), '« týden'))
@@ -28,34 +30,58 @@ class Body:
print ("</header>")
print ("<article id=\"prev\">")
print (self.a.imglink(self.a.delta('+m'),'prev'))
+ print ("<p>"+self.a.timestamp(self.a.delta('+m'))+"</p>")
print ("</article>")
print ("<article id=\"now\">")
print (self.a.imglink(self.a.img, 'now'))
+ print ("<p>"+self.a.timestamp(self.a.img)+"</p>")
print ("</article>")
print ("<article id=\"next\">")
print (self.a.imglink(self.a.delta('-m'), 'next'))
+ print ("<p>"+self.a.timestamp(self.a.delta('-m'))+"</p>")
print ("</article>")
print ("<footer>")
print ("<a href=\"?f=index\" title=\"všechny fotky\">vše</a>")
print ("</footer>")
- def index(self):
+ def index(self, page):
index=os.listdir(os.path.realpath(self.datadir))
remove=['notfound.jpeg', 'latest.jpeg']
for r in remove:
index.remove(r)
- print ("<header>")
+ index.sort()
+ count=len(index)
+ pnum=count/config.pagination+1
+ if int(page) > int(pnum):
+ page=pnum-1
+ #print pnum
+ rngend=(int(page)+1)*config.pagination-1
+ #print rngend
+ rngstart=rngend-(config.pagination-1)
+ #print rngstart
+ print ("<header>")
print ("<h1>Hnízdo - Index</h1>")
print ("</header>")
+ print ("<nav>")
+ a = 0
+ while a < pnum:
+ print("<a href=\"?f=index&p="+str(a)+"\">"+str(a+1)+"</a>")
+ a = a + 1
+ print ("</nav>")
print ("<ul>")
- for f in index:
- print("<li>")
- print(self.a.link(f, f[:12]))
+ f = rngstart
+ while f <= rngend and f <= count-1:
+ #print f
+ print("<li>")
+ print(self.a.imglink(index[f], ""))
+ print("<p>"+self.a.link(index[f], self.a.timestamp(index[f]))+"</p>")
print("</li>")
- print ("</ul>")
+ f = f + 1
+ print ("</ul>")
+ print ("<footer><a href=\"?f=latest\">úvod</a></footer>")
def page(self):
if self.site == "index":
- self.index()
+ self.index(self.part)
else:
self.articles()
diff --git a/cgi-bin/index.py b/cgi-bin/index.py
index 20480a4..a2080ee 100755
--- a/cgi-bin/index.py
+++ b/cgi-bin/index.py
@@ -10,6 +10,7 @@ cgitb.enable()
query = cgi.FieldStorage()
param = query.getvalue("f")
+page = query.getvalue("p")
print ("<!DOCTYPE html>")
print ("<html>")
@@ -20,12 +21,17 @@ print ("<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/style.css\">"
print ("</head>")
print ("<body>")
-if param in config.special:
- body=display.Body(param)
+if param == "latest":
+ body=display.Body("latest", "")
+if param == "index":
+ if re.match("^[0-9]+$", str(page)):
+ body=display.Body("index", str(page))
+ else:
+ body=display.Body("index", "0")
elif re.match("^20[0-9]{2}(0[0-9]|1[1-2])([0-2][0-9]|3[0-1])(0[0-9]|1[0-9]|2[0-3])([0-5][0-9])$", str(param)):
- body=display.Body(param)
+ body=display.Body(param, "")
else:
- body=display.Body("latest")
+ body=display.Body("latest", "")
body.page()
diff --git a/cgi-bin/link.py b/cgi-bin/link.py
index b0e6560..6075ea2 100644
--- a/cgi-bin/link.py
+++ b/cgi-bin/link.py
@@ -22,11 +22,22 @@ class Link:
else:
return os.path.relpath(self.src_datadir + "notfound.jpeg")
- def imglink(self, target, order):
+ def imglink(self, target, order=""):
+ if order:
+ cssclass="class=\""+order+"\""
+ else:
+ cssclass=""
if self.detect(target):
- return "<a href=\""+self.href(target)+"\"><img src=\""+self.src(target)+"\" class=\""+order+"\"/></a>"
+ return "<a href=\""+self.href(target)+"\"><img src=\""+self.src(target)+"\""+cssclass+"/></a>"
else:
- return "<img src=\""+self.src(target)+"\" class=\""+order+"\"/>"
+ return "<img src=\""+self.src(target)+cssclass+"\"/>"
+
+ def timestamp(self, date):
+ if self.detect(date):
+ date=datetime.datetime.strftime(datetime.datetime.strptime(date[:12], "%Y%m%d%H%M"), "%Y-%m-%d %H:%M")
+ return date
+ else:
+ return ""
def href(self, target):
##print os.path.realpath(root+target)
diff --git a/style/style.css b/style/style.css
index c9e9178..32cc34f 100644
--- a/style/style.css
+++ b/style/style.css
@@ -1,14 +1,25 @@
+html {
+ padding: 0;
+ background: #fffeff;
+
+}
+
body {
width: 920px;
- margin: auto auto;
+ padding-top: 2em;
+ margin: 1em auto 0 auto;
font-family: Georgia, serif;
- background: url(background.png) left top no-repeat #fffedf;
+ background: url(background.png) left top no-repeat #fffedf;
+ border: 3px double #f60;
}
-header {}
+header {
+ border-bottom: 1px dotted #f60;
+}
h1 {
text-align: center;
+ color: maroon;
}
a, a:link, a:hover, a:visited {
@@ -18,6 +29,7 @@ a, a:link, a:hover, a:visited {
nav {
text-align: center;
+ margin-bottom: 1em;
}
nav a, nav span, footer a {
@@ -40,6 +52,7 @@ nav a:hover, footer a:hover {
}
article {
+ margin-top: 2em;
float: left;
text-align: center;
}
@@ -52,7 +65,8 @@ article img {
article#prev, article#next {
width: 180px;
- margin: 0 2.5%
+ margin: 2em 2.5%;
+ padding-top: 10%;
}
article#now {
@@ -68,4 +82,33 @@ footer {
clear: both;
text-align: center;
padding: 1em;
+ border-top: 1px dotted #ff6600;
+}
+
+ul {
+ padding: 1em;
+ column-count: 5;
+ text-align: center;
+}
+
+ul li {
+ list-style: none;
+ margin-bottom: 1em;
+}
+
+ul li a {
+ display: inline-block;
+ background: #ff6600;
+ padding: 2px 5px;
+ border: 1px solid #000;
+ border-radius: 4px;
+}
+
+ul li a:hover {
+ background: #fffedf;
+}
+
+ul li img {
+ width: 133px;
+ height: 100px;
}