def send_verification_passed_email(self, email, company_rek_id):
        action = create_action_id(actions.INVOICE_VERIFICATION_PASSED, company_rek_id)

        plain_text = render_to_string('mails/verified_through_invoice.txt')
        html = render_to_string('mails/verified_through_invoice.html')

        notification_manager.add(action, email, 'Ваша компания успешно прошла верификацию в Реквизитке', plain_text, html, 1)
示例#2
0
    def test_deferred_notifications_task_send_two(self):
        action = create_action_id(actions.CONFIRM_NEW_EMPLOYEE, 123)
        notification_manager.add(action, '*****@*****.**', 'subj',
                                 'text', 'html', 0)
        notification_manager.add(action, '*****@*****.**', 'subj2',
                                 'text', 'html', 0)

        notifications = Notification.objects.get({
            'is_sent': False,
            'send_date': {
                '$lte': timezone.now()
            }
        })
        self.assertEqual(len(notifications), 2)

        mail.outbox = []

        task = DeferredNotificationsTask()
        task.execute()

        notifications = Notification.objects.get({
            'is_sent': False,
            'send_date': {
                '$lte': timezone.now()
            }
        })
        self.assertEqual(len(notifications), 0)
        self.assertEqual(len(mail.outbox), 2)
        notifications = Notification.objects.get({'is_sent': True})
        self.assertEqual(len(notifications), 2)
示例#3
0
    def verify(self, brand_name=None, description=None):
        brand_name_filled = (self.brand_name
                             and len(self.brand_name)) or (brand_name
                                                           and len(brand_name))
        description_filled = (self.description and len(
            self.description)) or (description and len(description))
        if not brand_name_filled:
            raise Exception(
                "Can't change state to verified. Required data is not filled.")

        if brand_name and len(brand_name):
            self.brand_name = brand_name

        if description and len(description):
            self.description = description

        self.objects.update({'_id': self._id}, {
            '$set': {
                'account_status': self.account_status,
                'brand_name': self.brand_name,
                'description': self.description
            }
        })
        notification_manager.remove(
            create_action_id(actions.VERIFICATION_PERIODIC, unicode(self._id)))
示例#4
0
    def post(self, request):
        form = FeedbackForm(request.POST, request.FILES)
        if form.is_valid():
            user_email = form.cleaned_data['email']
            msg = form.cleaned_data['msg']

            if form.cleaned_data['extra_field'] == get_token(request):
                mail_to = '*****@*****.**'

                browser_info = u'IP адрес: %s, браузер: %s, дата: %s' % (request.META['HTTP_HOST'], request.META['HTTP_USER_AGENT'], date.today().strftime("%d.%m.%Y"))
                user_info=''
                if request.user.is_authenticated():
                    user_info=u'Пользователь ID:%s %s' % (unicode(request.user.id), request.user.email)

                plain_text = render_to_string('mail/feedback.txt', { 'text':msg,
                                                                     'user_email':user_email,
                                                                     'browser_info':browser_info,
                                                                     'user_info':user_info },
                                              context_instance=RequestContext(request))

                subject, from_email, to, bcc = 'Сообщение в службу поддержки Rekvizitka.Ru', settings.EMAIL_HOST_USER, [mail_to,],[]

                action = create_action_id(FEEDBACK_SENT, randint(1, 10000))
                notification_manager.add(action, mail_to, subject, plain_text, plain_text, 10)

                result_json = simplejson.dumps({'error' : False})
                return HttpResponse(mark_safe(result_json))

        result_json = simplejson.dumps({'error' : True})
        return HttpResponse(mark_safe(result_json))
示例#5
0
    def testRequestRecommendation(self):
        message = "Could you please recommend me."
        self.register(verified=False)
        self.login()
        mail.outbox = []
        companies = self.register_companies(3)
        requested_company = companies[0]
        rek_id = requested_company.rek_id
        response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : rek_id})
        self.assertEqual(response.status_code, 400) # no required parameter 'message'

        response = self.client.post('/recommendations/ask/%(rek_id)s/' % {'rek_id' : rek_id}, {'message' : message})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 0)
        self.assertEqual(RecommendationRequest.objects.count(), 1)

        recommendation = RecommendationRequest.objects.get({})[0]
        self.assertEqual(recommendation.requester, self.company._id)
        self.assertEqual(recommendation.recipient, requested_company._id)
        self.assertEqual(recommendation.message, message)
        self.assertEqual(recommendation.status, RecommendationStatusEnum.RECEIVED)
        self.assertEqual(recommendation.viewed, False)
        self.assertTrue(timezone.now() - datetime.timedelta(seconds=10) < recommendation.send_date < timezone.now())

        self.assertIsNotNone(recommendation)
        action = create_action_id(RECOMMENDATION_ASKED, recommendation._id)
        notification = Notification.objects.get_one({'action' : action})
        self.assertIsNotNone(notification)
示例#6
0
    def send_email(self, user, link_id):
        email = user.email

        mail_context = {'SITE_DOMAIN_NAME' : settings.SITE_DOMAIN_NAME, 'link_id' : unicode(link_id)}

        text = render_to_string('mails/password_reset.txt', dictionary=mail_context)
        html = render_to_string('mails/password_reset.html', dictionary=mail_context)

        action_id = create_action_id(actions.PASSWORD_RECOVERY, email)
        subject = 'Восстановление пароля на Rekvizitka.Ru'
        notification_manager.add(action_id, email, subject, text, html, 0)
示例#7
0
    def send_rotten_invoice_notification(self, email, invoice_number, invoice_name, amount, date):
        action = create_action_id(actions.INVOICE_ROTTEN, invoice_number)

        data = {'name' : invoice_name,
                'number' : unicode(invoice_number),
                'amount' : unicode(amount),
                'date' : date.strftime('%d-%m-%Y')}

        plain_text = render_to_string('mails/invoice_rotten.txt', dictionary=data)
        html = render_to_string('mails/invoice_rotten.html', dictionary=data)

        notification_manager.add(action, email, u'Окончание срока действия счета', plain_text, html, 1)
示例#8
0
    def send_invitation_message(self, email, invite_id, message, brand_name, cookie_code):
        mail_context = {'text' : message,
                        'brand_name' : brand_name,
                        'join_url' : u"http://%s/invites/join/%s/" % (settings.SITE_DOMAIN_NAME, cookie_code),
                        'main_page_link' : u"http://%s/" % settings.SITE_DOMAIN_NAME }

        subject = 'Вас пригласили в деловую сеть Реквизитка'

        plain_text = render_to_string('mail/invite.txt', dictionary=mail_context)
        html = render_to_string('mail/invite.html', dictionary=mail_context)

        action = create_action_id(INVITATION, invite_id)
        notification_manager.add(action, email, subject, plain_text, html, 0)
示例#9
0
    def send_deposit_transaction_msg(self, email, transaction_id, amount):
        action = create_action_id(actions.DEPOSIT_TRANSACTION, transaction_id)

        data = {
            'amount': unicode(amount),
            'SITE_DOMAIN_NAME': settings.SITE_DOMAIN_NAME
        }
        plain_text = render_to_string('mails/popolnenie_deposita.txt', data)
        html = render_to_string('mails/popolnenie_deposita.html', data)

        notification_manager.add(action, email,
                                 'Начисление средств на депозит', plain_text,
                                 html, 1)
示例#10
0
    def send_rec_message(self, email, message, rec_id, recipient_rek_id, requester_brand_name):
        mail_context = {'text': message,
                        'company_name' : requester_brand_name,
                        'our_recommendations_url' : "http://%s%s" % (settings.SITE_DOMAIN_NAME,
                                                                     reverse('we_recommend_view', kwargs={'code' : recipient_rek_id}))}
        plain_text_template = get_template('mails/recommended.txt')
        plain_text = plain_text_template.render(Context(mail_context))
        html_template = get_template('mails/recommended.html')
        html = html_template.render(Context(mail_context))
        subject = 'Запрос рекомендации на сайте Rekvizitka.Ru'

        action = create_action_id(RECOMMENDATION_ASKED, rec_id)
        notification_manager.add(action, email, subject, plain_text, html, 120)
