]> git.ipfire.org Git - ipfire.org.git/commitdiff
Add modules to place adverts.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Nov 2012 12:15:24 +0000 (13:15 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 2 Nov 2012 12:15:24 +0000 (13:15 +0100)
www/templates/download-splash.html
www/templates/modules/ads/download-splash.html [new file with mode: 0644]
www/translations/de_DE/LC_MESSAGES/webapp.po
www/translations/webapp.pot
www/webapp/__init__.py
www/webapp/backend/__init__.py
www/webapp/backend/ads.py [new file with mode: 0644]
www/webapp/handlers_base.py
www/webapp/ui_modules.py

index aaf69fae52ecba7b8817903b1731f766dff958a7..f1665a0172b2c16b86157fb5a8ee96a0d2fe303b 100644 (file)
@@ -56,6 +56,8 @@
                </div>
        </div>
 
+       {{ modules.Advertisement("download-splash") }}
+
        <h3>{{ _("Next steps") }}</h3>
        <div class="row">
                <div class="span4">
diff --git a/www/templates/modules/ads/download-splash.html b/www/templates/modules/ads/download-splash.html
new file mode 100644 (file)
index 0000000..ac5c732
--- /dev/null
@@ -0,0 +1,8 @@
+<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>
index 5b167ef3d52d14765cc3b5979bff241edcb5c195..b3d28196095e509a49911fd4d17ae492b7e0f6c6 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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"
index 2ea829878d172e06bba8e751411828fd1982cb60..48de2119bc7f0d7db17882a5f65634a1e59d2ea5 100644 (file)
@@ -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 <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 ""
index 141fedbc197630a4e160a38150be464ef8ec980a..f5c656d1b5f15845da62de69c4cd220957b2da9b 100644 (file)
@@ -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,
index 28794299c6c151e40f82a5715bb7e2cbfbf9ca97..c97c0dd1f58764850a712f832db516799f373bfd 100644 (file)
@@ -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 (file)
index 0000000..eadf10a
--- /dev/null
@@ -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 """<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)
index 38620c5cc633fd4b137feed9913bd09e68069ec5..7dd75f19818b91f4afb4414b86dee66f24290fa0 100644 (file)
@@ -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()
index 6994e75fad64e65301173a2f31f8bf9f282cd2c8..7e6af2f2c22f64996898a4d14ef6decdbe5b59d6 100644 (file)
@@ -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")