Monday, September 27, 2010

sending 3 e-mail randomly to user

Hi, everyone

I'm trying to code "sending email randomly function".

[img]http://file.kaywon.ac.kr:2700/club/bluerad/test6.JPG[/img]

this is request form that i made.

When user click "submit" button, the data will be saved and send e-mail to 3
judges of 10 judges randomly.

[b]development envirnment: python27, postgresql8.4, django1.2[/b]
[b]models.py[/b]
[code]class Wb(models.Model):
wbtitle field

wbtitle=models.CharField(max_length=30)

wbreason=models.TextField()
[/code]

[b]forms.py[/b]
[code]
class MsgRequestForm(forms.Form):
wbtitle=forms.CharField(label='Title',
widget=forms.TextInput (attrs={'size':30, 'max_length':30}))

wbreason=forms.CharField(label='Reason:',
widget=forms.Textarea(attrs={'size':10000}))
[/code]
[b]views.py[/b]
[code]
from django.contrib.auth.decorators import login_required

from django.db import models

from django.contrib.auth.models import User

# login required function
@login_required

def msg_request(request):
# If it is released through the POST method to submit form data and a
message calling the function.
if request.method=='POST':
# Create a message that contains the user information form object
MsgPostForm。
form=MsgRequestForm(request.POST)
#If the user submitted form data validation legitimate message。
if form.is_valid():
#According to the information the user submits the message to create a new
message object。
wbmessage=Wb(wbtitle=form.cleaned_data['wbtitle'],
wbreason=form.cleaned_data['wbreason'],
)
#Save the message object to the message information table。
wbmessage.save()

#wb_address=request.META.get('HTTP_REFERER',"/")


#Randomly select 3 from group judges of entity Auth_user_groups
chosen_judges=User.objects.filter(groups__name="judges").order_by('?')[3]

#Jump to page
return HttpResponseRedirect('/')
# If a direct call to the function,
# Then create a data message is not bound to any form object。
else:
form=MsgRequestForm()
variables=RequestContext(request,{'form':form})
return render_to_response('msg_request.html',variables)
[/code]

this is my code source
[url]http://club.kaywon.ac.kr/DownloadServlet?id=bluerad&filename=mysite(2)(2).zip[/url]

do you have any idea?
how to send 3 email randomly to judges?

#Randomly select 3 from group judges of entity Auth_user_groups
#chosen_judges=User.objects.filter(groups__name="judges").order_by('?')[3]

django has "judges" group and "user" group. I will use judges group. when
they registed, emial will be saved on the database.

how can I send 3 random e-mail to judges?

plz help me.

--
View this message in context: http://old.nabble.com/sending-3-e-mail-randomly-to-user-tp29825704p29825704.html
Sent from the django-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment