except ImportError: pass def detect_geo(self): if self.ip and self.counter == 0: from django.contrib.gis.geoip import GeoIP, GeoIPException try: g = GeoIP() info = g.city(self.ip) or dict() for (k, v) in info.items(): setattr(self, 'ip_%s' % k, v) except GeoIPException: pass def detect_open(self): if self.counter == 0: self.counter = 1 elif self.counter >= 1: self.counter += 1 def save(self, *args, **kwargs): self.detect_ua() self.detect_geo() self.detect_open() super(MailLogTrack, self).save(*args, **kwargs) if VERSION < (1, 7): initial_signals()
def ready(self): from dbmail import initial_signals from dbmail.defaults import ALLOWED_MODELS_ON_ADMIN if 'Signal' in ALLOWED_MODELS_ON_ADMIN: initial_signals()
class MailSubscription(MailSubscriptionAbstract): class Meta: verbose_name = _('Mail Subscription') verbose_name_plural = _('Mail Subscriptions') def __str__(self): if self.user: return self.user.username return self.address ''' class MailSubscriptionGroup(models.Model): group = models.CharField(max_length=100, unique=True) class MailNotification(models.Model): group = models.ForeignKey(AbstractMailSubscriptionGroup) notify = models.ManyToManyField(MailSubscription) @classmethod def notify(cls, user, mail_slug, group, **kwargs): from dbmail import send_db_subscription for notify in cls.objects.filter(notify__user=user, group=group): send_db_subscription( mail_slug, user.pk, {'pk': notify.pk}, **kwargs) ''' if VERSION < (1, 7): initial_signals()
def ready(self): from dbmail import initial_signals initial_signals()