コード例 #1
0
ファイル: repair.py プロジェクト: MarijkeDM/oca-backend
def _repair_order_received(service_user, message_flow_run_id, member, steps, end_id, end_message_flow_id, parent_message_key,
                   tag, result_key, flush_id, flush_message_flow_id, service_identity, user_details):
    from solutions.common.bizz.messaging import send_inbox_forwarders_message


    logging.info("_flow_member_result_repair_order: \n %s" % steps)

    remarks = _get_value(steps[0], u'message_remarks')
    if steps[1].answer_id == u"positive":
        picture_url = _get_value(steps[1], u'message_picture')
    else:
        picture_url = None

    sln_settings = get_solution_settings(service_user)

    logging.info("Saving repair order from %s" % user_details[0].email)
    service_identity_user = create_service_identity_user_wo_default(service_user, service_identity)
    o = SolutionRepairOrder(parent=parent_key_unsafe(service_identity_user, sln_settings.solution))
    o.description = remarks
    o.sender = SolutionUser.fromTO(user_details[0])
    o.timestamp = steps[1].received_timestamp
    o.status = SolutionRepairOrder.STATUS_RECEIVED
    o.picture_url = picture_url
    o.user = user_details[0].toAppUser() if user_details else None

    msg = common_translate(sln_settings.main_language, SOLUTION_COMMON, 'if-repair-order-received',
                           remarks=remarks)

    message = create_solution_inbox_message(service_user, service_identity, SolutionInboxMessage.CATEGORY_REPAIR, None, False, user_details, steps[1].received_timestamp, msg, True, [picture_url] if picture_url else [])
    o.solution_inbox_message_key = message.solution_inbox_message_key
    o.put()
    message.category_key = unicode(o.key())
    message.put()

    sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, service_identity)

    sm_data = []
    sm_data.append({u"type": u"solutions.common.repair_orders.update"})
    sm_data.append({u"type": u"solutions.common.messaging.update",
                 u"message": serialize_complex_value(SolutionInboxMessageTO.fromModel(message, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False)})

    send_message(service_user, sm_data, service_identity=service_identity)

    attachments = []
    if picture_url:
        att = AttachmentTO()
        att.content_type = AttachmentTO.CONTENT_TYPE_IMG_JPG
        att.download_url = picture_url
        att.name = common_translate(sln_settings.main_language, SOLUTION_COMMON, u'picture')
        att.size = 0
        attachments = [att]

    app_user = user_details[0].toAppUser()

    send_inbox_forwarders_message(service_user, service_identity, app_user, msg, {
            'if_name': user_details[0].name,
            'if_email':user_details[0].email
        }, message_key=message.solution_inbox_message_key, attachments=attachments, reply_enabled=message.reply_enabled)
コード例 #2
0
def _resolve_voucher(service_user, service_identity, url):
    '''Lookup the provided URL. Can be a city voucher. Else it will be treated as a custom loyalty card.'''

    # 1/ Check if a custom loyalty card already exists for this URL
    custom_loyalty_card = CustomLoyaltyCard.get_by_url(url)
    if custom_loyalty_card and custom_loyalty_card.app_user:
        human_user, app_id = get_app_user_tuple(custom_loyalty_card.app_user)
        return _create_resolve_result(CustomLoyaltyCard.TYPE, url,
                                      human_user.email(), app_id)

    # 2/ Check if it's a city voucher
    si = system.get_identity(service_identity)
    poke_information, city_service_user = _find_voucher(url, si.app_ids)
    if not poke_information or not poke_information.tag.startswith(
            POKE_TAG_CITY_VOUCHER_QR):
        # 2.1/ Not a city voucher
        logging.debug(
            'Unknown QR code scanned: %s. Loyalty device will create custom paper loyalty card.',
            url)
        user_info = GetUserInfoResponseTO()
        user_info.app_id = user_info.email = user_info.name = user_info.qualifiedIdentifier = u'dummy'
        return _create_resolve_result(u'unknown', url, u'dummy', u'dummy')

    # 2.2/ It is a city voucher
    data = json.loads(poke_information.tag[len(POKE_TAG_CITY_VOUCHER_QR):])
    ancestor_key = SolutionCityVoucher.create_parent_key(data["app_id"])
    sln_city_voucher = SolutionCityVoucher.get_by_id(data["voucher_id"],
                                                     ancestor_key)
    if not sln_city_voucher:
        logging.debug("Could not find city voucher for data: %s", data)
        raise Exception("Could not find city voucher")

    sln_settings = get_solution_settings(service_user)

    r_dict = dict()
    r_dict["type"] = SolutionCityVoucher.TYPE
    r_dict["app_id"] = sln_city_voucher.app_id
    r_dict["voucher_id"] = sln_city_voucher.key().id()
    r_dict["uid"] = sln_city_voucher.uid
    if sln_city_voucher.activated:
        if sln_city_voucher.expired:
            raise BusinessException(
                common_translate(sln_settings.main_language, SOLUTION_COMMON,
                                 'Voucher has expired'))
        r_dict["status"] = 1
        r_dict["value"] = sln_city_voucher.value
        r_dict["redeemed_value"] = sln_city_voucher.redeemed_value
    elif service_user == city_service_user:
        r_dict["status"] = 2
    else:
        raise BusinessException(
            common_translate(sln_settings.main_language, SOLUTION_COMMON,
                             'Voucher not activated'))

    return r_dict
コード例 #3
0
ファイル: service.py プロジェクト: MarijkeDM/oca-backend
def _send_denied_signup_email(city_customer, signup, lang, reason):
    subject = common_translate(city_customer.language,
                               SOLUTION_COMMON,
                               u'signup_request_denied_by_city',
                               city=city_customer.name)
    message = common_translate(city_customer.language,
                               SOLUTION_COMMON,
                               u'signup_request_denial_reason',
                               reason=reason)

    city_from = '%s <%s>' % (city_customer.name, city_customer.user_email)
    send_mail(city_from, signup.customer_email, subject, message)
コード例 #4
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
    def get(self):
        data_dict, app_user = self.get_user_info()
        if not data_dict or not app_user:
            language = self.request.get("language", DEFAULT_LANGUAGE)
            title = common_translate(language, SOLUTION_COMMON, u'Error')
            text = common_translate(language, SOLUTION_COMMON, u"error-occured-unknown-try-again")
        else:
            azzert(data_dict['a'] == "loyalty_no_mobiles_lottery_winner")
            service_email = data_dict['e']
            service_identity_user = users.User(service_email)
            service_user, service_identity = get_service_identity_tuple(service_identity_user)
            user_profile = db.get(UserProfile.createKey(app_user))
            if user_profile:
                language = self.request.get("language", user_profile.language)
                if redeem_lottery_winner(service_user, service_identity, data_dict['mk'], app_user, user_profile.name):
                    title = common_translate(language, SOLUTION_COMMON, u'Success')
                    text = common_translate(language, SOLUTION_COMMON, u'loyalty-lottery-loot-receive')
                else:
                    title = common_translate(language, SOLUTION_COMMON, u'Error')
                    text = common_translate(language, SOLUTION_COMMON, u'Unfortunately you have not confirmed on time and lost your chance')
            else:
                language = self.request.get("language", DEFAULT_LANGUAGE)
                title = common_translate(language, SOLUTION_COMMON, u'Error')
                text = common_translate(language, SOLUTION_COMMON, u"error-occured-unknown-try-again")

        params = {
            'title': title,
            'text': text
        }

        jinja_template = JINJA_ENVIRONMENT.get_template('pages/loyalty_title_text.html')
        self.response.out.write(jinja_template.render(params))
コード例 #5
0
def solution_voucher_pin_activate(service_user, email, method, params, tag,
                                  service_identity, user_details):
    logging.debug("Received voucher pin activate call with params: %s", params)
    sln_settings = get_solution_settings(service_user)
    r = SendApiCallCallbackResultTO()
    r.result = None
    r.error = None
    try:
        jsondata = json.loads(params)

        city_service_users = get_service_users_for_city(jsondata["app_id"])
        if not city_service_users:
            raise Exception(u"No city_service_users")

        if service_user not in city_service_users:
            raise Exception(u"Normal service tried activating voucher")

        ancestor_key = SolutionCityVoucher.create_parent_key(
            jsondata["app_id"])
        sln_city_voucher = SolutionCityVoucher.get_by_id(
            jsondata["voucher_id"], ancestor_key)
        if not sln_city_voucher:
            raise Exception(u"sln_city_voucher was None")

        if sln_city_voucher.activated:
            raise Exception(u"sln_city_voucher was already activated")

        sln_city_voucher_settings = get_city_vouchers_settings(
            jsondata["app_id"])
        if not sln_city_voucher_settings:
            raise Exception(u"sln_city_voucher_settings was None")

        if jsondata["pin"] not in sln_city_voucher_settings.pincodes:
            r.error = common_translate(sln_settings.main_language,
                                       SOLUTION_COMMON, 'Pincode invalid')
            return r

        index = sln_city_voucher_settings.pincodes.index(jsondata["pin"])
        r_dict = dict()
        r_dict["username"] = sln_city_voucher_settings.usernames[index]
        result = json.dumps(r_dict)
        r.result = result if isinstance(result,
                                        unicode) else result.decode("utf8")
    except:
        logging.error("solutions.voucher.activate.pin exception occurred",
                      exc_info=True)
        r.error = common_translate(sln_settings.main_language, SOLUTION_COMMON,
                                   'error-occured-unknown')
    return r
コード例 #6
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def edit_city_wide_lottery_info(key, winnings, date, x_winners):
    ll_info_edit = SolutionCityWideLottery.get(key)
    if not ll_info_edit:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)

    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionCityWideLottery.load_pending(ll_info_edit.app_id)
        if ll_info_edit.key() != ll_info.key() and end_timestamp <= ll_info.end_timestamp:
            raise BusinessException("lottery-time-bigger-first-upcoming")

        ll_info_edit.end_timestamp = end_timestamp
        ll_info_edit.schedule_loot_time = ll_info_edit.end_timestamp - 24 * 3600
        ll_info_edit.winnings = winnings
        ll_info_edit.x_winners = x_winners
        ll_info_edit.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update")

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
コード例 #7
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def can_edit_city_postal_codes():
    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)
    if SolutionModule.CITY_APP not in sln_settings.modules:
        raise BusinessException(common_translate(sln_settings.main_language,
                                                 SOLUTION_COMMON, u'insufficient-permissions'))
    return sln_settings