示例#11
0
    def execute(self):
        print >> sys.stdout, '%s Executing UnreadDialogNotificationTask' % unicode(datetime.now())

        search_ts = get_cts() - cts_from_timedelta(timedelta(hours = 3))
        ts_min = search_ts - cts_from_timedelta(timedelta(days = 3))
        result = self.make_employee_op_collection(search_ts, ts_min)
        if result['ok'] != 1:
            print >> sys.stderr, u'Failed to perform map_reduce during checking unread messages: %s' % repr(result)
            return

        result = self.make_employee_last_ops()
        if result['ok'] != 1:
            print >> sys.stderr, u'Failed to perform map_reduce step 2 during checking unread messages: %s' % repr(result)
            return

        unread_dialogs_cursor = self.find_unsent_messages()

        for unread_data in unread_dialogs_cursor:
            try:
                employee = unread_data['_id']
                if self.is_online(employee):
                    mark_as_sent = Operation({'owner' : employee,
                                              'operation_type' : OperationTypeEnum.OT_EMAIL_SENT,
                                              'data' : {'fake' : True},
                                              'listeners' : [employee],
                                              'is_service' : True})
                    mark_as_sent.save()
                    continue
                email = self.get_employee_email(employee)

                if not email or not is_valid_email(email):
                    continue

                action = create_action_id(actions.UNREAD_DIALOGS, employee)
                subj = u'Непрочитанные сообщения в Реквизитке'

                data = {'SITE_DOMAIN_NAME' : settings.SITE_DOMAIN_NAME}
                text = render_to_string('mail/chat/unread_dialogs.txt', data)
                html = render_to_string('mail/chat/unread_dialogs.html', data)

                notification_manager.remove(action)
                notification_manager.add(action, email, subj, text, html, settings.UNREAD_MESSAGE_EMAIL_NOTIFY_TIMEOUT)
                mark_as_sent = Operation({'owner' : employee,
                                          'operation_type' : OperationTypeEnum.OT_EMAIL_SENT,
                                          'data' : {},
                                          'listeners' : [employee],
                                          'is_service' : True})
                mark_as_sent.save()
            except Exception:
                pass
示例#12
0
    def generate_verification_letters(self, email, company_id):
        letters_count = SettingsManager.get_property('verifylettercount')
        interval_days = SettingsManager.get_property('verifyletterdelaydays')
        subject = u"Пройдите верификацию вашей компании в Реквизитке"

        mail_context = {'SITE_DOMAIN_NAME' : settings.SITE_DOMAIN_NAME}

        text = render_to_string('mails/periodic_verify_letter.txt', dictionary=mail_context)
        html = render_to_string('mails/periodic_verify_letter.html', dictionary=mail_context)

        action_id = create_action_id(actions.VERIFICATION_PERIODIC, unicode(company_id))
        for day in xrange(letters_count):
            delay = interval_days * (day + 1) * 60 * 24
            notification_manager.add(action_id, email, subject, text, html, delay)
示例#13
0
def send_staff_confirmation_email(email, sender, code):
    mail_context = {'code': code,
                    'sender': sender.full_name,
                    'company' : sender.company.get_name()}

    plain_text_template = get_template('mails/staff_confirm.txt')
    html_template = get_template('mails/staff_confirm.html')

    plain_text = plain_text_template.render(Context(mail_context))
    html = html_template.render(Context(mail_context))

    subject = u'Вас добавили в сотрудники компании %s в деловой сети Rekvizitka.Ru' % mail_context['company']

    action = create_action_id(actions.CONFIRM_NEW_EMPLOYEE, code)
    notification_manager.add(action, email, subject, plain_text, html, 10)
示例#14
0
    def test_deferred_notifications_task_send_one(self):
        action = create_action_id(actions.CONFIRM_NEW_EMPLOYEE, 123)
        notification_manager.add(action, '*****@*****.**', 'subj', 'text', 'html', 0)

        notifications = Notification.objects.get({'is_sent': False, 'send_date': {'$lte': timezone.now()}})
        self.assertEqual(len(notifications), 1)

        mail.outbox = []

        task = DeferredNotificationsTask()
        task.execute()

        notifications = Notification.objects.get({'is_sent': False, 'send_date': {'$lte': timezone.now()}})
        self.assertEqual(len(notifications), 0)
        self.assertEqual(len(mail.outbox), 1)
示例#15
0
    def send_email(self, user, link_id):
        email = user.email

        mail_context = {
            'SITE_DOMAIN_NAME': settings.SITE_DOMAIN_NAME,
            'link_id': unicode(link_id)
        }

        text = render_to_string('mails/password_reset.txt',
                                dictionary=mail_context)
        html = render_to_string('mails/password_reset.html',
                                dictionary=mail_context)

        action_id = create_action_id(actions.PASSWORD_RECOVERY, email)
        subject = 'Восстановление пароля на Rekvizitka.Ru'
        notification_manager.add(action_id, email, subject, text, html, 0)
示例#16
0
    def verify(self, brand_name=None, description=None):
        brand_name_filled = (self.brand_name and len(self.brand_name)) or (brand_name and len(brand_name))
        description_filled = (self.description and len(self.description)) or (description and len(description))
        if not brand_name_filled:
            raise Exception("Can't change state to verified. Required data is not filled.")

        if brand_name and len(brand_name):
            self.brand_name = brand_name

        if description and len(description):
            self.description = description

        self.objects.update({'_id' : self._id}, {'$set' : {
            'account_status' : self.account_status,
            'brand_name' : self.brand_name,
            'description' : self.description
        }})
        notification_manager.remove(create_action_id(actions.VERIFICATION_PERIODIC, unicode(self._id)))
示例#17
0
    def test_deferred_notifications_task_send_timeout(self):
        action = create_action_id(actions.CONFIRM_NEW_EMPLOYEE, 123)
        notification_manager.add(action, '*****@*****.**', 'subj', 'text', 'html', 10)
        notification_manager.add(action, '*****@*****.**', 'subj2', 'text', 'html', 10)

        notifications = Notification.objects.get({'is_sent': False})
        self.assertEqual(len(notifications), 2)

        mail.outbox = []

        task = DeferredNotificationsTask()
        task.execute()

        notifications = Notification.objects.get({'is_sent': False})
        self.assertEqual(len(notifications), 2)
        self.assertEqual(len(mail.outbox), 0)
        notifications = Notification.objects.get({'is_sent': True})
        self.assertEqual(len(notifications), 0)
示例#18
0
def send_staff_confirmation_email(email, sender, code):
    mail_context = {
        'code': code,
        'sender': sender.full_name,
        'company': sender.company.get_name()
    }

    plain_text_template = get_template('mails/staff_confirm.txt')
    html_template = get_template('mails/staff_confirm.html')

    plain_text = plain_text_template.render(Context(mail_context))
    html = html_template.render(Context(mail_context))

    subject = u'Вас добавили в сотрудники компании %s в деловой сети Rekvizitka.Ru' % mail_context[
        'company']

    action = create_action_id(actions.CONFIRM_NEW_EMPLOYEE, code)
    notification_manager.add(action, email, subject, plain_text, html, 10)
示例#19
0
    def generate_verification_letters(self, email, company_id):
        letters_count = SettingsManager.get_property('verifylettercount')
        interval_days = SettingsManager.get_property('verifyletterdelaydays')
        subject = u"Пройдите верификацию вашей компании в Реквизитке"

        mail_context = {'SITE_DOMAIN_NAME': settings.SITE_DOMAIN_NAME}

        text = render_to_string('mails/periodic_verify_letter.txt',
                                dictionary=mail_context)
        html = render_to_string('mails/periodic_verify_letter.html',
                                dictionary=mail_context)

        action_id = create_action_id(actions.VERIFICATION_PERIODIC,
                                     unicode(company_id))
        for day in xrange(letters_count):
            delay = interval_days * (day + 1) * 60 * 24
            notification_manager.add(action_id, email, subject, text, html,
                                     delay)
