Beispiel #1
0
def decline(request, pk):
    if request.method == "POST":
        b = get_object_or_404(User, pk=pk)
        f = PartnerForm(request.POST)
        f.id = pk
        #send email notification
        subject = "East Scarborough Storefront - Account Denied"
        message = "Dear " + b.username + ",\n\nYour account request at East Scarborough Storefront has been denied.\nPlease call the Storefront for more details.\n\nThank you"
        b.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
        b.delete()
        return render(request, 'juakstore/admin_decline.html')
    else:
        form = BookingForm()
        return HttpResponseRedirect(reverse('juakstore/admin_decline.html', args=(pk,)))
Beispiel #2
0
def accept(request, pk):
    if request.method == "POST":
        b = get_object_or_404(User, pk=pk)
        f = PartnerForm(request.POST)
        f.id = pk
        
        b.is_active = True
        b.save()
        #send email notification
        subject = "East Scarborough Storefront - Account Approved"
        current_site = Site.objects.get_current()        
        text_content = "Dear " + b.username + ",\n\nYour account request at East Scarborough Storefront has been approved.\nYou can login at " + current_site.name + ".\n\nThank you"
        html_content = 'Dear ' + b.username + ',<br><br>Your account request at East Scarborough Storefront has been approved.<br>You can login at <a href="http://' + current_site.domain + '">' + current_site.name + '</a>.<br><br>Thank you'
        msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [b.email])
        msg.attach_alternative(html_content, "text/html")
        msg.send()          
        return render(request, 'juakstore/admin_accept.html', {'user': b})
    else:
        form = BookingForm()
        return HttpResponseRedirect(reverse('juakstore/admin_accept.html', args=(pk,)))
Beispiel #3
0
def partnerships(request):
    if request.method == 'POST':
        form = PartnerForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['organization_name'] + ' wants to be our partner!'
            message = form.cleaned_data['message']
            email = form.cleaned_data['email']
            recipients = ['*****@*****.**']

            EmailMessage(subject, message, email, recipients).send()
            return JsonResponse({"status":"success", "message":"Welcome aboard!<br>:)"}, status=200)
        else:
            return JsonResponse({"status":"failure", "message":"Please make sure that you entered a valid email."}, status=400)
    else :
        form = PartnerForm()
        partners = iTool.groupby(Partner.objects.all(), lambda x: int(x.partner_type)) # int() will order the type correctly

        return render(request, 'partnerships.html',
            {'title':"Partnerships",
             'partners':{k: list(v) for k, v in partners},
             'form': form,
             'config':config
            })
Beispiel #4
0
def partner():    
    forms = PartnerForm()
    if forms.validate_on_submit():        
        partner = Partner(orgname=forms.orgname.data,ownername=forms.ownername.data,
                    email=forms.email.data, phone=forms.phone.data,state=forms.state.data,city=forms.city.data,address=forms.address.data)
        db.session.add(partner)
        db.session.commit()
        

        import smtplib

        from string import Template

        from email.mime.multipart import MIMEMultipart
        from email.mime.text import MIMEText

        MY_ADDRESS = 'your_mail_id'
        PASSWORD = '******'

       
        def get_contacts(filename):
            """
            Return two lists names, emails containing names and email addresses
            read from a file specified by filename.
            """
            
            names = []
            emails = []
            with open(filename, mode='r', encoding='utf-8') as contacts_file:
                for a_contact in contacts_file:
                    names.append(a_contact.split()[0])
                    emails.append(a_contact.split()[1])
            return names, emails

        def read_template(filename):
            """
            Returns a Template object comprising the contents of the 
            file specified by filename.
            """
            
            with open(filename, 'r', encoding='utf-8') as template_file:
                template_file_content = template_file.read()
            return Template(template_file_content)

        def main():
            names, emails = get_contacts('mycontact.txt') # read contacts
            message_template = read_template('message.txt')

            # set up the SMTP server
            s = smtplib.SMTP(host='smtp.gmail.com', port=587)
            s.starttls()
            s.login(MY_ADDRESS, PASSWORD)

            # For each contact, send the email:
            for name, email in zip(names, emails):
                msg = MIMEMultipart()       # create a message

                # add in the actual person name to the message template
                message = message_template.substitute(PERSON_NAME=name.title())

                # Prints out the message body for our sake
                print(message)

                # setup the parameters of the message
                msg['From']=MY_ADDRESS
                msg['To']=email
                msg['Subject']="Thanks For Joining"
                
                # add in the message body
                msg.attach(MIMEText(message, 'plain'))
                
                # send the message via the server set up earlier.
                s.send_message(msg)
                del msg
                
            # Terminate the SMTP session and close the connection
            s.quit()
        main()
            

    


        

    return render_template('partner.html', forms=forms)