Monday, February 2, 2015

Re: sending email

Hi James,
I manage to fixe my email issue. Basically what i am trying to do here is to get the app to send an email to the a leave applicant when his/her leave is approved by the department director and at the same time update the data on the databases.

Here is my working view.py code for future referencing.

def coporateservices_authorized_Leave(request, id):
    if request.method == 'POST':
        a=newleave.objects.get(id=id)
        form = coporateservices_authoriseleave(request.POST, instance=a)
        if form.is_valid():
         form.save()
        to_emails = [u.email for u in User.objects.filter(username__in=[a.username])]
        send_mail("RBV Leave Application Email Testing", "Your Leave Application have been approved by"+" "+a.authorized_by1,
        "RBV eLeave <Rbv_eLeave_System>", to_emails)
        return render_to_response('thankyou.html')
    else:
        a=newleave.objects.get(id=id)
        form =  coporateservices_authoriseleave(instance=a)
        return render_to_response('coporate_services_leave_approvial.html', {'form': form}, context_instance=RequestContext(request))

once again thank you very much for your help.


 Cheers.




On Tue, Feb 3, 2015 at 2:38 PM, sum abiut <suabiut@gmail.com> wrote:
Hi James,

if you have a look at my view.py code below. i am trying to send email to a selected user that i have select to update that particular user using a form. The updated part is working fine now, i can update the particular row that i have selected. what i want to do next is to email that particular user that his data has been updated. i am still very confuse about the email part.

view.py

def coporateservices_authorized_Leave(request, id):
if request.method == 'POST':
a=newleave.objects.get(id=id)
form = coporateservices_authoriseleave(request.POST, instance=a)
if form.is_valid():
form.save()
to_emails = [a.admins.all()]
send_mail("RBV Leave Application Email Testing", "Your Leave have been approved",
"RBV eLeave <Rbv_eLeave_System>", [to_emails])
return render_to_response('thankyou.html')
else:
a=newleave.objects.get(id=id)
form = coporateservices_authoriseleave(instance=a)
return render_to_response('coporate_services_leave_approvial.html', {'form': form}, context_instance=RequestContext(request))


model.py

class newleave(models.Model):
first_name = models.CharField(max_length=45)
last_name =models.CharField(max_length=45)
department=models.CharField(max_length =45)
position=models.CharField(max_length =45)
leave_type =models.CharField(max_length=45)
specify_details=models.TextField(default="")
start_date =models.DateField(null=True)
end_date=models.DateField(null=True)
total_working_days=models.IntegerField(null=True)
department_head_authorization =models.CharField(max_length=45, default ="")
authorized_by=models.CharField(max_length=45, default ="")
remarks=models.TextField()
authorization_date =models.DateField(null=True)
corporate_services_authorization =models.CharField(max_length=45)
authorized_by1=models.CharField(max_length=45)
remarks1=models.TextField(default ="")
authoriztaion1_date =models.DateField(null=True)
total_Leave_Left =models.IntegerField(default=20)
username =models.ForeignKey(User, default =1)










On Mon, Feb 2, 2015 at 8:44 PM, monoBOT <monobot.soft@gmail.com> wrote:

2015-02-02 6:51 GMT+01:00 sum abiut <suabiut@gmail.com>:

to_emails = [a.admins.all()]

You are asking for item admins here:


to_emails = [a.admins.all()]



--
monoBOT
Visite mi sitio(Visit my site): monobotsoft.es/blog/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BxOsGBHGrjKgDV7ZvS%2Bs1EUm571bpQzdGPEn6MGyRKvUqYh2w%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



-




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y4aJYmh1zS--w5vdi6dPJpW_acruQY-JfWbtWUwFgOwHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment