1+ import datetime
12from django .db import models
23from django .conf import settings
34from django .contrib .auth .models import User
1314 ('both' , 'Developer/Designer' ),
1415)
1516
17+ MESSAGE_WAIT_PERIOD = 2
18+ MAX_MESSAGES = 100
19+
1620class Profile (LocationModel ):
1721 user = models .OneToOneField (User , related_name = 'profile' )
1822 url = models .URLField (blank = True )
@@ -21,11 +25,28 @@ class Profile(LocationModel):
2125 twitter_id = models .CharField (max_length = 15 , blank = True )
2226 skills = TagField ('comma separated list of your skills (eg. python, django)' )
2327
28+ # other metadata
2429 allow_org_emails = models .BooleanField (default = False )
30+ signup_date = models .DateTimeField (auto_now_add = True )
31+ last_email_sent = models .DateTimeField (null = True )
32+ num_emails_sent = models .IntegerField (default = 0 )
2533
2634 def __unicode__ (self ):
2735 return unicode (self .user )
2836
37+ def can_send_email (self ):
38+ if self .last_email_sent :
39+ elapsed = datetime .datetime .now () - self .last_email_sent
40+ else :
41+ elapsed = datetime .timedelta (minutes = MESSAGE_WAIT_PERIOD + 1 )
42+ return (elapsed > datetime .timedelta (minutes = MESSAGE_WAIT_PERIOD ) and
43+ self .num_emails_sent < MAX_MESSAGES )
44+
45+ def record_email_sent (self ):
46+ self .last_email_sent = datetime .datetime .now ()
47+ self .num_emails_sent += 1
48+ self .save ()
49+
2950def create_profile (sender , instance , created , ** kwargs ):
3051 if created :
3152 Profile .objects .create (user = instance )
0 commit comments