</div>
</div>
+ {{ modules.Advertisement("download-splash") }}
+
<h3>{{ _("Next steps") }}</h3>
<div class="row">
<div class="span4">
--- /dev/null
+<div class="row">
+ <div class="span6 offset3">
+ <div class="alert alert-info ac">
+ <strong>{{ _("Advertisement") }}</strong><br>
+ {{ _("This download is sponsored by %s!") % ad.who }}
+ </div>
+ </div>
+</div>
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-10-23 11:34+0200\n"
+"POT-Creation-Date: 2012-11-02 13:12+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgid "Thanks for downloading IPFire!"
msgstr "Vielen Dank, für das Herunterladen von IPFire! "
-#: templates/download-splash.html:59
+#: templates/download-splash.html:61
msgid "Next steps"
msgstr "Nächste Schritte"
-#: templates/download-splash.html:64
+#: templates/download-splash.html:66
msgid "Install IPFire"
msgstr "IPFire installieren"
-#: templates/download-splash.html:80
+#: templates/download-splash.html:82
msgid "Access documentation"
msgstr "Dokumentation lesen"
-#: templates/download-splash.html:98
+#: templates/download-splash.html:100
msgid "Join the community"
msgstr "Der Community beitreten"
msgid "Most recent"
msgstr "Aktuellste"
+#: templates/modules/ads/download-splash.html:4
+msgid "Advertisement"
+msgstr "Werbung"
+
+#: templates/modules/ads/download-splash.html:5
+#, python-format
+msgid "This download is sponsored by %s!"
+msgstr "Dieser Download wurde gesponsort von %s!"
+
#: templates/modules/menu.html:4
msgid "Download"
msgstr "Download"
msgid "Profile not found"
msgstr "Profil nicht gefunden"
-#: webapp/handlers_news.py:43 webapp/ui_modules.py:58
+#: webapp/handlers_news.py:43 webapp/ui_modules.py:76
msgid "Unknown author"
msgstr "Unbekannter Autor"
-#: webapp/ui_modules.py:221
+#: webapp/ui_modules.py:239
#, python-format
msgid "%s to %s"
msgstr "%s nach %s"
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-10-23 11:34+0200\n"
+"POT-Creation-Date: 2012-11-02 13:12+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgid "Thanks for downloading IPFire!"
msgstr ""
-#: templates/download-splash.html:59
+#: templates/download-splash.html:61
msgid "Next steps"
msgstr ""
-#: templates/download-splash.html:64
+#: templates/download-splash.html:66
msgid "Install IPFire"
msgstr ""
-#: templates/download-splash.html:80
+#: templates/download-splash.html:82
msgid "Access documentation"
msgstr ""
-#: templates/download-splash.html:98
+#: templates/download-splash.html:100
msgid "Join the community"
msgstr ""
msgid "Most recent"
msgstr ""
+#: templates/modules/ads/download-splash.html:4
+msgid "Advertisement"
+msgstr ""
+
+#: templates/modules/ads/download-splash.html:5
+#, python-format
+msgid "This download is sponsored by %s!"
+msgstr ""
+
#: templates/modules/menu.html:4
msgid "Download"
msgstr ""
msgid "Profile not found"
msgstr ""
-#: webapp/handlers_news.py:43 webapp/ui_modules.py:58
+#: webapp/handlers_news.py:43 webapp/ui_modules.py:76
msgid "Unknown author"
msgstr ""
-#: webapp/ui_modules.py:221
+#: webapp/ui_modules.py:239
#, python-format
msgid "%s to %s"
msgstr ""
login_url = "/login",
template_path = os.path.join(BASEDIR, "templates"),
ui_modules = {
+ "Advertisement" : AdvertisementModule,
"DonationBox" : DonationBoxModule,
"DownloadButton" : DownloadButtonModule,
"Menu" : MenuModule,
define("debug", default=False, help="Run in debug mode", type=bool)
parse_command_line()
+from ads import Advertisements
from accounts import Accounts
from banners import Banners
from geoip import GeoIP
--- /dev/null
+#!/usr/bin/python
+
+from __future__ import division
+
+import datetime
+import textile
+
+from databases import Databases
+from misc import Singleton
+
+class Advertisements(object):
+ __metaclass__ = Singleton
+
+ @property
+ def db(self):
+ return Databases().webapp
+
+ def get(self, where=None):
+ args = []
+ query = "SELECT * FROM advertisements \
+ WHERE DATE(NOW()) >= date_start AND DATE(NOW()) <= date_end AND published = 'Y'"
+
+ if where:
+ query += " AND `where` = %s"
+ args.append(where)
+
+ query += " ORDER BY RAND() LIMIT 1"
+
+ ad = self.db.get(query, *args)
+ if ad:
+ return Advert(self, ad.id, ad)
+
+
+class Advert(object):
+ def __init__(self, advertisements, id, data=None):
+ self.advertisements = advertisements
+ self.id = id
+
+ self.__data = data
+
+ @property
+ def db(self):
+ return self.advertisements.db
+
+ @property
+ def data(self):
+ if self.__data is None:
+ self.__data = self.db.get("SELECT * FROM advertisements WHERE id = %s", self.id)
+ assert self.__data
+
+ return self.__data
+
+ @property
+ def company(self):
+ return self.data.company
+
+ @property
+ def text(self):
+ return self.data.text
+
+ @property
+ def url(self):
+ return self.data.url
+
+ @property
+ def who(self):
+ return """<a href="%s" target="_blank">%s</a>""" % (self.url, self.text or self.company)
+
+ def update_impressions(self):
+ self.db.execute("UPDATE advertisements SET impressions = impressions + 1 WHERE id = %s", self.id)
return ret
+ @property
+ def advertisements(self):
+ return backend.Advertisements()
+
@property
def accounts(self):
return backend.Accounts()
def accounts(self):
return self.handler.accounts
+ @property
+ def advertisements(self):
+ return self.handler.advertisements
+
@property
def banners(self):
return self.handler.banners
return self.handler.news
+class AdvertisementModule(UIModule):
+ def render(self, where):
+ assert where in ("download-splash",), where
+
+ ad = self.advertisements.get(where)
+ if not ad:
+ return ""
+
+ # Mark that advert has been shown.
+ ad.update_impressions()
+
+ return self.render_string("modules/ads/%s.html" % where, ad=ad)
+
+
class MenuModule(UIModule):
def render(self):
return self.render_string("modules/menu.html")