====== Turbo Gears ====== tg-admin quickstart jmeno projektu: foto [[TurboGearsToolbox| Turbo Gears Toolbox]] ====== SQLite ====== sqlite3 devdata.sqlite CREATE TABLE fotografie ( id INTEGER PRIMARY KEY, nazev TEXT, soubor TEXT ); INSERT INTO "fotografie" VALUES(1,'Acko','aaa.txt'); Některé příkazy sqlite3 .help .databases .tables .schema fotografie .dump fotografie .explain on select * from fotografie; .mode list .mode html .mode insert .headers on .explain on .quit ======= První verze, adresář foto/foto ====== ==== 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 import pkg_resources try: pkg_resources.require("SQLObject>=0.8,<=0.10.0") except pkg_resources.DistributionNotFound: import sys print >> sys.stderr, """You are required to install SQLObject but appear not to have done so. Please run your projects setup.py or run `easy_install SQLObject`. """ sys.exit(1) import logging log = logging.getLogger("foto.controllers") class Root(controllers.RootController): @expose(template="foto.templates.welcome") def index(self): import time # log.debug("Happy TurboGears Controller Responding For Duty") flash("Your application is now running") return dict(now=time.ctime()) @expose(template="foto.templates.pokus") def pokus(self): import time log.debug("*** Nekdo navstivil fologalerii ***") flash("Fotografie") return dict(current_time=time.ctime()) ==== Soubor template/pokus.kid ==== Fotografie
tento text bude nahrazen hodnou promenne current_time
======= 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 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 ===== Fotografie - uvod
tento text bude nahrazen hodnou promenne current_time
Obsah
Editace tabulky
==== Soubor template/obsah.kid ==== Fotogalerie - obsah

Fotogalerie

Nazev Soubor Obrazek
${obrazek.nazev} ${obrazek.soubor}
Editace tabulky
==== Čá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; }