コード例 #8
0
ファイル: __init__.py プロジェクト: MarijkeDM/oca-backend
def set_default_broadcast_types(sln_settings, solution=SOLUTION_COMMON):
    if not sln_settings.broadcast_types:
        sln_settings.broadcast_types = []
        for broadcast_type in DEFAULT_BROADCAST_TYPES:
            translated = common_translate(sln_settings.main_language, solution,
                                          broadcast_type)
            sln_settings.broadcast_types.append(translated)
コード例 #9
0
ファイル: locations.py プロジェクト: MarijkeDM/oca-backend
    def trans():
        sln_i_settings_key = SolutionIdentitySettings.create_key(
            service_user, service_identity)
        sln_i_settings = SolutionIdentitySettings(key=sln_i_settings_key)
        sln_i_settings.name = name
        sln_i_settings.phone_number = sln_settings.phone_number
        sln_i_settings.qualified_identifier = sln_settings.qualified_identifier
        sln_i_settings.description = sln_settings.description
        sln_i_settings.opening_hours = sln_settings.opening_hours
        sln_i_settings.address = sln_settings.address
        sln_i_settings.location = sln_settings.location
        sln_i_settings.search_keywords = sln_settings.search_keywords
        sln_i_settings.inbox_forwarders = []
        sln_i_settings.inbox_connector_qrcode = None
        sln_i_settings.inbox_mail_forwarders = []
        sln_i_settings.inbox_email_reminders_enabled = False
        sln_i_settings.holidays = []
        sln_i_settings.holiday_out_of_office_message = common_translate(
            sln_settings.main_language, SOLUTION_COMMON,
            'holiday-out-of-office')
        sln_i_settings.put()

        if not sln_settings.identities:
            sln_settings.identities = []
        sln_settings.identities.append(service_identity)
        sln_settings.put()
        on_trans_committed(_create_service_identity, service_user,
                           sln_i_settings, broadcast_to_users)
コード例 #10
0
def send_expired_voucher_message(voucher_key, sln_settings, days):
    voucher = SolutionCityVoucher.get(voucher_key)
    if not voucher or days in voucher.expiration_reminders_sent:
        return

    language = sln_settings.main_language
    service_user = sln_settings.service_user
    branding = get_solution_main_branding(service_user).branding_key

    if voucher.owner:
        activation_date = format_timestamp(voucher.activation_date,
                                           sln_settings,
                                           format='medium')
        message = common_translate(language,
                                   SOLUTION_COMMON,
                                   u'voucher_expiration_message',
                                   days=days,
                                   date=activation_date)
        with users.set_user(sln_settings.service_user):
            member = MemberTO()
            member.alert_flags = Message.ALERT_FLAG_VIBRATE
            member.member = voucher.owner.email()
            member.app_id = voucher.app_id
            messaging.send(parent_key=None,
                           parent_message_key=None,
                           message=message,
                           answers=[],
                           flags=Message.FLAG_ALLOW_DISMISS,
                           members=[member],
                           branding=branding,
                           tag=None)

        voucher.expiration_reminders_sent.append(days)
        db.put(voucher)
コード例 #11
0
def order_sandwich_received(service_user, message_flow_run_id, member, steps, end_id, end_message_flow_id, parent_message_key,
                   tag, result_key, flush_id, flush_message_flow_id, service_identity, user_details):
    type_ = get_first_fmr_step_result_value(steps, u'message_type')
    topping = get_first_fmr_step_result_value(steps, u'message_topping')
    customizations = get_first_fmr_step_result_value(steps, u'message_customize')
    remark = get_first_fmr_step_result_value(steps, u'message_remark')
    takeaway_time = get_first_fmr_step_result_value(steps, u'message_takeaway_time')

    deferred.defer(process_sandwich_order, service_user, service_identity, user_details, type_, topping, customizations,
                   remark, takeaway_time, parent_message_key)

    sln_settings = get_solution_settings(service_user)
    main_branding = get_solution_main_branding(service_user)

    result = FlowMemberResultCallbackResultTO()
    result.type = TYPE_MESSAGE
    result.value = MessageCallbackResultTypeTO()
    result.value.flags = Message.FLAG_ALLOW_DISMISS | Message.FLAG_AUTO_LOCK
    result.value.answers = []
    result.value.alert_flags = Message.ALERT_FLAG_SILENT
    result.value.attachments = []
    result.value.branding = main_branding.branding_key
    result.value.dismiss_button_ui_flags = 0
    result.value.tag = None
    result.value.message = common_translate(sln_settings.main_language, SOLUTION_COMMON, u'order-sandwich-received')
    result.value.step_id = u'message_sandwich_ordered'
    return result
