From: Michael Tremer Date: Fri, 2 Nov 2012 12:15:24 +0000 (+0100) Subject: Add modules to place adverts. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0048e66852bbb66369dc21252da755c3a1caa1c;p=ipfire.org.git Add modules to place adverts. --- diff --git a/www/templates/download-splash.html b/www/templates/download-splash.html index aaf69fae..f1665a01 100644 --- a/www/templates/download-splash.html +++ b/www/templates/download-splash.html @@ -56,6 +56,8 @@ + {{ modules.Advertisement("download-splash") }} +

{{ _("Next steps") }}

diff --git a/www/templates/modules/ads/download-splash.html b/www/templates/modules/ads/download-splash.html new file mode 100644 index 00000000..ac5c7326 --- /dev/null +++ b/www/templates/modules/ads/download-splash.html @@ -0,0 +1,8 @@ +
+
+
+ {{ _("Advertisement") }}
+ {{ _("This download is sponsored by %s!") % ad.who }} +
+
+
diff --git a/www/translations/de_DE/LC_MESSAGES/webapp.po b/www/translations/de_DE/LC_MESSAGES/webapp.po index 5b167ef3..b3d28196 100644 --- a/www/translations/de_DE/LC_MESSAGES/webapp.po +++ b/www/translations/de_DE/LC_MESSAGES/webapp.po @@ -8,7 +8,7 @@ msgid "" 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 \n" "Language-Team: LANGUAGE \n" @@ -429,19 +429,19 @@ msgstr "" 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" @@ -1026,6 +1026,15 @@ msgstr "Springe zu" 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" @@ -1398,11 +1407,11 @@ msgstr "Vor mehr als einem Tag" 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" diff --git a/www/translations/webapp.pot b/www/translations/webapp.pot index 2ea82987..48de2119 100644 --- a/www/translations/webapp.pot +++ b/www/translations/webapp.pot @@ -8,7 +8,7 @@ msgid "" 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 \n" "Language-Team: LANGUAGE \n" @@ -420,19 +420,19 @@ msgstr "" 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 "" @@ -1017,6 +1017,15 @@ 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 "" @@ -1389,11 +1398,11 @@ 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 "" diff --git a/www/webapp/__init__.py b/www/webapp/__init__.py index 141fedbc..f5c656d1 100644 --- a/www/webapp/__init__.py +++ b/www/webapp/__init__.py @@ -28,6 +28,7 @@ class Application(tornado.web.Application): login_url = "/login", template_path = os.path.join(BASEDIR, "templates"), ui_modules = { + "Advertisement" : AdvertisementModule, "DonationBox" : DonationBoxModule, "DownloadButton" : DownloadButtonModule, "Menu" : MenuModule, diff --git a/www/webapp/backend/__init__.py b/www/webapp/backend/__init__.py index 28794299..c97c0dd1 100644 --- a/www/webapp/backend/__init__.py +++ b/www/webapp/backend/__init__.py @@ -6,6 +6,7 @@ from tornado.options import define, options, parse_command_line 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 diff --git a/www/webapp/backend/ads.py b/www/webapp/backend/ads.py new file mode 100644 index 00000000..eadf10ac --- /dev/null +++ b/www/webapp/backend/ads.py @@ -0,0 +1,70 @@ +#!/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 """%s""" % (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) diff --git a/www/webapp/handlers_base.py b/www/webapp/handlers_base.py index 38620c5c..7dd75f19 100644 --- a/www/webapp/handlers_base.py +++ b/www/webapp/handlers_base.py @@ -119,6 +119,10 @@ class BaseHandler(tornado.web.RequestHandler): return ret + @property + def advertisements(self): + return backend.Advertisements() + @property def accounts(self): return backend.Accounts() diff --git a/www/webapp/ui_modules.py b/www/webapp/ui_modules.py index 6994e75f..7e6af2f2 100644 --- a/www/webapp/ui_modules.py +++ b/www/webapp/ui_modules.py @@ -21,6 +21,10 @@ class UIModule(tornado.web.UIModule): def accounts(self): return self.handler.accounts + @property + def advertisements(self): + return self.handler.advertisements + @property def banners(self): return self.handler.banners @@ -42,6 +46,20 @@ class UIModule(tornado.web.UIModule): 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")