Skip to content

Commit

Permalink
fixed problem with import
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlium committed Nov 13, 2013
1 parent 1e6debf commit 170c9e7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion TODO
@@ -1 +1,2 @@
Add backend for ipgeobase. Now supported own db with providers & ISP.
Add backend for ipgeobase. Now supported own db with providers & ISP.
Py3.2 support
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -50,9 +50,9 @@
# built documents.
#
# The short X.Y version.
version = '1.2'
version = '1.2.1'
# The full version, including alpha/beta/rc tags.
release = '1.2'
release = '1.2.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/dev_install.rst
Expand Up @@ -19,7 +19,7 @@ Installation for development
.. code-block:: python
>>> from geoip import record_by_ip_as_dict
>>> from geoip.geo import record_by_ip_as_dict
>>> print (record_by_ip_as_dict('91.195.136.52'))
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Expand Up @@ -17,7 +17,7 @@ and provider.

Here is a basic example::

from geoip import record_by_ip_as_dict
from geoip.geo import record_by_ip_as_dict

ip = '91.195.136.52'

Expand Down
8 changes: 0 additions & 8 deletions geoip/__init__.py
@@ -1,8 +0,0 @@
__all__ = ["record_by_ip_as_dict", "record_by_request_as_dict",
"record_by_ip", "record_by_request", "get_ip"]

from .geo import (
record_by_ip_as_dict, record_by_request_as_dict,
record_by_ip, record_by_request, get_ip,
)
from .signals import *
20 changes: 18 additions & 2 deletions geoip/models.py
@@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-

from django.db.models.signals import post_save, m2m_changed
from django.utils.translation import ugettext as _
from django.dispatch import receiver
from django.db import models

from geoip.redis_wrapper import RedisSync
from geoip.tasks import link_provider_task
from geoip.defaults import BACKEND


class Country(models.Model):
Expand Down Expand Up @@ -58,8 +62,8 @@ def __unicode__(self):
return self.name

class Meta:
verbose_name = u'ISP'
verbose_name_plural = u"ISP's"
verbose_name = _('ISP')
verbose_name_plural = _("ISP's")
unique_together = (('country', 'name'), )


Expand Down Expand Up @@ -112,3 +116,15 @@ def set_provider(self, provider):
class Meta:
verbose_name = _('IP range')
verbose_name_plural = _("IP ranges")


@receiver(post_save, sender=Range, dispatch_uid="range")
def save_to_redis(sender, instance, *args, **kwargs):
if BACKEND == 'redis':
RedisSync().sync_instance(instance)


@receiver(m2m_changed, sender=Provider.isp.through, dispatch_uid="provider")
def save_provider(sender, instance, action, *args, **kwargs):
if action == 'post_clear':
link_provider_task(instance)
4 changes: 2 additions & 2 deletions geoip/tasks.py
Expand Up @@ -5,18 +5,18 @@
from celery.task import Task

from geoip.defaults import USE_CELERY, REDIS_SYNC_LOCK
from geoip.provider import LinkIspWithProvider
from geoip.models import Range


class LinkIspWithProviderTask(Task):
def run(self, *args, **kwargs):
from geoip.provider import LinkIspWithProvider
LinkIspWithProvider().run(*args, **kwargs)


class SyncRedisTask(Task):
def run(self, *args, **kwargs):
try:
from geoip.models import Range
if not os.path.exists(REDIS_SYNC_LOCK):
open(REDIS_SYNC_LOCK, 'w').close()
Range.sync_with_redis()
Expand Down
2 changes: 1 addition & 1 deletion geoip/test_settings.py
Expand Up @@ -37,4 +37,4 @@
TEST_RUNNER = 'discover_runner.DiscoverRunner'

GEO_REDIS_TYPE = 'pk'
GEO_REDIS_DB = 5
GEO_REDIS_DB = 6
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -4,7 +4,7 @@

setup(
name='django-geoip-redis',
version="1.2",
version="1.2.1",
description='Django GeoIP. Based on default DB or Redis.',
keywords='django geoip mysql redis',
long_description=open('README.rst').read(),
Expand Down

0 comments on commit 170c9e7

Please sign in to comment.