コード例 #12
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def add_city_wide_lottery_info(city_app_id, winnings, date, x_winners):
    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)
    try:
        now_ = now()
        end_timestamp = date.toEpoch()
        if end_timestamp <= (now_ + 24 * 3600):
            raise BusinessException("end-date-24h-in-future")

        ll_info = SolutionCityWideLottery.load_pending(city_app_id)
        if ll_info:
            logging.warn("end_timestamp: %s", end_timestamp)
            logging.warn("ll_info.end_timestamp: %s", ll_info.end_timestamp)
            if end_timestamp <= ll_info.end_timestamp:
                raise BusinessException("lottery-time-bigger-first-upcoming")

        ll_info = SolutionCityWideLottery(parent=SolutionCityWideLottery.create_parent_key(city_app_id))
        ll_info.timestamp = now_
        ll_info.end_timestamp = end_timestamp
        ll_info.schedule_loot_time = ll_info.end_timestamp - 24 * 3600
        ll_info.winnings = winnings
        ll_info.x_winners = x_winners
        ll_info.winners = []
        ll_info.winner_info = []
        ll_info.skip_winners = []
        ll_info.deleted = False
        ll_info.pending = True
        ll_info.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update")

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
コード例 #13
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def delete_loyalty_lottery_info(key):
    ll_info_delete = SolutionLoyaltyLottery.get(key)
    if not ll_info_delete:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    sln_settings = get_solution_settings(service_user)

    try:
        ll_info = SolutionLoyaltyLottery.load_pending(service_user, service_identity)
        if ll_info_delete.key() == ll_info.key():
            raise RETURNSTATUS_TO_SUCCESS
        if ll_info_delete.schedule_loot_time > 0:
            ll_info_delete.delete()

        sln_settings.updates_pending = True
        put_and_invalidate_cache(sln_settings)
        broadcast_updates_pending(sln_settings)

        send_message(service_user, u"solutions.common.loyalty.lottery.update", service_identity=service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
コード例 #14
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def delete_loyalty_visit(key):
    service_user = users.get_current_user()
    try:
        delete_visit(service_user, key)
        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
コード例 #15
0
ファイル: __init__.py プロジェクト: MarijkeDM/oca-backend
def try_to_translate(key, language):
    try:
        return common_translate(language,
                                SOLUTION_COMMON,
                                key,
                                suppress_warning=True)
    except:
        return key
コード例 #16
0
ファイル: service.py プロジェクト: MarijkeDM/oca-backend
def _send_signup_status_inbox_reply(sln_settings, parent_chat_key, approved,
                                    reason):
    lang = sln_settings.main_language
    if approved:
        message = common_translate(lang, SOLUTION_COMMON, u'approved')
    else:
        message = common_translate(lang,
                                   SOLUTION_COMMON,
                                   u'signup_request_denial_reason',
                                   reason=reason)

    inbox_message = new_inbox_message(sln_settings,
                                      message,
                                      parent_chat_key,
                                      mark_as_read=not approved,
                                      mark_as_trashed=approved)
    return inbox_message
コード例 #17
0
ファイル: menu.py プロジェクト: MarijkeDM/oca-backend
 def create_qr():
     return qr.create(common_translate(
         get_solution_settings(service_user).main_language,
         SOLUTION_COMMON,
         u'upload_menu_item_image',
         item_name=item.name),
                      json.dumps(tag),
                      qr_template_id,
                      flow=u'Upload image')
コード例 #18
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def restapi_add_city_postal_code(app_id, postal_code):
    try:
        sln_settings = can_edit_city_postal_codes()
        add_city_postal_code(app_id, postal_code)
        return RETURNSTATUS_TO_SUCCESS
    except ValueError:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language,
                                     SOLUTION_COMMON, u'invlid_postal_code'))
    except BusinessException as e:
        return ReturnStatusTO.create(False, e.message)
コード例 #19
0
ファイル: menu.py プロジェクト: MarijkeDM/oca-backend
    def trans():
        sln_settings = get_solution_settings(service_user)
        menu = get_restaurant_menu(service_user, sln_settings.solution)
        category = menu.categories[category_id]
        if not category:
            return create_error(
                common_translate(sln_settings.main_language,
                                 SOLUTION_COMMON,
                                 u'category_not_found',
                                 name=category_name))
        for item in category.items:
            if item.id == item_id:
                break
        else:
            return create_error(
                common_translate(sln_settings.main_language,
                                 SOLUTION_COMMON,
                                 u'item_not_found',
                                 name=item_name))

        if item.image_id:
            delete_file_blob(service_user, item.image_id)

        response = download_image()
        if response.status_code != 200:
            return create_error(
                common_translate(sln_settings.main_language, SOLUTION_COMMON,
                                 u'error-occured-unknown-try-again'))

        item.image_id = create_file_blob(service_user,
                                         response.content).key().id()
        menu.put()
        on_trans_committed(channel.send_message,
                           service_user,
                           'solutions.common.menu.item_image_configured',
                           category=serialize_complex_value(
                               category, MenuCategory, False),
                           item=serialize_complex_value(item, MenuItem, False))
        return None
コード例 #20
0
ファイル: menu.py プロジェクト: MarijkeDM/oca-backend
    def trans():
        sln_settings = get_solution_settings(service_user)

        m = get_restaurant_menu(service_user, sln_settings.solution)
        if not m:
            m = RestaurantMenu(key=RestaurantMenu.create_key(
                service_user, sln_settings.solution))
        m.is_default = False
        m.predescription = menu.predescription
        m.postdescription = menu.postdescription
        m.categories = MenuCategories()
        category_names = list()
        for c in menu.categories:
            if c.name in category_names:
                raise BusinessException(
                    common_translate(sln_settings.main_language,
                                     SOLUTION_COMMON,
                                     "category_duplicate_name",
                                     name=c.name))
            if c.id == MISSING:
                c.id = str(uuid.uuid4()).decode('UTF-8')
            category_names.append(c.name)
            item_names = list()
            for i in c.items:
                if i.name in item_names:
                    raise BusinessException(
                        common_translate(sln_settings.main_language,
                                         SOLUTION_COMMON,
                                         "product_duplicate_name",
                                         name=i.name))
                if i.id == MISSING:
                    i.id = str(uuid.uuid4()).decode('UTF-8')
                item_names.append(i.name)
            m.categories.add(c)

        sln_settings.updates_pending = True
        put_and_invalidate_cache(m, sln_settings)
        return sln_settings
