Commits

Ivan Markeyev committed a63fda9

initial

Comments (0)

Files changed (3)

__init__.py

Empty file added.
+# -*- coding: utf-8 -*-
+
+import urllib2
+import urllib
+import logging
+from urllib2 import URLError
+
+from django.contrib.sites.models import Site
+from cms.plugin_base import CMSPluginBase
+from cms.plugin_pool import plugin_pool
+
+
+class CMSRadiusHostingLinksPlugin(CMSPluginBase):
+    name = u'Ссылки от radiushosting'
+    render_template = "cmsplugin_radiushostinglinks/links.html"
+
+    def render(self, context, instance, placeholder):
+        r = context.get('request')
+        context.update({
+                        'instance': instance,
+                        'placeholder': placeholder,
+                    })
+        if r:
+            d = Site.objects.all()[0].domain
+            try:
+                params = {
+                    "url": r.path.encode("utf-8"),
+                    "host": d,
+                    "charset": "utf-8",
+                }
+                html = urllib2.urlopen(u"http://links.radiushosting.ru/"
+                                       "get_links.php?%s" % \
+                                       (urllib.urlencode(params),),
+                                       timeout=3).read()
+                context.update({'html': html})
+            except URLError:
+                log = logging.getLogger("radiushosting_ru")
+                log.error(u"не удалось получить ссылки radiushosting.ru")
+                context.update({'html': ''})
+        return context
+
+plugin_pool.register_plugin(CMSRadiusHostingLinksPlugin)
+

templates/cmsplugin_radiushostinglinks/links.html

+{{ html|safe }}