示例#1
0
文件: views.py 项目: stden/bonushouse
 def post(self, request, *args, **kwargs):
     if request.method == 'POST' and request.POST:
         email_list = []
         i = 0
         while (i <= (len(request.POST)-1)/2 - 1): #  Криво и тупо, но работает(
             if i == 0:
                 email_list.append({'name': request.POST.get('name'), 'email': request.POST.get('email')})
             else:
                 email_list.append({'name': request.POST.get('name%d' % i), 'email': request.POST.get('email%d' % i)})
             i += 1
         for email in email_list:
             form = self.form_class(email)
             if not form.is_valid():
                 return HttpResponse(simplejson.dumps({'text':u'Пользователь с email %s уже зарегистрирован!' % email.get('email'), 'email': email.get('email')}), status=500)
             to = email.get('email')
             name = email.get('name')
             subject = get_settings_value('REFER_FRIEND_EMAIL_SUBJECT')
             template = Template(get_settings_value('REFER_FRIEND_EMAIL_TEMPLATE'))
             site = Site.objects.get_current()
             link = 'http://' + site.domain + '/?refered_by='+str(request.user.pk)
             context = Context({'name': name, 'link': link, 'sender':request.user.get_profile().get_name()})
             message = template.render(context)
             send_mail(subject, message,  settings.DEFAULT_FROM_EMAIL, [to,], True)
         return HttpResponse('OK')
     return HttpResponse()
示例#2
0
文件: views.py 项目: stden/bonushouse
def share_link(request):
    redirect_url = request.POST.get('url','/')
    message = ''
    response = {}
    if request.method == 'POST':
        share_link_form = ShareLinkForm(request.POST)
        if share_link_form.is_valid():
            response['success'] = True
            share_link_context = Context({'LINK':settings.BASE_URL+share_link_form.cleaned_data['url'], 'NAME': share_link_form.cleaned_data['name'], 'SENDER': request.user.get_profile().get_name()})
            share_link_template = Template(get_settings_value('SHARE_LINK_EMAIL_TEMPLATE'))
            message = share_link_template.render(share_link_context)
            subject = get_settings_value('SHARE_LINK_EMAIL_SUBJECT')
            to = share_link_form.cleaned_data['email']
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [to, ], True)
            if request.is_ajax():
                message = u'Спасибо! Мы отправим ссылку вашему другу в самое ближайшее время. Приятных покупок!'
            else:
                messages.info(request, u'Спасибо! Мы отправим ссылку вашему другу в самое ближайшее время. Приятных покупок!')
        else:
            response['success'] = False
            for field in share_link_form:
                for error in field.errors:
                    if request.is_ajax():
                        message += u"%s - %s<br/>" % (field.label, error)
                    else:
                        messages.error(request, (u'%s - %s' % (field.label, error)))
    if request.is_ajax():
        response['message'] = message
        return HttpResponse(simplejson.dumps(response))
    else:
        return redirect(redirect_url)
示例#3
0
文件: forms.py 项目: stden/bonushouse
 def send(self):
     context = Context(self.cleaned_data)
     template = Template(get_settings_value('FOR_PARTNERS_FORM_TEMPLATE'))
     message = template.render(context)
     subject = get_settings_value('FOR_PARTNERS_FORM_SUBJECT')
     to = get_settings_value('FOR_PARTNERS_FORM_EMAIL')
     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [to,], True)
示例#4
0
文件: forms.py 项目: stden/bonushouse
 def save(self, referer):
     to = self.cleaned_data['email']
     name = self.cleaned_data['name']
     subject = get_settings_value('REFER_FRIEND_EMAIL_SUBJECT')
     template = Template(get_settings_value('REFER_FRIEND_EMAIL_TEMPLATE'))
     site = Site.objects.get_current()
     link = 'http://' + site.domain + '/?refered_by='+str(referer.pk)
     context = Context({'name': name, 'link': link, 'sender':get_current_user().get_profile().get_name()})
     message = template.render(context)
     send_mail(subject, message,  settings.DEFAULT_FROM_EMAIL, [to,], True)