コード例 #21
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
    def get(self):
        data_dict, app_user = self.get_user_info()
        if not data_dict or not app_user:
            language = self.request.get("language", DEFAULT_LANGUAGE)
            title = common_translate(language, SOLUTION_COMMON, u'Error')
            text = common_translate(language, SOLUTION_COMMON, u"error-occured-unknown-try-again")
        else:
            azzert(data_dict['a'] == "loyalty_no_mobiles_unsubscribe")
            service_name = data_dict['n']
            service_identity_user_email = data_dict['e']

            suls_key = SolutionUserLoyaltySettings.createKey(app_user)
            suls = SolutionUserLoyaltySettings.get(suls_key)
            if not suls:
                suls = SolutionUserLoyaltySettings(key=suls_key)
                suls.reminders_disabled = False
                suls.reminders_disabled_for = []

            if service_identity_user_email not in suls.reminders_disabled_for:
                suls.reminders_disabled_for.append(service_identity_user_email)
                suls.put()

            user_profile = db.get(UserProfile.createKey(app_user))
            if user_profile:
                language = self.request.get("language", user_profile.language)
            else:
                language = self.request.get("language", DEFAULT_LANGUAGE)

            title = common_translate(language, SOLUTION_COMMON, u'You have been unsubscribed')
            text = common_translate(language, SOLUTION_COMMON, u'You will not receive any loyalty updates from "%(name)s" anymore', name=service_name)

        params = {
            'title': title,
            'text': text
        }

        jinja_template = JINJA_ENVIRONMENT.get_template('pages/loyalty_title_text.html')
        self.response.out.write(jinja_template.render(params))
コード例 #22
0
def delete_holiday(holiday):
    from solutions.common.bizz.holiday import delete_holiday as delete_holiday_bizz
    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    try:
        delete_holiday_bizz(service_user, service_identity, holiday)
        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(
            False,
            common_translate(sln_settings.main_language, SOLUTION_COMMON,
                             e.message))
コード例 #23
0
def save_out_of_office_message(message):
    from solutions.common.bizz.holiday import save_out_of_office_message as save_oof_message
    service_user = users.get_current_user()
    session_ = users.get_current_session()
    service_identity = session_.service_identity
    try:
        save_oof_message(service_user, service_identity, message)
        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(
            False,
            common_translate(sln_settings.main_language, SOLUTION_COMMON,
                             e.message))
コード例 #24
0
def put_order_weekday_timeframe(service_user, timeframe_id, day, time_from,
                                time_until):
    sln_settings = get_solution_settings(service_user)
    if time_from == time_until:
        raise BusinessException(
            common_translate(sln_settings.main_language, SOLUTION_COMMON,
                             'time-start-end-equal'))
    if time_from >= time_until:
        raise BusinessException(
            common_translate(sln_settings.main_language, SOLUTION_COMMON,
                             'time-start-end-smaller'))

    sln_settings = get_solution_settings(service_user)
    if timeframe_id:
        sawt = SolutionOrderWeekdayTimeframe.get_by_id(
            timeframe_id, parent_key(service_user, sln_settings.solution))
        if not sawt:
            # Already deleted before channel update went through
            send_message(service_user,
                         u"solutions.common.order.settings.timeframe.update")
            return
        sawt.day = day
        sawt.time_from = time_from
        sawt.time_until = time_until
    else:
        sawt = SolutionOrderWeekdayTimeframe.get_or_create(
            parent_key(service_user, sln_settings.solution), day, time_from,
            time_until)
    sawt.put()

    sln_settings = get_solution_settings(service_user)
    sln_settings.updates_pending = True
    put_and_invalidate_cache(sln_settings)

    broadcast_updates_pending(sln_settings)
    send_message(service_user,
                 u"solutions.common.order.settings.timeframe.update")
