def form_valid(self, form): chapter = Chapter.objects.get(pk=form.cleaned_data['chapter']) emails = form.cleaned_data['invites'] emails.replace('\r\n', ',') emails = emails.split(',') template_name = 'invite.tmpl' subject = 'Become a preferred service provider for %s' % ( chapter.name, ) url = '/sponsor/' + chapter.slug for email in emails: # Make sure its a legit email address if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", email): mail = Mail(chapter.organizer.email, [email], subject, template_name=template_name, chapter=chapter, url=url) mail.send() if chapter.configured(): return HttpResponseRedirect(reverse('or_dash')) else: return HttpResponseRedirect( reverse('or_setup') + '?chapter=' + str(chapter.id))
def budget_check(): for leadbuyer in LeadBuyer.objects.all(): if not leadbuyer.budget: continue connections = Connection.objects.for_buyer(leadbuyer.user, days_of_month()) total = sum(connection.term.cost for connection in connections if connection.status == 'sent') if total >= leadbuyer.budget: print leadbuyer.user.first_name + ' ' + leadbuyer.user.last_name msg = Mail('*****@*****.**', [leadbuyer.user.email], subject="Brightmap Budget", template_name='budget_notice.tmpl', bcc=None, buyer=leadbuyer.user, connections=connections, total=total, budget=leadbuyer.budget, url=reverse('lb_budget')) ans = raw_input('Send Notice? (y/n)') if ans == 'y': msg.send()
def check_budget(term): """ Check if the LeadBuy has gone over budget """ leadbuyer = LeadBuyer.objects.get(user=term.buyer) if not leadbuyer.budget: return True connections = Connection.objects.for_buyer(term.buyer, days_of_month()) total = sum(connection.term.cost for connection in connections if connection.status == 'sent') if total >= leadbuyer.budget: return False warning_level = float(leadbuyer.budget) * 0.90 if total >= warning_level: buyer = term.buyer #organizer = term.deal.chapter.organizer mail = Mail('*****@*****.**', [buyer.email], 'Budget', 'budget_notice.tmpl', bcc=None, buyer=buyer, budget=leadbuyer.budget, total=total, connections=connections, url=reverse('lb_dash')) mail.send() return True
def remind( request ): if 'term' in request.GET: term = Term.objects.get( pk = request.GET['term']) url = 'http://brightmap.com/'+reverse('or_dash') context = {'term':term, 'url':url} template = 'reminder.tmpl' subject = 'BrightMap Sponsorship: '+ term.buyer.first_name+ ' '+ term.buyer.last_name+' - APPROVAL REQUIRED' sender = '*****@*****.**' recipients = [ term.deal.chapter.organizer.email ] bcc = [] elif 'chapter' in request.GET: chapter = Chapter.objects.get( pk = request.GET['chapter'] ) url = 'http://brightmap.com/'+reverse('or_setup') context = {'chapter':chapter, 'url':url} template = 'setup_reminder.tmpl' subject = "BrightMap Organizer Reminder" sender = '*****@*****.**' recipients = [ chapter.organizer.email ] bcc = [] else: return HttpResponseRedirect('/') mail = Mail( sender, recipients, subject, template, bcc, kwargs = context ) mail.send() return HttpResponseRedirect('/')
def convert_pending_deals(): terms = Term.objects.filter(status='pending') for term in terms: # Check if the user is approved try: authorize = Authorize.objects.get(user=term.buyer) except Authorize.DoesNotExist: continue if not authorize.profile_id: continue # If this is a Standard or Exclusive deal child = term.get_child() # Approve Standard deals if isinstance(child, Cancel): if child.exclusive: continue # Check trial deals, only allow 1 per buyer, 1 per chapter elif isinstance(child, Expire): expires = Expire.objects.filter(buyer=term.buyer, status='approved') if len(expires) >= settings.MAX_TRIALS: continue # Check the number of trials the organizer has expires = Expire.objects.filter(deal=term.deal, status='approved') if len(expires) > 0: continue print "Deal: " + term.deal.chapter.name + '-' +\ term.deal.interest.interest + ' for ' +\ term.buyer.first_name + ' ' + term.buyer.last_name ans = raw_input('Convert? (y/n)') if not ans == 'y': continue term.status = 'approved' term.save() subject = term.deal.chapter.name + ' sponsorship approved' mail = Mail("*****@*****.**", [term.buyer.email, term.deal.chapter.organizer.email], subject, 'deal_status.tmpl', term=term, url=reverse('lb_dash')) mail.send()
def status(request): """ Change the status of a deal """ if request.method == 'GET' and 'term' in request.GET: term = Term.objects.get(pk=request.GET['term']) if term.owner() == request.user and 'status' in request.GET: status = request.GET['status'] # Email status changes to everyone if status in TERM_STATUS: term.status = request.GET['status'] term.save() mail = Mail(term.deal.chapter.organizer.email, [term.buyer.email], 'BrightMap Deal', 'deal_status.tmpl', term=term, url=reverse('lb_dash')) mail.send() return HttpResponseRedirect(reverse('or_dash'))
def mail_organizer( user, deal, term, deal_type ): # Render the letter organizer = deal.chapter.organizer sender = '*****@*****.**' if deal_type == 'cancel': subject = deal.chapter.name + ' deal canceled: ' + user.first_name + ' '+ user.last_name recipients = [ organizer.email ] template_name = 'canceled.tmpl' else: subject = deal.chapter.name + ' sponsorship: ' + user.first_name + ' '+ user.last_name recipients = [ organizer.email, term.buyer.email ] template_name = 'request.tmpl' mail = Mail( sender, recipients, subject, template_name = template_name, user = user, deal = deal, term = term, type = deal_type ) mail.send() return
def warn_user(term, warning=False): """ Warn a deal buyer that their deal has changed, if warning is about to expire """ child = term.get_child() if isinstance(child, Expire) or isinstance(term, Expire): buyer = term.buyer organizer = term.deal.chapter.organizer if warning: template_name = 'expire_warning.tmpl' subject = 'BrightMap Trial Expiring: ' + term.deal.chapter.name connects = term.connections() chapter = term.deal.chapter else: # Check if they are authorized leadbuyer = LeadBuyer.objects.get(user=buyer) if leadbuyer.authorized(): template_name = 'expire_notice.tmpl' subject = 'BrightMap Trial Expired: ' + term.deal.chapter.name connects = term.connections() chapter = term.deal.chapter cancel = False else: template_name = 'expire_cancel.tmpl' subject = 'BrightMap Trial Expired: ' + term.deal.chapter.name connects = term.connections() chapter = term.deal.chapter cancel = True msg = Mail(organizer.email, [buyer.email], subject=subject, template_name=template_name, bcc=[organizer.email], buyer=buyer, term=term, connections=connects, chapter=chapter, url=reverse('lb_dash')) result = msg.send() if not result: print log('Error sending email to %s for deal expiration' % (buyer.email, )) # If this is not warning, delete the trial and make it a standard deal if not warning: term.canceled() if cancel: return new_term = Cancel(deal=term.deal, cost=20, buyer=term.buyer, exclusive=False, status='approved') new_term.save() # Create duplicates for exist free trials. So emails duplicate emails are not sent connections = Connection.objects.filter(term=term) for connection in connections: clone = Connection(term=new_term, survey=connection.survey, status='duplicate') clone.save() return
from base.mail import Mail def get_host_ip(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(('8.8.8.8', 80)) ip = s.getsockname()[0] finally: s.close() return ip if __name__ == '__main__': conf = yaml.load(open('conf/ip_monitor_conf.yaml', 'r')) last_ip = conf['last_ip'] new_ip = get_host_ip() if new_ip != last_ip: conf['last_ip'] = new_ip yaml.dump(conf, open('conf/ip_monitor_conf.yaml', 'w+'), default_flow_style=False, allow_unicode=True) server = conf['send_server'] user = conf['send_user'] passwd = conf['send_passwd'] receivers = [receiver['email'] for receiver in conf['receivers'] if receiver['active']] email = Mail() email.setSmtpServer(server) email.setSender(user, passwd) email.setReceivers(receivers) email.setMessage(subject="IP地址更改通知", content="Ant1009 服务器IP地址更改为: %s" % new_ip) email.sendMail()