예제 #1
0
def create_voucher_export_pdfs():
    def get_last_month():
        today = date.today()
        d = today - relativedelta(months=1)
        return date(d.year, d.month, 1)

    first_day_of_last_month = int(time.mktime(get_last_month().timetuple()))
    first_day_of_current_month = int(
        time.mktime(date.today().replace(day=1).timetuple()))

    for sln_settings in SolutionSettings.all().filter(
            'modules =', SolutionModule.CITY_VOUCHERS):
        deferred.defer(create_voucher_statistics_for_city_service,
                       sln_settings.service_user, sln_settings.main_language,
                       first_day_of_last_month, first_day_of_current_month)
예제 #2
0
def create_loyalty_export_pdfs():
    def get_last_month():
        today = date.today()
        d = today - relativedelta(months=1)
        return date(d.year, d.month, 1)

    first_day_of_last_month = int(time.mktime(get_last_month().timetuple()))
    first_day_of_current_month = int(
        time.mktime(date.today().replace(day=1).timetuple()))
    countdown = 0
    for sln_settings in SolutionSettings.all().filter('modules =', 'loyalty'):
        identities = [None]
        if sln_settings.identities:
            identities.extend(sln_settings.identities)
        for service_identity in identities:
            deferred.defer(create_loyalty_statistics_for_service,
                           sln_settings.service_user,
                           service_identity,
                           first_day_of_last_month,
                           first_day_of_current_month,
                           _countdown=countdown)
        countdown += 2
예제 #3
0
def _process_cityapp_uitdatabank_events(cap_key, page):
    try:
        uitdatabank_actors = defaultdict(list)
        for sln_settings in SolutionSettings.all().filter(
                "uitdatabank_actor_id !=", None):
            uitdatabank_actors[sln_settings.uitdatabank_actor_id].append(
                sln_settings)

        pagelength = 50
        cap = CityAppProfile.get(cap_key)
        if page == 1:
            run_time = now()
            services_to_update = set()
        else:
            run_time = cap.run_time
            services_to_update = set(cap.services_to_update)

        logging.info("process_cityapp_uitdatabank_events for %s page %s",
                     cap.service_user, page)
        success, result = get_uitdatabank_events(
            cap, page, pagelength, cap.uitdatabank_last_query or None)
        if not success:
            logging.exception(result, _suppress=False)
            return

        sln_settings = get_solution_settings(cap.service_user)
        to_put = list()
        should_update_service = page != 1

        result_count = 0
        updated_events_count = 0
        for r in result:
            result_count += 1
            updated_events = _populate_uit_events(
                sln_settings, cap.uitdatabank_secret, cap.uitdatabank_key,
                r['cdbid'], uitdatabank_actors, cap.uitdatabank_last_query
                or None)
            if updated_events:
                services_to_update.update(
                    (event.service_user for event in updated_events))
                updated_events_count += 1
                should_update_service = True
                to_put.extend(updated_events)

        def trans_update_cap():
            cap = db.get(cap_key)
            cap.run_time = run_time
            cap.services_to_update = list(services_to_update)
            cap.put()
            return cap

        cap = db.run_in_transaction(trans_update_cap)

        logging.debug("Added/updated %s/%s events", updated_events_count,
                      result_count)
        if to_put:
            put_and_invalidate_cache(*to_put)

        if result_count != 0:
            deferred.defer(_process_cityapp_uitdatabank_events, cap_key,
                           page + 1)
        else:

            def trans_set_last_query():
                cap = db.get(cap_key)
                cap.uitdatabank_last_query = cap.run_time
                cap.put()
                return cap

            cap = db.run_in_transaction(trans_set_last_query)

            if should_update_service:
                for service_user in cap.services_to_update:
                    if service_user != sln_settings.service_user:
                        settings_to_put = get_solution_settings(service_user)
                    else:
                        settings_to_put = sln_settings
                    settings_to_put.put_identity_pending = True
                    settings_to_put.put()
    except Exception, e:
        logging.exception(str(e), _suppress=False)
예제 #4
0
def _get_agenda_solution_settings():
    return SolutionSettings.all().filter("modules =", SolutionModule.AGENDA)
def _all_solution_settings():
    return SolutionSettings.all(keys_only=True)
def get_all_solution_settings_keys(module):
    return SolutionSettings.all(keys_only=True).filter('modules', module)
예제 #7
0
def _qry():
    return SolutionSettings.all(keys_only=True).filter(
        "modules =", SolutionModule.SANDWICH_BAR)
예제 #8
0
def _qry():
    return SolutionSettings.all().filter('modules =', 'loyalty')
예제 #9
0
def _get_order_solution_settings():
    return SolutionSettings.all().filter("modules =", SolutionModule.ORDER)
예제 #10
0
def _get_solution_settings_keys():
    return SolutionSettings.all(keys_only=True)
예제 #11
0
def city_vouchers_enabled_qry():
    return SolutionSettings.all(keys_only=True).filter(
        'modules',
        SolutionModule.CITY_VOUCHERS).filter('service_disabled', False)