Druhá verze

Data

sqlite3 devdata.sqlite 
CREATE TABLE fotografie (
    id INTEGER PRIMARY KEY,
    nazev TEXT,
    soubor TEXT
);
 
INSERT INTO "fotografie" VALUES(1,'Kvetouci strom','0053.jpg');
INSERT INTO "fotografie" VALUES(2,'Hlemyzd','4635.jpg');
INSERT INTO "fotografie" VALUES(3,'Kobylka','1940.jpg');
INSERT INTO "fotografie" VALUES(4,'Safran a vcela','3515.jpg');
INSERT INTO "fotografie" VALUES(5,'Kvetina','4174.jpg');
INSERT INTO "fotografie" VALUES(6,'Brambora','4182.jpg');

Přenést obrázky z http://kmlinux/~culik/foto do adresáře static

Soubor model.py

from datetime import datetime
from turbogears.database import PackageHub
from sqlobject import *
from turbogears import identity
 
hub = PackageHub("foto")
__connection__ = hub
 
class Fotografie(SQLObject):
    nazev = StringCol()
    soubor = StringCol()

Soubor controllers.py

from turbogears import controllers, expose, flash
 
from foto import model
from turbogears.toolbox.catwalk import CatWalk
 
from model import Fotografie
 
import logging
log = logging.getLogger("foto.controllers")
 
class Root(controllers.RootController):
 
    catwalk = CatWalk(model)
 
    @expose(template="foto.templates.uvod")
    def index(self):
        import time
        log.debug("*** Nekdo navstivil fologalerii ***")
        flash("Fotografie, verze 01")
        return dict(current_time=time.ctime())
 
    @expose(template="foto.templates.obsah")
    def obsah(self):
        return dict (snimky=Fotografie.select ())

Soubor template/uvod.kid

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
<title>Fotografie - uvod</title>
</head>
<body>
 
  <div id="sidebar">
    <h2>Plovoucí text </h2>
    Nejaky text <br/>
    Odkaz na <a href="http://www.turbogears.org">TurboGears website</a>
  </div>
 
  <div class="notice">
     <span py:replace="current_time"> tento text bude nahrazen hodnou promenne current_time</span>
  </div>
 
  <div class="commands">
      <a href="obsah">Obsah</a>
  </div>
 
  <div class="tools">
      <a href="catwalk">Editace tabulky</a>
  </div>
 
</body>
</html>

Soubor template/obsah.kid

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"  py:extends="'master.kid'">
 
<head>
   <meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
   <title> Fotogalerie - obsah </title>
</head>
 
<body>
 
   <H2> Fotogalerie </H2>
 
   <TABLE WIDTH="100%" border="1">
 
   <TH> Nazev </TH> 
   <TH> Soubor </TH> 
   <TH> Obrazek </TH> 
 
   <TR py:for="obrazek in snimky">
        <TD> ${obrazek.nazev} </TD>
        <TD> <A HREF='static/${obrazek.soubor}'> ${obrazek.soubor} </A> </TD>
        <TD> <IMG SRC='static/${obrazek.soubor}' HEIGHT="100"/> </TD>
   </TR> 
 
   </TABLE> 
 
   <div class="tools">
      <a href="catwalk">Editace tabulky</a>
   </div>
 
</body>
</html>

Část souboru static/css/style.css

.commands {
  margin: 0.5em auto 0.5em auto;
  padding: 15px 10px 15px 55px;
  width: 450px;
  background: #ff7 ;
  border: 1px solid #cce;
}
 
.tools {
  margin: 0.5em auto 0.5em auto;
  padding: 15px 10px 15px 55px;
  width: 450px;
  background: #f77 ;
  border: 1px solid #cce;
}

Spuštění aplikace

./start-foto.py

http://localhost:8080

 
turbogears2.txt · Last modified: 2008/04/17 14:13 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki