Skip to content

Commit

Permalink
add receive time
Browse files Browse the repository at this point in the history
  • Loading branch information
thesues committed Apr 25, 2011
1 parent 501e930 commit d06bc77
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion smthtop10/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from django import forms
from django.utils.translation import ugettext_lazy as _


#this is for registration
class UserRegsiterForm(RegistrationFormUniqueEmail):
kindlemail=forms.EmailField()
updatetime=forms.ChoiceField(choices=UPDATE_TIME)
def clean_kindlemail(self):
if UserProfile.objects.filter(kindlemail=self.cleaned_data['kindlemail']):
raise forms.ValidationError("This email address is already in use. Please supply a different email address.")
Expand All @@ -15,4 +17,5 @@ class ProfileForm(forms.ModelForm):
class Meta:
model=UserProfile
exclude=["user"]



10 changes: 8 additions & 2 deletions smthtop10/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self,author="unknow",content="unknow",signature="unknown",reference
self.imagefilenameList=[]
def __str__(self):
return "%s:\n%s" % (self.author.encode("utf8"),self.content.encode("utf8"))

class Feed():
def __init__(self,title="unknown"):
self.list=list()
Expand All @@ -25,9 +25,15 @@ def append(self,post):
def __str__(self):
return self.title.encode("utf8")

class UserProfile(models.Model):
UPDATE_TIME=(
(7,"7:00 AM"),
(13,"13:00 AM"),
(19,"19:00 AM")
)
class UserProfile(models.Model):
kindlemail=models.EmailField(max_length=75)
user=models.ForeignKey(User,unique=True)
updateTime=models.IntegerField(choices=UPDATE_TIME)
def __unicode__(self):
return unicode(self.user.username)

Expand Down
1 change: 1 addition & 0 deletions smthtop10/regbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def user_created(sender, user, request, **kwargs):
form = UserRegsiterForm(request.POST)
profile=UserProfile(user=user)
profile.kindlemail=form.data['kindlemail']
profile.updateTime=form.data['updateTime']
profile.save()
from registration.signals import user_registered
user_registered.connect(user_created)
5 changes: 4 additions & 1 deletion smthtop10/sendMail.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from django.core.mail import *
from smthtop10.models import UserProfile
from datetime import date
from datetime import datetime
today=date.today()
hour=datetime.now().hour
archive="./archive/"+today.strftime("%Y%m%d")+"/"

#gernarater mobi files
Expand All @@ -17,7 +19,8 @@
print mobifile
if os.path.isfile(mobifile):
t=EmailMessage()
for i in UserProfile.objects.all():
for i in UserProfile.objects.filter(updateTime__iexact=hour)
t.to.append(i.kindlemail)
t.attach_file(mobifile)
t.send()

2 changes: 1 addition & 1 deletion smthtop10/shell/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export DJANGO_SETTINGS_MODULE=newsmth.settings
python buildbook.py
python sendMail.py
python sendMail.py

0 comments on commit d06bc77

Please sign in to comment.