Ejemplo n.º 1
0
 def setUpClass(cls):
     cls.domain = 'forwarding-rules-dbaccessors'
     cls.forwarding_rules = [
         ForwardingRule(domain=cls.domain),
         ForwardingRule(domain=cls.domain),
         ForwardingRule(domain='other'),
     ]
     ForwardingRule.get_db().bulk_save(cls.forwarding_rules)
Ejemplo n.º 2
0
 def setUpClass(cls):
     cls.domain = 'forwarding-rules-dbaccessors'
     cls.forwarding_rules = [
         ForwardingRule(domain=cls.domain),
         ForwardingRule(domain=cls.domain),
         ForwardingRule(domain='other'),
     ]
     ForwardingRule.get_db().bulk_save(cls.forwarding_rules)
Ejemplo n.º 3
0
def add_forwarding_rule(request, domain, forwarding_rule_id=None):
    forwarding_rule = None
    if forwarding_rule_id is not None:
        forwarding_rule = ForwardingRule.get(forwarding_rule_id)
        if forwarding_rule.domain != domain:
            raise Http404

    if request.method == "POST":
        form = ForwardingRuleForm(request.POST)
        if form.is_valid():
            if forwarding_rule is None:
                forwarding_rule = ForwardingRule(domain=domain)
            forwarding_rule.forward_type = form.cleaned_data.get(
                "forward_type")
            forwarding_rule.keyword = form.cleaned_data.get("keyword")
            forwarding_rule.backend_id = form.cleaned_data.get("backend_id")
            forwarding_rule.save()
            return HttpResponseRedirect(
                reverse('list_forwarding_rules', args=[domain]))
    else:
        initial = {}
        if forwarding_rule is not None:
            initial["forward_type"] = forwarding_rule.forward_type
            initial["keyword"] = forwarding_rule.keyword
            initial["backend_id"] = forwarding_rule.backend_id
        form = ForwardingRuleForm(initial=initial)

    context = {
        "domain": domain,
        "form": form,
        "forwarding_rule_id": forwarding_rule_id,
    }
    return render(request, "sms/add_forwarding_rule.html", context)
Ejemplo n.º 4
0
def delete_forwarding_rule(request, domain, forwarding_rule_id):
    forwarding_rule = ForwardingRule.get(forwarding_rule_id)
    if forwarding_rule.domain != domain:
        raise Http404
    forwarding_rule.retire()
    return HttpResponseRedirect(reverse("list_forwarding_rules",
                                        args=[domain]))
Ejemplo n.º 5
0
def list_forwarding_rules(request, domain):
    forwarding_rules = ForwardingRule.view("sms/forwarding_rule", key=[domain], include_docs=True).all()
    
    context = {
        "domain" : domain,
        "forwarding_rules" : forwarding_rules,
    }
    return render(request, "sms/list_forwarding_rules.html", context)
Ejemplo n.º 6
0
def get_forwarding_rules_for_domain(domain):
    return ForwardingRule.view(
        "by_domain_doc_type_date/view",
        startkey=[domain, 'ForwardingRule'],
        endkey=[domain, 'ForwardingRule', {}],
        include_docs=True,
        reduce=False,
    ).all()
Ejemplo n.º 7
0
def add_forwarding_rule(request, domain, forwarding_rule_id=None):
    forwarding_rule = None
    if forwarding_rule_id is not None:
        forwarding_rule = ForwardingRule.get(forwarding_rule_id)
        if forwarding_rule.domain != domain:
            raise Http404
    
    if request.method == "POST":
        form = ForwardingRuleForm(request.POST)
        if form.is_valid():
            if forwarding_rule is None:
                forwarding_rule = ForwardingRule(domain=domain)
            forwarding_rule.forward_type = form.cleaned_data.get("forward_type")
            forwarding_rule.keyword = form.cleaned_data.get("keyword")
            forwarding_rule.backend_id = form.cleaned_data.get("backend_id")
            forwarding_rule.save()
            return HttpResponseRedirect(reverse('list_forwarding_rules', args=[domain]))
    else:
        initial = {}
        if forwarding_rule is not None:
            initial["forward_type"] = forwarding_rule.forward_type
            initial["keyword"] = forwarding_rule.keyword
            initial["backend_id"] = forwarding_rule.backend_id
        form = ForwardingRuleForm(initial=initial)
    
    context = {
        "domain" : domain,
        "form" : form,
        "forwarding_rule_id" : forwarding_rule_id,
    }
    return render(request, "sms/add_forwarding_rule.html", context)
Ejemplo n.º 8
0
def list_forwarding_rules(request, domain):
    forwarding_rules = ForwardingRule.view("sms/forwarding_rule",
                                           key=[domain],
                                           include_docs=True).all()

    context = {
        "domain": domain,
        "forwarding_rules": forwarding_rules,
    }
    return render(request, "sms/list_forwarding_rules.html", context)
Ejemplo n.º 9
0
def forwarding_handler(v, text):
    rules = ForwardingRule.view("sms/forwarding_rule", key=[v.domain], include_docs=True).all()
    text_words = text.upper().split()
    keyword_to_match = text_words[0] if len(text_words) > 0 else ""
    for rule in rules:
        matches_rule = False
        if rule.forward_type == FORWARD_ALL:
            matches_rule = True
        elif rule.forward_type == FORWARD_BY_KEYWORD:
            matches_rule = keyword_to_match == rule.keyword.upper()

        if matches_rule:
            send_sms_with_backend(v.domain, "+%s" % v.phone_number, text, rule.backend_id)
            return True
    return False
Ejemplo n.º 10
0
def forwarding_handler(v, text):
    rules = ForwardingRule.view("sms/forwarding_rule",
                                key=[v.domain],
                                include_docs=True).all()
    text_words = text.upper().split()
    keyword_to_match = text_words[0] if len(text_words) > 0 else ""
    for rule in rules:
        matches_rule = False
        if rule.forward_type == FORWARD_ALL:
            matches_rule = True
        elif rule.forward_type == FORWARD_BY_KEYWORD:
            matches_rule = (keyword_to_match == rule.keyword.upper())

        if matches_rule:
            send_sms_with_backend(v.domain, "+%s" % v.phone_number, text,
                                  rule.backend_id)
            return True
    return False
Ejemplo n.º 11
0
def delete_forwarding_rule(request, domain, forwarding_rule_id):
    forwarding_rule = ForwardingRule.get(forwarding_rule_id)
    if forwarding_rule.domain != domain or forwarding_rule.doc_type != "ForwardingRule":
        raise Http404
    forwarding_rule.retire()
    return HttpResponseRedirect(reverse("list_forwarding_rules", args=[domain]))
Ejemplo n.º 12
0
 def tearDownClass(cls):
     ForwardingRule.get_db().bulk_delete(cls.forwarding_rules)
Ejemplo n.º 13
0
 def tearDownClass(cls):
     ForwardingRule.get_db().bulk_delete(cls.forwarding_rules)
     super(DBAccessorsTest, cls).tearDownClass()
Ejemplo n.º 14
0
 def tearDownClass(cls):
     ForwardingRule.get_db().bulk_delete(cls.forwarding_rules)
     super(DBAccessorsTest, cls).tearDownClass()
Ejemplo n.º 15
0
 def tearDownClass(cls):
     ForwardingRule.get_db().bulk_delete(cls.forwarding_rules)