summaryrefslogtreecommitdiffstats
path: root/mycomments/models.py
blob: dabc1075d309b0bb9168342dbc6774025a12b59d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from django.db import models
from django.contrib.comments.models import Comment

class MyComment(Comment):
    class Meta:
        proxy = True
        verbose_name = "Comment"

class BannedIP(models.Model):
    ip_address = models.GenericIPAddressField(unpack_ipv4=True, unique=True)

    def __unicode__(self):
        return u"%s" % self.ip_address

    class Meta:
        ordering = ('ip_address',)
        verbose_name = 'banned IP'
        verbose_name_plural = 'banned IPs'

class BannedUserName(models.Model):
    user_name = models.CharField("user's name", max_length=50, unique=True)

    def __unicode__(self):
        return u"%s" % self.user_name

    class Meta:
        ordering = ('user_name',)


# connect our signals
from django.contrib.comments.signals import (comment_was_posted,
        comment_will_be_posted)
from django.db.models.signals import pre_save
from mycomments.signals import (send_comment_by_mail, check_spam_comment,
        set_comment_ip_address)

comment_was_posted.connect(send_comment_by_mail,
        dispatch_uid='mycomments.models')
comment_will_be_posted.connect(check_spam_comment,
        dispatch_uid='mycomments.models')
# Note: why I have to connect to 'Comment' and not 'MyComment' is beyond me and
# probably a bug, but this does the job.
pre_save.connect(set_comment_ip_address, sender=Comment,
        dispatch_uid='mycomments.models')

# vim: set ts=4 sw=4 et: