diff --git a/fotokiste/dev.cfg b/fotokiste/dev.cfg index 3ae6213..de52518 100644 --- a/fotokiste/dev.cfg +++ b/fotokiste/dev.cfg @@ -27,7 +27,7 @@ sqlobject.dburi="sqlite://%(current_dir_uri)s/devdata.sqlite" # SERVER # Some server parameters that you may want to tweak -# server.socket_port=8080 +server.socket_port=80 # Enable the debug output at the end on pages. # log_debug_info_filter.on = False diff --git a/fotokiste/fotokiste/controllers.py b/fotokiste/fotokiste/controllers.py index dd829e6..01251a7 100644 --- a/fotokiste/fotokiste/controllers.py +++ b/fotokiste/fotokiste/controllers.py @@ -7,7 +7,7 @@ from turbogears import controllers, expose, flash, redirect # log = logging.getLogger("fotokiste.controllers") -class DummyPicture(object): +class SamplePicture(object): title = "leer" url = "nichts" @@ -17,19 +17,23 @@ import tempfile import cherrypy import re import datetime +import random -IMAGE_STORE = os.path.join(tempfile.gettempdir(), "fotokiste.jpg") -VIDEO_URL = "http://webcam.glasmensch.org/?action=stream" -SNAPSHOT_URL = "http://webcam.glasmensch.org/?action=snapshot" +IMAGE_GALLERY_PATH = os.path.join(os.getcwd(), 'fotokiste', 'static', 'gallery') +IMAGE_SUFFIX = ".jpg" +IMAGE_STORE = os.path.join(tempfile.gettempdir(), "fotokiste" + IMAGE_SUFFIX) +GALLERY_NUM = 12 +VIDEO_URL = "http://fotokiste:8081/?action=stream" +SNAPSHOT_URL = "http://fotokiste:8081/?action=snapshot" ALLOWED_MAILADDRESS_CHARACTERS = "\w._%@-" ALLOWED_MAILTEXT_CHARACTERS = "\w@_\-\.\s\n\#\(\)\[\]\{\}\|\>\<\,\+/\'\"\?\!\:=%\$^&\*" MAIL_ADDRESS_REGEX = r"^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,6}$" # TODO: this path is relative - to be fixed! -MAIL_SIGNATURE_FILE = "mail_signature.txt" +MAIL_SIGNATURE_FILE = os.path.join(os.getcwd(), "mail_signature.txt") MAIL_FROM_ADDRESS = '"Fusion-Fotokiste" ' MAIL_SUBJECT = "Ein überwachungskritisches Foto von der Fusion!" -MAIL_ATTACHMENT_FILENAME = "fusion.jpeg" -SMTP_HOST = "192.168.1.31" +MAIL_ATTACHMENT_FILENAME = "fusion" + IMAGE_SUFFIX +SMTP_HOST = "localhost" SMTP_PORT = "25" MAIL_MAX_LENGTH = 5000 ERRORS_MAX_LENGTH = 25 @@ -65,6 +69,33 @@ def check_mailaddress(address): else: return False +def store_picture(): + if not os.path.isdir(IMAGE_GALLERY_PATH): + os.mkdir(IMAGE_GALLERY_PATH) + import shutil + timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + filename = os.path.join(IMAGE_GALLERY_PATH, "%s%s" % (timestamp, IMAGE_SUFFIX)) + shutil.copy(IMAGE_STORE, filename) + +def get_random_pictures(): + default = [""] * GALLERY_NUM + try: + result = [] + all_files = [fname for fname in os.listdir(IMAGE_GALLERY_PATH) + if os.path.isfile(os.path.join(IMAGE_GALLERY_PATH, fname)) + and fname.endswith(IMAGE_SUFFIX)] + if not all_files: + return default + all_files.sort() + print all_files + # the last five pictures + result.extend(all_files[-5:]) + while len(result) < GALLERY_NUM: + result.append(all_files[random.randint(0, len(all_files)-1)]) + return result + except OSError: + return default + def send_mail(address, text): import smtplib import StringIO @@ -125,11 +156,12 @@ class Root(controllers.RootController): def index(self, **kargs): # TODO: this should generate a selection of random pictures + pic_names = get_random_pictures() gallery = [] - for i in range(22): - obj = DummyPicture() - obj.title = "test%d" % i - obj.url = "URL: %d" % i + for i in range(len(pic_names)): + obj = SamplePicture() + obj.title = "pic%d" % (i+1) + obj.url = "%s" % pic_names[i] gallery.append(obj) # remove old picture @@ -146,10 +178,13 @@ class Root(controllers.RootController): @expose(template="fotokiste.templates.mailtext") - def mailtext(self, mailaddress="", mailtext="", already_stored="no", **kargs): + def mailtext(self, mailaddress="", mailtext="", already_captured="no", already_stored="no", **kargs): # store the picture if necessary - if already_stored != "yes": + if already_captured != "yes": urllib.urlretrieve(SNAPSHOT_URL, IMAGE_STORE) + already_captured = "no" + if already_stored != "yes": + already_stored = "no" # filter input mailaddress = filter_mailaddress(mailaddress) mailtext = filter_mailtext(mailtext) @@ -165,14 +200,17 @@ class Root(controllers.RootController): @expose(template="fotokiste.templates.senden") - def senden(self, mailaddress="", mailtext="", senden=None): + def senden(self, mailaddress="", mailtext="", already_stored="no", senden=None): # filter input mailaddress = filter_mailaddress(mailaddress) mailtext = filter_mailtext(mailtext) + if already_stored != "yes": + already_stored = "no" return_dict = merged_dicts({ "mailaddress": mailaddress, "mailtext": mailtext, + "already_stored": already_stored, }, DEFAULT_DICT) # check for a valid mail address and redirect if necessary if not check_mailaddress(mailaddress): @@ -183,6 +221,8 @@ class Root(controllers.RootController): redirect("mailtext", return_dict) else: # send the mail + if already_stored != "yes": + store_picture() if send_mail(mailaddress, mailtext): return return_dict else: diff --git a/fotokiste/fotokiste/static/css/1024optimized.css b/fotokiste/fotokiste/static/css/1024optimized.css index e4a59b8..4da02fc 100644 --- a/fotokiste/fotokiste/static/css/1024optimized.css +++ b/fotokiste/fotokiste/static/css/1024optimized.css @@ -5,7 +5,17 @@ body { text-align: center; font: 1em Arial, Helvetica, sans-serif; } - + +input.button { + margin: 5px 20px 5px 20px; + text-align: center; + font-size: large; +} + +label { + font-size: large; +} + #header { /** background: url(../static/images/header.jpg) top left no-repeat; position: relative; @@ -56,13 +66,8 @@ body { * fails to show up sometimes */ #mail_pic img { - width: 320px; - height: 240px; -} - -#live_pic img { - width: 320px; - height: 240px; + width: 350px; + height: 260px; } /* Styles for the text area */ @@ -70,7 +75,7 @@ body { position: relative; margin: 15px auto 15px auto; padding: 0; - width: 90%; + width: 95%; text-align: left; line-height: 1.25em; } @@ -110,12 +115,16 @@ h2 { padding: 20px; } - -#vkb { - margin: 0 auto 0 15%; -} - - + +#vkb { + margin: 0 auto 0 15%; +} + +img.gallery { + width: 100px; + height: 60px; + } + /* Style for the footer */ #footer { padding: 2px; diff --git a/fotokiste/fotokiste/static/javascript/mjp-streamer.js b/fotokiste/fotokiste/static/javascript/mjp-streamer.js new file mode 100644 index 0000000..3b50abe --- /dev/null +++ b/fotokiste/fotokiste/static/javascript/mjp-streamer.js @@ -0,0 +1,38 @@ +/* Copyright (C) 2007 Richard Atterer, richard©atterer.net + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2. See the file + COPYING for details. */ + +var imageNr = 0; // Serial number of current image +var finished = new Array(); // References to img objects which have finished downloading +var paused = false; + +function createImageLayer() { + var img = new Image(); + img.style.position = "absolute"; + img.style.zIndex = -1; + img.style.width = "400px"; + img.style.height = "320px"; + img.onload = imageOnload; + img.onclick = imageOnclick; + img.src = "http://fotokiste:8081/?action=snapshot&n=" + (++imageNr); + var webcam = document.getElementById("live_pic"); + webcam.insertBefore(img, webcam.firstChild); +} + +// Two layers are always present (except at the very beginning), to avoid flicker +function imageOnload() { + this.style.zIndex = imageNr; // Image finished, bring to front! + while (1 < finished.length) { + var del = finished.shift(); // Delete old image(s) from document + del.parentNode.removeChild(del); + } + finished.push(this); + if (!paused) createImageLayer(); +} + +function imageOnclick() { // Clicking on the image will pause the stream + paused = !paused; + if (!paused) createImageLayer(); +} + diff --git a/fotokiste/fotokiste/templates/login.kid b/fotokiste/fotokiste/templates/login.kid index 4fd6755..8698362 100644 --- a/fotokiste/fotokiste/templates/login.kid +++ b/fotokiste/fotokiste/templates/login.kid @@ -96,7 +96,7 @@ - + diff --git a/fotokiste/fotokiste/templates/mailtext.kid b/fotokiste/fotokiste/templates/mailtext.kid index cb834df..26e4b08 100644 --- a/fotokiste/fotokiste/templates/mailtext.kid +++ b/fotokiste/fotokiste/templates/mailtext.kid @@ -11,31 +11,37 @@ - + + +
+
+
+ +
+
-
- -
- +
+

- +
+
-
- - +
+ +
+
-