Ejemplo n.º 1
0
def get_question(request):
    """Returns question data for bot"""

    obj = SiteConfiguration.get_solo().bot_question

    if obj is None:
        return JsonResponse({
            'status': 'fail',
            'message': 'no question defined'
        })

    data = {'status': 'ok'}
    data['data'] = {
        'person_name':
        obj.person.name,
        'greeting':
        obj.person.greeting,
        'question':
        obj.title,
        'answers': [{
            'id': x.pk,
            'answer': x.title,
            'description': x.description,
            'type': x.answer_type
        } for x in obj.answers.order_by('answer_type')]
    }
    return JsonResponse(data)
Ejemplo n.º 2
0
 def setUp(self):
     self.template = Template(
         '{% load solo_tags %}'
         '{% get_solo "tests.SiteConfiguration" as site_config  %}'
         '{{ site_config.site_name }}'
     )
     self.cache = get_cache('default')
     self.cache_key = SiteConfiguration.get_cache_key()
     self.cache.clear()
     SiteConfiguration.objects.all().delete()
Ejemplo n.º 3
0
def on_customer_create(sender, instance, **kwargs):
    if instance.id or instance.card:
        return
    conf = SiteConfiguration.get_solo()
    existing_cards = set(Customer.objects.existing_cards())
    for card in conf.get_cards_range():
        if card not in existing_cards:
            instance.card = card
            break
    if Customer.objects.avail_cards_count() <= conf.lower_limit:
        conf.card_end = F('card_end') + conf.increase_by
        conf.save()
Ejemplo n.º 4
0
def on_email_task_save(sender, instance, created, **kwargs):
    if created:
        try:
            tpl = Text.objects.active().get(place=Text.PLACE.EMAIL)
        except Text.DoesNotExist:
            return
        ctx = tpl.get_template_context(instance.customer)
        text = tpl.render(data=ctx)
        ctx['msg'] = text
        ctx['token'] = instance.token
        ctx['site_url'] = settings.SITE_URL
        tpl = loader.get_template('email_card.html')
        text = tpl.render(Context(ctx))
        conf = SiteConfiguration.get_solo()
        msg = EmailMultiAlternatives(subject=conf.email_subject,
                                     body=text,
                                     to=[instance.customer.email],
                                     from_email=settings.DEFAULT_FROM_EMAIL)
        msg.attach_alternative(text, 'text/html')
        card_img = MIMEImage(
            open('content/static/img/card-h.png', 'rb').read())
        card_img.add_header('Content-ID', '<card_image>')
        logo = MIMEImage(open('content/static/img/logo.png', 'rb').read())
        logo.add_header('Content-ID', '<logo>')
        bac_logo = MIMEImage(
            open('content/static/img/BAC_Logo.png', 'rb').read())
        bac_logo.add_header('Content-ID', '<bac_logo>')
        msg.attach(card_img)
        msg.attach(logo)
        msg.attach(bac_logo)
        try:
            msg.send(fail_silently=False)
        except:
            instance.customer.email_status = EmailStatus.FAILED
        else:
            instance.customer.email_status = EmailStatus.SENT
            instance.when_sent = timezone.now()
            instance.save()
        finally:
            instance.customer.save()
    else:
        if instance.when_opened \
                and instance.customer.email_status != EmailStatus.OPENED:
            instance.customer.email_status = EmailStatus.OPENED
            instance.customer.save()
Ejemplo n.º 5
0
 def get_card_name(self):
     if self.card is None:
         return ''
     conf = SiteConfiguration.get_solo()
     letters = conf.card_letters
     return '{0} {1}'.format(letters, self.card)
Ejemplo n.º 6
0
 def avail_cards_count(self):
     conf = SiteConfiguration.get_solo()
     exist = self.has_cards(card__gte=conf.card_start,
                            card__lte=conf.card_end).count()
     return conf.get_cards_count() - exist
Ejemplo n.º 7
0
 def get_setting(self, name):
     try:
         return getattr(settings, name)
     except:
         return getattr(SiteConfiguration.get_solo(),
                        name.replace('SOCIAL_AUTH_', '').lower())
 def get_setting(self, name):
     try:
         return getattr(settings, name)
     except:
         return getattr(SiteConfiguration.get_solo(), name.replace('SOCIAL_AUTH_','').lower())