Ejemplo n.º 1
0
Archivo: views.py Proyecto: mjtorn/prkl
def incoming_message(request):
    """SMS and all
    """

    ctx = mediator_views.incoming_message(request)

    if ctx["sms"] is None:
        ret = mediator_utils.create_error(u"Tänään jokin meni pieleen viestisi kanssa prkl", None, "system")
    elif ctx["sms_form"].cleaned_data["type"] == "mms":
        mms_handler = handlers.MmsHandler(ctx)
        mms = mms_handler.sms
        # Do it right, do it right
        if mms_handler.command == "tänään":
            ## Slight preparation
            # Consider anonymous
            user = auth_models.AnonymousUser()

            # Mandatory tag(s)
            tag_obs = models.Tag.objects.filter(is_default=True).values("id", "name")
            tags = [(t["id"], t["name"]) for t in tag_obs]

            # This is the chosen one
            tag = tag_obs.get(name="Satunnainen")

            try:
                new_prkl = mms_handler.tanaan(user, tags, tag["id"], forms.SubmitPrklForm)
                ret = mediator_utils.create_return(u"MMS-Prkl lisätty", mms, price="025")
            except mms_handler.MmsHandlerException, e:
                ret = mediator_utils.create_error(unicode(e), sms, "system")
Ejemplo n.º 2
0
Archivo: views.py Proyecto: mjtorn/prkl
    else:
        sms_handler = handlers.SmsHandler(ctx)
        sms = sms_handler.sms
        # These two are close enough to each other that we can do this...
        if sms_handler.command == "jrprkl" or sms_handler.command == "prkl":
            if len(sms_handler.argument_list) == 2:
                vip_word = sms_handler.argument_list[0]
                user_id = sms_handler.argument_list[1]

                try:
                    # ... and this to succeed
                    if sms_handler.command == "jrprkl":
                        period, price = sms_handler.jrprkl(vip_word, user_id)
                    else:
                        period, price = sms_handler.prkl(vip_word, user_id)
                    ret = mediator_utils.create_return(u"Tänään sait %s vippiä prkl" % vip_word, sms, price=price)
                except sms_handler.InvalidVipWord, e:
                    ret = mediator_utils.create_error(unicode(e), sms_handler.sms, "user")
                except sms_handler.InvalidUserId, e:
                    ret = mediator_utils.create_error(unicode(e), sms_handler.sms, "user")

            else:
                ret = mediator_utils.create_error(u"Viestin muotoa ei tunnistettu", sms, "user")

        elif sms_handler.command == u"tänään":
            ## Slight preparation
            # Consider anonymous
            user = auth_models.AnonymousUser()

            # Mandatory tag(s)
            tag_obs = models.Tag.objects.filter(is_default=True).values("id", "name")