fixed display of the stream
completed the basic workflow
This commit is contained in:
parent
2ed79c7b26
commit
82fc5c90e9
6 changed files with 148 additions and 48 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import turbogears as tg
|
import turbogears as tg
|
||||||
from turbogears import controllers, expose, flash
|
from turbogears import controllers, expose, flash, redirect
|
||||||
# from fotokiste import model
|
# from fotokiste import model
|
||||||
# import logging
|
# import logging
|
||||||
# log = logging.getLogger("fotokiste.controllers")
|
# log = logging.getLogger("fotokiste.controllers")
|
||||||
|
@ -10,8 +12,90 @@ class DummyPicture(object):
|
||||||
url = "nichts"
|
url = "nichts"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import urllib
|
||||||
|
import tempfile
|
||||||
|
import cherrypy
|
||||||
|
import re
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
IMAGE_STORE = os.path.join(tempfile.gettempdir(), "fotokiste.jpg")
|
||||||
|
VIDEO_URL = "http://localhost:8081/?action=stream"
|
||||||
|
SNAPSHOT_URL = "http://localhost:8081/?action=snapshot"
|
||||||
|
ALLOWED_MAILADDRESS_CHARACTERS = "\w._%@-"
|
||||||
|
ALLOWED_MAILTEXT_CHARACTERS = "\w@_\-\.\s\n\#\(\)\[\]\{\}\|\>\<\,\+/\'\"\?\!\:=%\$^&\*"
|
||||||
|
MAIL_SIGNATURE_FILE = "mail_signature.txt"
|
||||||
|
MAIL_FROM_ADDRESS = "fotokiste@glasmensch.org"
|
||||||
|
MAIL_SUBJECT = "Ein Foto von der Fusion!"
|
||||||
|
SMTP_HOST = "localhost"
|
||||||
|
SMTP_PORT = "25"
|
||||||
|
MAIL_MAX_LENGTH = 5000
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_DICT = { "video_url": VIDEO_URL }
|
||||||
|
|
||||||
|
def debug(message):
|
||||||
|
print "%s: %s" % (datetime.datetime.now().isoformat(), message)
|
||||||
|
|
||||||
|
def merged_dicts(dict_a, dict_b):
|
||||||
|
return dict(dict_a.items() + dict_b.items())
|
||||||
|
|
||||||
|
def filter_mailaddress(address):
|
||||||
|
return re.sub("[^%s]" % ALLOWED_MAILADDRESS_CHARACTERS, "", address)
|
||||||
|
|
||||||
|
def filter_mailtext(text):
|
||||||
|
filtered = re.sub("[^%s]" % ALLOWED_MAILTEXT_CHARACTERS, "", text)
|
||||||
|
if len(filtered) > MAIL_MAX_LENGTH:
|
||||||
|
return filtered[:MAIL_MAX_LENGTH-1]
|
||||||
|
else:
|
||||||
|
return filtered
|
||||||
|
|
||||||
|
def check_mailaddress(address):
|
||||||
|
if re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,6}$", address):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def send_mail(address, text):
|
||||||
|
import smtplib
|
||||||
|
import MimeWriter
|
||||||
|
import StringIO
|
||||||
|
import base64
|
||||||
|
# read the additional mail parts (signature and picture)
|
||||||
|
try:
|
||||||
|
signature = file(MAIL_SIGNATURE_FILE).read()
|
||||||
|
except IOError, msg:
|
||||||
|
debug("failed to open the signature file (%s): %s" % \
|
||||||
|
(MAIL_SIGNATURE_FILE, msg))
|
||||||
|
try:
|
||||||
|
picture = StringIO.StringIO(file(IMAGE_STORE).read())
|
||||||
|
except IOError, msg:
|
||||||
|
debug("failed to open the image file (%s): %s" % \
|
||||||
|
(IMAGE_STORE, msg))
|
||||||
|
|
||||||
|
# prepare the message
|
||||||
|
message = StringIO.StringIO()
|
||||||
|
writer = MimeWriter.MimeWriter(message)
|
||||||
|
writer.addheader("Subject", MAIL_SUBJECT)
|
||||||
|
# the picture should be shown inline by the mail clients
|
||||||
|
writer.addheader("Content-Disposition", "inline")
|
||||||
|
writer.startmultipartbody('mixed')
|
||||||
|
# start off with a text/plain part
|
||||||
|
part = writer.nextpart()
|
||||||
|
body = part.startbody('text/plain')
|
||||||
|
body.write(text + signature)
|
||||||
|
# now add an attachment
|
||||||
|
part = writer.nextpart()
|
||||||
|
# the 'Content-Disposition' is necessary for displaying the image inline
|
||||||
|
part.addheader('Content-Disposition', 'attachment; filename="fusion.jpeg"')
|
||||||
|
part.addheader('Content-Transfer-Encoding', 'base64')
|
||||||
|
body = part.startbody('image/jpeg')
|
||||||
|
base64.encode(picture, body)
|
||||||
|
# finish off
|
||||||
|
writer.lastpart()
|
||||||
|
|
||||||
|
con = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
|
||||||
|
con.sendmail(address, MAIL_FROM_ADDRESS, message.getvalue())
|
||||||
|
|
||||||
IMAGE_STORE = os.tempnam()
|
|
||||||
|
|
||||||
class Root(controllers.RootController):
|
class Root(controllers.RootController):
|
||||||
|
|
||||||
|
@ -31,40 +115,59 @@ class Root(controllers.RootController):
|
||||||
if os.path.isfile(IMAGE_STORE):
|
if os.path.isfile(IMAGE_STORE):
|
||||||
os.unlink(IMAGE_STORE)
|
os.unlink(IMAGE_STORE)
|
||||||
|
|
||||||
return { "gallery": gallery }
|
return merged_dicts({ "gallery": gallery }, DEFAULT_DICT)
|
||||||
|
|
||||||
|
|
||||||
@expose(template="fotokiste.templates.ausloeser")
|
@expose(template="fotokiste.templates.ausloeser")
|
||||||
def ausloeser(self, **kargs):
|
def ausloeser(self, **kargs):
|
||||||
flash("Das Bild wird in 5 Sekunden aufgenommen!")
|
flash("Das Bild wird in 5 Sekunden aufgenommen!")
|
||||||
return {}
|
return merged_dicts({}, DEFAULT_DICT)
|
||||||
|
|
||||||
@expose(template="fotokiste.templates.mailtext")
|
@expose(template="fotokiste.templates.mailtext")
|
||||||
def mailtext(self, mailtext=None, already_stored="no", **kargs):
|
def mailtext(self, mailaddress="", mailtext="", already_stored="no", **kargs):
|
||||||
# mailtext filtern
|
# store the picture if necessary
|
||||||
|
if already_stored != "yes":
|
||||||
|
urllib.urlretrieve(SNAPSHOT_URL, IMAGE_STORE)
|
||||||
|
# filter input
|
||||||
|
mailaddress = filter_mailaddress(mailaddress)
|
||||||
|
mailtext = filter_mailtext(mailtext)
|
||||||
|
|
||||||
# "already_stored" filtern
|
#if not check_mailaddress(mailaddress):
|
||||||
if already_stored != "no":
|
# turbogears.flash(
|
||||||
already_stored = "yes"
|
|
||||||
return {
|
|
||||||
"mailtext": mailtext,
|
|
||||||
"already_stored": already_stored,
|
|
||||||
}
|
|
||||||
|
|
||||||
@expose(template="fotokiste.templates.senden")
|
return merged_dicts({
|
||||||
def senden(self, mailaddress=None, mailtext=None, already_stored=False, **kargs):
|
|
||||||
# Bild speichern, falls "already_stored" falsch ist
|
|
||||||
# Mail versenden
|
|
||||||
|
|
||||||
# mailaddress filtern
|
|
||||||
# mailtext filtern
|
|
||||||
|
|
||||||
# das Bild wurde gerade gespeichert
|
|
||||||
already_stored = "yes"
|
|
||||||
|
|
||||||
return {
|
|
||||||
"mailaddress": mailaddress,
|
"mailaddress": mailaddress,
|
||||||
"mailtext": mailtext,
|
"mailtext": mailtext,
|
||||||
"already_stored": already_stored,
|
"already_stored": already_stored,
|
||||||
}
|
}, DEFAULT_DICT)
|
||||||
|
|
||||||
|
@expose(template="fotokiste.templates.senden")
|
||||||
|
def senden(self, mailaddress="", mailtext="", senden=None):
|
||||||
|
# filter input
|
||||||
|
mailaddress = filter_mailaddress(mailaddress)
|
||||||
|
mailtext = filter_mailtext(mailtext)
|
||||||
|
|
||||||
|
return_dict = merged_dicts({
|
||||||
|
"mailaddress": mailaddress,
|
||||||
|
"mailtext": mailtext,
|
||||||
|
}, DEFAULT_DICT)
|
||||||
|
# check for a valid mail address and redirect if necessary
|
||||||
|
if not check_mailaddress(mailaddress):
|
||||||
|
if not mailaddress:
|
||||||
|
flash("Gib bitte eine Ziel-Mailadresse an!")
|
||||||
|
else:
|
||||||
|
flash("Die Mailadresse scheint nicht ungueltig zu sein.")
|
||||||
|
redirect("mailtext", return_dict)
|
||||||
|
else:
|
||||||
|
# Mail versenden
|
||||||
|
send_mail(mailaddress, mailtext)
|
||||||
|
return return_dict
|
||||||
|
|
||||||
|
@expose()
|
||||||
|
def get_current_shot(self):
|
||||||
|
if os.path.exists(IMAGE_STORE):
|
||||||
|
return cherrypy.lib.cptools.serveFile(IMAGE_STORE,
|
||||||
|
"image/jpeg")
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,19 @@ body {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* dimensions are necessary - otherwise the picture/video
|
||||||
|
* fails to show up sometimes
|
||||||
|
*/
|
||||||
|
#mail_pic img {
|
||||||
|
width: 320px;
|
||||||
|
height: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#live_pic img {
|
||||||
|
width: 320px;
|
||||||
|
height: 240px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Styles for the text area */
|
/* Styles for the text area */
|
||||||
#main_content {
|
#main_content {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -9,11 +9,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div id="shoot_pic">
|
<div id="live_pic"><img src="${video_url}"/></div>
|
||||||
<p><img width="300" height="384"
|
|
||||||
src="${tg.url('/static/images/platzhalter.jpg')}"
|
|
||||||
alt="shoot_pic" /></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -8,17 +8,13 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div id="mail_pic">
|
<div id="mail_pic"><img src="${tg.url('/get_current_shot')}"/></div>
|
||||||
<p><img width="200px" height="256px"
|
|
||||||
src="${tg.url('/static/images/platzhalter.jpg')}"
|
|
||||||
alt="Versende-Bild" /></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="mail_info">
|
<div id="mail_info">
|
||||||
<form action="${tg.url('/senden')}">
|
<form action="${tg.url('/senden')}">
|
||||||
<label for="mailaddress">An:</label>
|
<label for="mailaddress">An:</label>
|
||||||
<input type="textfield" id="mailaddress"
|
<input type="textfield" id="mailaddress"
|
||||||
name="mailaddress" size="30" />
|
name="mailaddress" value="${mailaddress}" size="30" />
|
||||||
<br/>
|
<br/>
|
||||||
<label for="mailtext">Text:</label>
|
<label for="mailtext">Text:</label>
|
||||||
<textarea name="mailtext" id="mailtext"
|
<textarea name="mailtext" id="mailtext"
|
||||||
|
|
|
@ -8,16 +8,12 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
<div id="mail_pic">
|
<div id="mail_pic"><img src="${tg.url('/get_current_shot')}"/></div>
|
||||||
<p><img width="300" height="384"
|
|
||||||
src="${tg.url('/static/images/platzhalter.jpg')}"
|
|
||||||
alt="versendetes Bild" /></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="mail_info">
|
<div id="mail_info">
|
||||||
<form action="${tg.url('/mailtext')}">
|
<form action="${tg.url('/mailtext')}">
|
||||||
<input type="hidden" name="mailtext" value="${mailtext}" />
|
<input type="hidden" name="mailtext" value="${mailtext}" />
|
||||||
<input type="hidden" name="already_stored" value="${already_stored}" />
|
<input type="hidden" name="already_stored" value="yes" />
|
||||||
<input type="submit" name="send" value="Erneut versenden" />
|
<input type="submit" name="send" value="Erneut versenden" />
|
||||||
</form>
|
</form>
|
||||||
<form action="${tg.url('/')}">
|
<form action="${tg.url('/')}">
|
||||||
|
|
|
@ -10,11 +10,7 @@
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div id="live_pic">
|
<div id="live_pic"><img src="${video_url}"/></div>
|
||||||
<p><img width="200" height="256"
|
|
||||||
src="${tg.url('/static/images/platzhalter.jpg')}"
|
|
||||||
alt="beispiel" /></p>
|
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
<td valign="center">
|
<td valign="center">
|
||||||
<!-- TODO: einfach nur ein weiterfuehrendes Icon - kein Formular -->
|
<!-- TODO: einfach nur ein weiterfuehrendes Icon - kein Formular -->
|
||||||
|
|
Loading…
Reference in a new issue