Django confirm email. Change value from false to true

49 views
Skip to first unread message

enemybass

unread,
Sep 18, 2012, 3:53:23 PM9/18/12
to django...@googlegroups.com
This is my model:

    from django.db import models
    
    class Meeting(models.Model):
        name = models.CharField(max_length=255)
        time = models.DateTimeField()
        confirmed = models.BooleanField(default=False)

This is my form:

    from django import forms
    
    class MeetingForm(forms.Form):
        name = forms.CharField(max_length=100)
        time = forms.DateTimeField()
        user_name = forms.CharField(max_length=100)
        user_email = forms.EmailField()

How to create a view that send a mail to user with link and when user clicks on this link confrimed field will change value to true?

Link is my biggest problem.



Stephen Anto

unread,
Sep 20, 2012, 6:28:32 AM9/20/12
to django...@googlegroups.com
Hi,

Just fllow bellow steps:

In urls.py add bellow url

urlpatterns = patterns('',
    url('^meeting/$',                            'meeting',                         name='meeting'),
    url('^meeting/confirm/(\w+)/$',        'meeting_confirm',            name='meeting_confirm'),
)

In views.py add bellow methods

def meeting(request):
    form = MeetingForm()
    pDict = request.POST.copy()
    if request.method == 'POST':
        form = MeetingForm(pDict)
        if form.is_valid():
            try:
                meeting_obj = Meeting()
                meeting_obj.name = pDict['name']
                meeting_obj.time = pDict['time']
                meeting_obj.confirmed = 0
                meeting_obj.save()

                path = reverse('meeting_confirm'',args=[meeting_obj.id])
                activation_url = u"%s%s" % (unicode(settings.CURRENT_SITE), path)

                context = {
                "email":pDict['user_email']
                "first_name":pDict['user_name'],
                "activation_url": activation_url,
                }
       
                ######## emails/user/meeting_subject.txt #########
                ######## emails/user/meeting_msg.txt ###########
                # Above are templates files for email. You should design as you want

                subject = render_to_string('emails/user/meeting_subject.txt', context)
                subject = "".join(subject.splitlines())
                message = render_to_string('emails/user/meeting_msg.txt', context)
                msg = EmailMultiAlternatives(subject,message, 'ad...@example.com',pDict['user_email'])
                msg.attach_alternative(message, "text/html")
                msg.send()       
           
except:
                pass
            
return render_to_response('meeting.html', locals(),context_instance=RequestContext(request))

def meeting_confirm(request,id):
    meeting_obj = Meeting.objects.get(id=id)
    meeting_obj.confirmed = 1
    meeting_obj.save()

    msg = 'Meeting has been confirmed!'
            
return render_to_response('meeting_confirm.html', locals(),context_instance=RequestContext(request))

I believe it may help you. For more http://f2finterview.com/web/Django/ Than you for visiting



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



--
Thanks & Regards
Stephen S



Blog:      blog.f2finterview.com

Reply all
Reply to author
Forward
0 new messages