コード例 #25
0
def validate_sandwiches(language, sandwich_types, sandwich_toppings, sandwich_options):
    """
    Args:
        language (unicode)
        sandwich_types (list of SandwichType)
        sandwich_toppings (list of SandwichToppings)
        sandwich_options (list of SandwichOptions)
    Raises:
        InvalidSandwichSettingsException
    """
    errors = set()
    type_labels = []
    topping_lables = []
    option_labels = []
    for sandwich_type in sandwich_types:
        if sandwich_type.description in type_labels:
            msg = common_translate(language, SOLUTION_COMMON, 'duplicate_sandwich_type',
                                   label=sandwich_type.description)
            errors.add(msg)
        else:
            type_labels.append(sandwich_type.description)
    for sandwich_topping in sandwich_toppings:
        if sandwich_topping.description in topping_lables:
            msg = common_translate(language, SOLUTION_COMMON, 'duplicate_sandwich_topping',
                                   label=sandwich_topping.description)
            errors.add(msg)
        else:
            topping_lables.append(sandwich_topping.description)
    for sandwich_option in sandwich_options:
        if sandwich_option.description in option_labels:
            msg = common_translate(language, SOLUTION_COMMON, 'duplicate_sandwich_option',
                                   label=sandwich_option.description)
            errors.add(msg)
        else:
            option_labels.append(sandwich_option.description)
    if errors:
        raise InvalidSandwichSettingsException('\n'.join(errors))
コード例 #26
0
def put_appointment_weekday_timeframe(service_user, appointment_id, day, time_from, time_until):
    sln_settings = get_solution_settings(service_user)
    if time_from == time_until:
        raise BusinessException(common_translate(sln_settings.main_language, SOLUTION_COMMON, 'time-start-end-equal'))
    if time_from >= time_until:
        raise BusinessException(common_translate(sln_settings.main_language, SOLUTION_COMMON, 'time-start-end-smaller'))

    sln_settings = get_solution_settings(service_user)
    if appointment_id:
        sawt = SolutionAppointmentWeekdayTimeframe.get_by_id(appointment_id, parent_key(service_user, sln_settings.solution))
        sawt.day = day
        sawt.time_from = time_from
        sawt.time_until = time_until
    else:
        sawt = SolutionAppointmentWeekdayTimeframe.get_or_create(parent_key(service_user, sln_settings.solution), day,
                                                                 time_from, time_until)
    sawt.put()

    sln_settings = get_solution_settings(service_user)
    sln_settings.updates_pending = True
    put_and_invalidate_cache(sln_settings)

    broadcast_updates_pending(sln_settings)
    send_message(service_user, u"solutions.common.appointment.settings.timeframe.update")
