Vitaliy Shishorin avatar Vitaliy Shishorin committed dae0ecd

* Initial import

Comments (0)

Files changed (14)

+# use glob syntax.
+syntax: glob
+*.elc
+*.orig
+*.pyc
+*~
+
+# switch to regexp syntax.
+syntax: regexp
+^\.pc/
+
+#glob:src/static/*
+glob:.project
+glob:.pydevproject
+Vitaliy Shishorin <moskrc@gmail.com>
+Changelog for cmsplugin_yandexmap
+=====================================
+
+1.0.0 (2011-03-06)
+----------------
+
+* Initial project setup
+Copyright (c) 2011 Vitaliy Shishorin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+include AUTHORS
+include LICENSE
+include README.rst
+include HISTORY
+recursive-include src/*/templates *
+===========
+cmsplugin_yandexmap
+===========
+
+Плагин для django-cms. Позволяет добавлять на страницу интерактивную Яндекс карту. Возможности аналогичны
+плагину googlemap.
+Лицензия MIT.
+
+
+Зависимости
+------------
+
+* django-cms >= 2.1
+
+Установка
+------------
+
+pip install cmsplugin_yandexmap
+
+В settings.py добавить плагин в ``INSTALLED_APPS``::
+
+    INSTALLED_APPS = (
+        ...
+        'cmsplugin_yandexmap',
+        ...
+    )
+
+и переменную YANDEX_MAPS_API_KEY со своим API-ключом от Яндекса. 
+Ключ можно получить тут: http://api.yandex.ru/maps/form.xml/
+
+затем запустить ``syncdb`` или ``migrate`` если вы используете South.
Add a comment to this file

cmsplugin_yandexmap/__init__.py

Empty file added.

cmsplugin_yandexmap/cms_plugins.py

+from django.conf import settings
+from cms.plugin_pool import plugin_pool
+from cms.plugin_base import CMSPluginBase
+from django.utils.translation import ugettext_lazy as _
+from models import YandexMap
+from django.forms.widgets import Media
+
+class YandexMapPlugin(CMSPluginBase):
+    model = YandexMap
+    name = _("Yandex Map")
+    render_template = "cmsplugin_yandexmap/yandexmap.html"
+    
+    def render(self, context, instance, placeholder):
+        context.update({
+            'object':instance, 
+            'placeholder':placeholder, 
+        })
+        return context
+    
+    #def get_plugin_media(self, request, context, plugin):
+    #    return Media(js = ('http://maps.google.com/maps/api/js?sensor=true',))
+
+plugin_pool.register_plugin(YandexMapPlugin)

cmsplugin_yandexmap/migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Adding model 'YandexMap'
+        db.create_table('cmsplugin_yandexmap', (
+            ('cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
+            ('address', self.gf('django.db.models.fields.CharField')(max_length=150)),
+            ('zipcode', self.gf('django.db.models.fields.CharField')(max_length=30)),
+            ('city', self.gf('django.db.models.fields.CharField')(max_length=100)),
+            ('content', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
+            ('zoom', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
+            ('lat', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=6, blank=True)),
+            ('lng', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=6, blank=True)),
+        ))
+        db.send_create_signal('cmsplugin_yandexmap', ['YandexMap'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'YandexMap'
+        db.delete_table('cmsplugin_yandexmap')
+
+
+    models = {
+        'cms.cmsplugin': {
+            'Meta': {'object_name': 'CMSPlugin'},
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+            'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+            'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        },
+        'cms.placeholder': {
+            'Meta': {'object_name': 'Placeholder'},
+            'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+        },
+        'cmsplugin_yandexmap.yandexmap': {
+            'Meta': {'object_name': 'YandexMap', 'db_table': "'cmsplugin_yandexmap'", '_ormbases': ['cms.CMSPlugin']},
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+            'content': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'lat': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '6', 'blank': 'True'}),
+            'lng': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '6', 'blank': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'zipcode': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+            'zoom': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['cmsplugin_yandexmap']
Add a comment to this file

cmsplugin_yandexmap/migrations/__init__.py

Empty file added.

cmsplugin_yandexmap/models.py

+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from cms.models import CMSPlugin
+
+class YandexMap(CMSPlugin):
+    """
+    A yandex maps integration
+    """
+    title = models.CharField(_("map title"), max_length=100, blank=True, null=True)
+    
+    address = models.CharField(_("address"), max_length=150)
+    zipcode = models.CharField(_("zip code"), max_length=30)
+    city = models.CharField(_("city"), max_length=100)
+    
+    content = models.CharField(_("additional content"), max_length=255, blank=True, null=True)
+    zoom = models.IntegerField(_("zoom level"), blank=True, null=True)
+    
+    lat = models.DecimalField(_('latitude'), max_digits=10, decimal_places=6, null=True, blank=True, 
+        help_text=_('Use latitude & longitude to fine tune the map possiton.'))
+    lng = models.DecimalField(_('longitude'), max_digits=10, decimal_places=6, null=True, blank=True)
+    
+    
+    def __unicode__(self):
+        return u"%s (%s, %s %s)" % (self.get_title(), self.address, self.zipcode, self.city,)
+    
+    def get_title(self):
+        if self.title == None:
+            return _("Map")
+        return self.title
+    
+    def get_content(self):
+        if self.content == None:
+            return ""
+        return self.content
+    
+    def get_zoom_level(self):
+        if self.zoom == None:
+            return 13
+        return self.zoom
+    
+    def get_lat_lng(self):
+        if self.lat and self.lng:
+            return [self.lat, self.lng]

cmsplugin_yandexmap/settings.py

+from django.conf import settings
+
+YANDEX_MAPS_API_KEY = getattr(settings, "YANDEX_MAPS_API_KEY", "")

cmsplugin_yandexmap/templates/cmsplugin_yandexmap/yandexmap.html

+{% load i18n %}
+<div class="plugin_yandexmap">
+	<!--  ATTENTION: set a height for this div in CSS -->
+	<div id="yandex-map-{{ object.id }}" class="yandex-map-container"></div>
+</div>
+
+<script src="http://api-maps.yandex.ru/1.1/index.xml?key={{settings.YANDEX_MAPS_API_KEY}}" type="text/javascript"></script>
+<script type="text/javascript">
+//<![CDATA[
+(function(){
+	// save settings form plugin
+	var container = 'yandex-map-{{ object.id }}';
+	var latlng = new YMaps.GeoPoint('133.575367','-25.813332'); // default to Australia
+
+	var title = "{{ object.get_title }}";
+	var address = "{{ object.zipcode }}, {{ object.city }}, {{ object.address }}";
+	var additional_content = "{{ object.get_content }}";
+	var zoom = {{ object.get_zoom_level }}
+
+	var map = new YMaps.Map(document.getElementById(container));
+	
+    YMaps.Styles.add("info_balloon", {
+        balloonContentStyle : {
+            template : new YMaps.Template('<div style="heigth:130px;">{% if object.title %}<strong>$[title]</strong><br/><br/>{% endif %}$[address]<br/>{% if object.get_content %}<br/>$[content]{% endif %}</div>')
+        }
+    });
+
+{% if object.get_lat_lng %}
+	// load latlng from given lat lng settings
+	latlng = new YMaps.GeoPoint({{ object.get_lat_lng|join:", " }});
+	initYandexMaps(latlng);
+{% else %}
+	// load latlng from given address
+	var geocoder = new YMaps.Geocoder(address, {results: 1, boundedBy: map.getBounds()});
+	
+	YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
+	    if (this.length()) {
+	    	initYandexMaps(this.get(0).getGeoPoint());
+	    }
+		else {
+			initYandexMaps(latlng);
+    	}	    
+	})	
+{% endif %}
+
+	// initialize yandex maps
+	function initYandexMaps(latlng) {
+		// initialize yandex map
+		map.setCenter(latlng, zoom);
+		
+	 	map.addControl(new YMaps.TypeControl());
+        map.addControl(new YMaps.ToolBar());
+        map.addControl(new YMaps.Zoom());
+        map.addControl(new YMaps.ScaleLine());
+        map.enableScrollZoom();		
+		
+		// create marker
+		var marker = new YMaps.Placemark(latlng,{ style : "info_balloon" });
+		marker.title = title;
+		marker.address = address;
+		marker.content = additional_content;
+		map.addOverlay(marker);
+	}
+})();
+//]]>
+</script>
+import os
+import sys
+# hack for utf8 long_description support
+reload(sys).setdefaultencoding("UTF-8")
+from setuptools import setup, find_packages
+
+def read(fname):
+    return open(os.path.join(os.path.dirname(__file__), fname)).read()
+
+version='1.0.0'
+
+setup(
+    name = 'cmsplugin_yandexmap',
+    version = version,
+    author = 'Vitaliy Shishorin',
+    author_email = 'moskrc@gmail.com',
+    url = 'http://bitbucket.org/moskrc/cmsplugin_yandexmap/',
+    download_url = 'http://bitbucket.org/moskrc/cmsplugin_yandexmap/get/tip.zip',
+
+    description = 'Plugin for django-cms. Yandex Map.',
+    long_description = open('README.rst').read().decode('utf8'),
+    license = 'MIT license',
+    requires = ['django (>=1.0)','django_cms (>=2.1.2)'],
+
+    packages=find_packages(),
+    package_data={'cmsplugin_yandexmap': ['templates/cmsplugin_yandexmap/*']},
+    
+
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Framework :: Django',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Natural Language :: English',
+        'Natural Language :: Russian',
+        'Programming Language :: Python',
+        'Topic :: Software Development :: Libraries :: Python Modules'
+    ],
+    include_package_data=True,
+    zip_safe = False,
+    install_requires=['django-cms>=2.1.2',],
+)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.