示例#20
0
    def send_rotten_invoice_notification(self, email, invoice_number,
                                         invoice_name, amount, date):
        action = create_action_id(actions.INVOICE_ROTTEN, invoice_number)

        data = {
            'name': invoice_name,
            'number': unicode(invoice_number),
            'amount': unicode(amount),
            'date': date.strftime('%d-%m-%Y')
        }

        plain_text = render_to_string('mails/invoice_rotten.txt',
                                      dictionary=data)
        html = render_to_string('mails/invoice_rotten.html', dictionary=data)

        notification_manager.add(action, email,
                                 u'Окончание срока действия счета', plain_text,
                                 html, 1)
示例#21
0
    def post(self, request):
        form = FeedbackForm(request.POST, request.FILES)
        if form.is_valid():
            user_email = form.cleaned_data['email']
            msg = form.cleaned_data['msg']

            if form.cleaned_data['extra_field'] == get_token(request):
                mail_to = '*****@*****.**'

                browser_info = u'IP адрес: %s, браузер: %s, дата: %s' % (
                    request.META['HTTP_HOST'], request.META['HTTP_USER_AGENT'],
                    date.today().strftime("%d.%m.%Y"))
                user_info = ''
                if request.user.is_authenticated():
                    user_info = u'Пользователь ID:%s %s' % (unicode(
                        request.user.id), request.user.email)

                plain_text = render_to_string(
                    'mail/feedback.txt', {
                        'text': msg,
                        'user_email': user_email,
                        'browser_info': browser_info,
                        'user_info': user_info
                    },
                    context_instance=RequestContext(request))

                subject, from_email, to, bcc = 'Сообщение в службу поддержки Rekvizitka.Ru', settings.EMAIL_HOST_USER, [
                    mail_to,
                ], []

                action = create_action_id(FEEDBACK_SENT, randint(1, 10000))
                notification_manager.add(action, mail_to, subject, plain_text,
                                         plain_text, 10)

                result_json = simplejson.dumps({'error': False})
                return HttpResponse(mark_safe(result_json))

        result_json = simplejson.dumps({'error': True})
        return HttpResponse(mark_safe(result_json))
示例#22
0
    def post(self, request, recommendation_id):
        # mustdo: add transaction
        company = request.company
        try:
            recommendation_id_obj = bson.ObjectId(recommendation_id)
        except Exception:
            return HttpResponse(simplejson.dumps({'error' : True,
                                                  'error_message' : "Запрос не найден."}),
                mimetype='application/javascript')

        recommendation = RecommendationRequest.objects.get_one({'_id' : recommendation_id_obj,
                                                                'recipient' : company._id,
                                                                'status' : RecommendationStatusEnum.RECEIVED})

        if not recommendation:
            return HttpResponse(simplejson.dumps({'error' : True,
                                                  'error_message' : "Запрос не найден."}),
                                                   mimetype='application/javascript')

        RecommendationRequest.objects.update({'_id' : recommendation_id_obj},
                                             {'$set' : {'status' : RecommendationStatusEnum.ACCEPTED}})

        company_to_recommend = recommendation.requester
        Company.objects.update({'_id' : recommendation.recipient}, {'$pull' : {'rec_requesters' : company_to_recommend}})
        accepted_requests_count = RecommendationRequest.objects.count({'status' : RecommendationStatusEnum.ACCEPTED,
                                                                       'requester' : company_to_recommend})
        if accepted_requests_count >= SettingsManager.get_property('rnes'):
            requester_company = Company.objects.get_one({'_id' : company_to_recommend})
            if requester_company.account_status == CompanyAccountStatus.JUST_REGISTERED:
                Company.objects.update({'_id' : company_to_recommend},
                                       {'$set' : {'account_status' : CompanyAccountStatus.VERIFIED}})
                notification_manager.remove(create_action_id(actions.VERIFICATION_PERIODIC, unicode(company_to_recommend)))

                self.send_accepted_message(recommendation.requester_email, company.brand_name)

        return HttpResponse(simplejson.dumps({'error' : False,
                                              'success_message' : "Рекомендация подтверждена."}),
                                               mimetype='application/javascript')