コード例 #27
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def close_city_wide_lottery_info(key):
    service_user = users.get_current_user()
    try:
        ll_info = SolutionCityWideLottery.get(key)
        if ll_info and not ll_info.pending and not ll_info.deleted:
            ll_info.deleted = True
            ll_info.put()

        send_message(service_user, u"solutions.common.loyalty.lottery.update",
                     service_identity=ll_info.service_identity)

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        sln_settings = get_solution_settings(service_user)
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))
コード例 #28
0
def bulk_invite_result(service_user, service_identity, tag, email, result, user_details):
    if not tag:
        logging.exception("Expected tag in bulk_invite_result")
        return

    if tag in (SERVICE_AUTOCONNECT_INVITE_TAG, APP_BROADCAST_TAG):
        return

    try:
        key = db.Key(tag)
    except db.BadKeyError:
        logging.info('Tag is no db.Key: %s. Ignoring...', tag)
        return

    def trans():
        invite = db.get(reconstruct_key(key))
        if not invite:
            logging.error("Invite object not found in datastore")
            return
        save_message = False
        if "accepted" == result:
            invite.status = RestaurantInvite.STATUS_ACCEPTED
            save_message = True
        else:
            invite.status = RestaurantInvite.STATUS_REJECTED
        invite.put()
        return save_message

    save_message = run_in_xg_transaction(trans)
    if save_message:
        now_ = now()
        sln_settings = get_solution_settings(service_user)
        msg = common_translate(sln_settings.main_language, SOLUTION_COMMON, 'if-accepted-invitation',
                               if_name=user_details[0].name,
                               if_email=user_details[0].email)

        message = create_solution_inbox_message(
            service_user, service_identity, SolutionInboxMessage.CATEGORY_BULK_INVITE, None, False, user_details, now_, msg, False)
        app_user = create_app_user_by_email(user_details[0].email, user_details[0].app_id)
        send_inbox_forwarders_message(service_user, service_identity, app_user, msg, {
            'if_name': user_details[0].name,
            'if_email': user_details[0].email
        }, message_key=message.solution_inbox_message_key, reply_enabled=message.reply_enabled, send_reminder=False)

        sln_i_settings = get_solution_settings_or_identity_settings(sln_settings, service_identity)
        send_message(service_user, u"solutions.common.messaging.update",
                     service_identity=service_identity,
                     message=serialize_complex_value(SolutionInboxMessageTO.fromModel(message, sln_settings, sln_i_settings, True), SolutionInboxMessageTO, False))
コード例 #29
0
def solution_voucher_redeem(service_user, email, method, params, tag,
                            service_identity, user_details):
    logging.debug("Received voucher redeem call with params: %s", params)
    sln_settings = get_solution_settings(service_user)
    r = SendApiCallCallbackResultTO()
    r.result = None
    r.error = None
    try:
        jsondata = json.loads(params)

        ancestor_key = SolutionCityVoucher.create_parent_key(
            jsondata["app_id"])
        sln_city_voucher = SolutionCityVoucher.get_by_id(
            jsondata["voucher_id"], ancestor_key)
        if not sln_city_voucher:
            raise Exception(u"sln_city_voucher was None")

        value = long(jsondata["value"])
        if (sln_city_voucher.value - sln_city_voucher.redeemed_value) < value:
            raise Exception(u"insufficient funds")

        service_identity_user = create_service_identity_user_wo_default(
            service_user, service_identity)
        sln_city_voucher_rt = SolutionCityVoucherRedeemTransaction(
            parent=parent_key_unsafe(service_identity_user, SOLUTION_COMMON))
        sln_city_voucher_rt.created = now()
        sln_city_voucher_rt.confirmed = False
        sln_city_voucher_rt.value = value
        sln_city_voucher_rt.voucher_key = unicode(sln_city_voucher.key())
        sln_city_voucher_rt.signature = sln_city_voucher.signature()
        sln_city_voucher_rt.put()

        r_dict = dict()
        r_dict["uid"] = sln_city_voucher.uid
        r_dict["voucher_redeem_key"] = unicode(sln_city_voucher_rt.key())
        r_dict["value"] = sln_city_voucher_rt.value

        result = json.dumps(r_dict)
        r.result = result if isinstance(result,
                                        unicode) else result.decode("utf8")
    except:
        logging.error("solutions.voucher.redeem exception occurred",
                      exc_info=True)
        r.error = common_translate(sln_settings.main_language, SOLUTION_COMMON,
                                   'error-occured-unknown')
    return r
コード例 #30
0
ファイル: loyalty.py プロジェクト: MarijkeDM/oca-backend
def delete_city_wide_lottery_info(key):
    ll_info_delete = SolutionCityWideLottery.get(key)
    if not ll_info_delete:
        return RETURNSTATUS_TO_SUCCESS

    service_user = users.get_current_user()
    sln_settings = get_solution_settings(service_user)

    try:
        ll_info = SolutionCityWideLottery.load_pending(ll_info_delete.app_id)
        if ll_info_delete.key() == ll_info.key():
            raise RETURNSTATUS_TO_SUCCESS
        if ll_info_delete.schedule_loot_time > 0:
            ll_info_delete.delete()

        send_message(service_user, u"solutions.common.loyalty.lottery.update")

        return RETURNSTATUS_TO_SUCCESS
    except BusinessException, e:
        return ReturnStatusTO.create(False, common_translate(sln_settings.main_language, SOLUTION_COMMON, e.message))