示例#5
0
文件: forms.py 项目: stden/bonushouse
 def save(self):
     phone = self.cleaned_data.get('phone')
     form_subject = self.cleaned_data.get('subject')
     name = self.cleaned_data.get('name')
     suitable_time = self.cleaned_data.get('suitable_time')
     to = form_subject.email
     #Рендерим тему письма
     template = Template(get_settings_value('CALL_ME_EMAIL_SUBJECT'))
     context = Context({'subject': form_subject})
     subject = template.render(context).strip()
     #Рендерим сообщение
     template = Template(get_settings_value('CALL_ME_EMAIL_TEMPLATE'))
     context = Context({'phone':phone, 'subject':form_subject.title,'name':name,'suitable_time':suitable_time})
     message = template.render(context)
     send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [to,], True)
示例#6
0
文件: utils.py 项目: stden/bonushouse
def send_notification(email, context, settings_value, subject):
    notification_template = Template(get_settings_value(settings_value))
    notification_context = context
    message = notification_template.render(notification_context)
    subject = subject
    to = [email]
    send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, to, True)
示例#7
0
文件: forms.py 项目: stden/bonushouse
def get_call_me_subjects():
    result = []
    subjects = get_settings_value('CALL_ME_AVAILABLE_SUBJECTS')
    if subjects is not None:
        for subject in subjects:
            result.append((subject, subject))
    return result
示例#8
0
文件: views.py 项目: stden/bonushouse
def index(request):
    context = RequestContext(request)
    if request.method == 'POST':
        form = ContactUsForm(request.POST)
        if form.is_valid():
            subject = get_settings_value('CONTACTS_EMAIL_SUBJECT')
            to = get_settings_value('CONTACTS_EMAIL_ADDRESS')
            template = Template(get_settings_value('CONTACTS_EMAIL_TEMPLATE'))
            context = Context(form.cleaned_data)
            message = template.render(context)
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [to,], True)
            return redirect('contact.views.contact_form_success')
    else:
        form = ContactUsForm()
    context['form'] = form
    context['contacts_text'] = get_settings_value('CONTACTS_ADDRESS')
    return render_to_response('contact/contact_form.html', context)
示例#9
0
文件: utils.py 项目: stden/bonushouse
def get_auto_bonus_count(price):
    """Автоматический расчет количества бонусов на основе цены"""
    bonus_value = float(get_settings_value('BONUS_PRICE'))
    try:
        price = int(price)
    except ValueError:
        price = 0
    for treshold in AUTO_BONUS_COUNTS:
        if price <= treshold[0]:
            result = float(price) * (1.0-treshold[1]) / bonus_value
            result = round(result, 0)
            return math.floor(result)
    result = price * AUTO_BONUS_COUNTS[-1][1] / bonus_value
    return int(result)
示例#10
0
 def complete(self):
     """Вызывается, когда аукцион истек или достигнута цена выкупа"""
     winner_bid = self.get_latest_bid()
     self.completed_date = now()
     self.is_completed = True
     if winner_bid:
         winner_user = winner_bid.user
         if self.is_abonement():
             self.agreement_id = self.get_agreement_id()
             self.barcode.save('barcode.png', self.gen_barcode())
         elif self.is_additional_service():
             self.agreement_id = self.get_agreement_id()
         else:
             code = generate_code()
             self.coupon_code = code
         self.winner = winner_user
         notification_template = Template(get_settings_value('NOTIFICATIONS_COMPLETE_AUCTION'))
         notification_context = Context(
             {'LINK': settings.BASE_URL + str(reverse_lazy('cabinet_auctions')), 'AUCTION': self})
         message = notification_template.render(notification_context)
         subject = settings.ORDER_COMPLETE_SUBJECT
         send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.winner.email, ], True)
     self.is_completed = True
     self.save()
示例#11
0
文件: views.py 项目: stden/bonushouse
 def get_context_data(self, **kwargs):
     context = super(ReferFriendView, self).get_context_data(**kwargs)
     context['description_text'] = get_settings_value('REFER_FRIEND_DESCRIPTION_TEXT')
     return context