コード例 #1
0
def job():
    settings = get_server_settings()
    customers = list(Customer.all().fetch(10))
    customers_per_app = defaultdict(list)
    for customer in customers:
        customers_per_app[customer.default_app_id].append(customer)
    book = xlwt.Workbook(encoding='utf-8')
    for app_id in customers_per_app:
        if not app_id:
            continue
        sheet = book.add_sheet(app_id)
        row = 0
        sheet.write(row, 0, 'Customer name')
        for customer in customers_per_app[app_id]:
            row += 1
            url = '%s/internal/shop/login_as?customer_id=%d' % (settings.baseUrl, customer.id)
            sheet.write(row, 0, xlwt.Formula('HYPERLINK("%s";"%s")' % (url, customer.name.replace('"', ''))))

    excel = StringIO()
    book.save(excel)
    excel_string = excel.getvalue()

    current_date = format_datetime(datetime.datetime.now(), locale=DEFAULT_LANGUAGE)
    to_emails = [u'*****@*****.**', u'*****@*****.**', u'*****@*****.**']
    
    attachments = []
    attachments.append(('Customers %s.xls' % current_date,
                        base64.b64encode(excel_string)))

    subject = 'List of all customers'
    message = 'See attachment.'
    send_mail('*****@*****.**', to_emails, subject, message, attachments=attachments)
コード例 #2
0
def job():
    customers = Customer.all()
    to_put = list()
    for c in customers:
        if not c.language:
            if not c.country:
                raise Exception('Customer %s has no country assigned' % c.name)
            c.language = COUNTRY_DEFAULT_LANGUAGES[c.country]
            to_put.append(c)
    db.put(to_put)
コード例 #3
0
def _change_customers_manager(manager_email):
    logging.info(
        'Unsetting regional manager on customers with assigned manager \'%s\'',
        manager_email)
    to_put = []
    manager_user = users.User(manager_email)
    for customer in Customer.all():
        if customer.manager == manager_user:
            customer.manager = None
            to_put.append(customer)
    put_in_chunks(to_put)
コード例 #4
0
def get_service_users_for_city(app_id):
    result = []
    for customer in Customer.all().filter('organization_type =',
                                          OrganizationType.CITY):
        if customer.app_ids and app_id == customer.app_id:
            if customer.service_email:
                sln_settings = get_solution_settings(customer.service_user)
                if SolutionModule.CITY_APP in sln_settings.modules:
                    result.append(customer.service_user)
        elif not customer.app_ids:
            logging.debug(
                "get_service_user_for_city failed for customer_id: %s",
                customer.id)

    return result
コード例 #5
0
def _put_customers(cursor=None):
    qry = Customer.all()
    if cursor:
        qry.with_cursor(cursor)

    customers = qry.fetch(200)
    if not customers:
        return
    cursor = qry.cursor()
    to_put = list()
    for c in customers:
        if c.service_disabled_at == 0:
            c.service_disabled_at = 0
            to_put.append(c)
    db.put(to_put)
    _put_customers(cursor)
コード例 #6
0
def migrate_and_create_user_profile(executor_user, from_service_user, to_user):
    from shop.models import Customer
    bizz_check(from_service_user.email() != to_user.email(), 'FROM and TO should not be equal')

    from_profile = _get_profile_not_cached(from_service_user)
    bizz_check(from_profile, 'ServiceProfile %s not found' % from_service_user)
    bizz_check(isinstance(from_profile, ServiceProfile),
               'Profile %s is not of expected type ServiceProfile, but of type %s' % (from_service_user, from_profile.kind()))

    service_email = u"*****@*****.**" % uuid.uuid4()

    to_profile = _get_profile_not_cached(to_user)
    if to_profile:
        bizz_check(isinstance(to_profile, UserProfile),
                   'Profile %s is not of expected type UserProfile, but of type %s' % (to_user, to_profile.kind()))
        if service_email not in to_profile.owningServiceEmails:
            to_profile.owningServiceEmails.append(service_email)
    else:
        to_profile = create_user_profile(to_user, to_user.email(), from_profile.defaultLanguage)
        to_profile.isCreatedForService = True
        to_profile.owningServiceEmails = [service_email]
        update_password_hash(to_profile, from_profile.passwordHash, now())

    si = get_default_service_identity_not_cached(from_service_user)
    si.qualifiedIdentifier = to_user.email()
    settings = get_solution_settings(from_service_user)
    settings.qualified_identifier = to_user.email()
    settings.login = to_user
    put_and_invalidate_cache(to_profile, si, settings)

    customer = Customer.all().filter('service_email', from_service_user.email()).get()
    if customer:
        def trans(customer_key):
            customer = db.get(customer_key)
            customer.user_email = to_user.email()
            customer.put()
        db.run_in_transaction(trans, customer.key())

        if SolutionModule.CITY_APP in settings.modules:
            for app_id in customer.app_ids:
                invalidate_service_user_for_city(app_id)
    else:
        logging.debug('There was no customer')

    return migrate(executor_user, from_service_user, users.User(service_email))
コード例 #7
0
def _add_properties():
    customers = Customer.all()
    to_put = list()
    for customer in customers:
        if customer.subscription_order_number:
            order_key = Order.create_key(customer.id,
                                         customer.subscription_order_number)
            order = Order.get(order_key)
            customer.creation_time = order.date
            customer.subscription_type = 0 if OrderItem.all(
                keys_only=True).ancestor(order_key).filter(
                    'product_code', 'MSSU').get() else 1
        else:
            customer.creation_time = 0  # at this point it's not known when the customer was created
        if customer.service_email:
            service_user = users.User(email=customer.service_email)
            sln_settings = get_solution_settings(service_user)
            customer.has_loyalty = True if u'loyalty' in sln_settings.modules else False
        else:
            customer.has_loyalty = False
        to_put.append(customer)
    db.put(to_put)
コード例 #8
0
def migrate(executor_user, from_service_user, to_service_user):
    from shop.models import Customer
    from_service_profile = _validate_job(from_service_user, to_service_user)

    customer = Customer.all().filter('service_email', from_service_user.email()).get()
    fsic_keys = map(str, get_all_service_friend_keys_query(from_service_user))

    job_key = db.Key.from_path(MigrateServiceJob.kind(), str(uuid.uuid4()),
                               parent=db.Key.from_path(MigrateServiceJob.kind(), MigrateServiceJob.kind()))

    def trans():
        job = MigrateServiceJob(key=job_key,
                                executor_user=executor_user,
                                from_service_user=from_service_user,
                                to_service_user=to_service_user,
                                phase=MigrateServiceJob.PHASE_1000_DISABLE_OLD_SERVICE,
                                solution=from_service_profile.solution,
                                customer_key=str(customer.key()) if customer else None,
                                fsic_keys=fsic_keys,
                                service_enabled=from_service_profile.enabled,
                                start_timestamp=now(),
                                data=KVStore(job_key))
        job.put()

        if customer:
            customer.migration_job = str(job_key)
            customer.put()

        deferred.defer(controller, job_key, None,
                       _transactional=True, _queue=HIGH_LOAD_CONTROLLER_QUEUE)

        on_trans_committed(channel.send_message, from_service_user, u'rogerthat.system.dologout')

        return job

    xg_on = db.create_transaction_options(xg=True)
    return db.run_in_transaction_options(xg_on, trans)
コード例 #9
0
def qry():
    return Customer.all(keys_only=True)
コード例 #10
0
def _get_customer_keys():
    return Customer.all(keys_only=True)
コード例 #11
0
ファイル: associations.py プロジェクト: MarijkeDM/oca-backend
def update_statistic():
    # Completely rebuilds statistics on run.

    current_date = now()
    broadcast_count_dict = {}
    for news_item in get_news_of_last_month():
        service_email = get_service_user_from_service_identity_user(
            news_item.sender).email()
        if service_email not in broadcast_count_dict:
            broadcast_count_dict[service_email] = 1
        else:
            broadcast_count_dict[service_email] += 1

    future_event_count_dict = {}

    for future_event_key in Event.get_future_event_keys(current_date):
        service_email = future_event_key.parent().name()
        if service_email not in future_event_count_dict:
            future_event_count_dict[service_email] = 1
        else:
            future_event_count_dict[service_email] += 1

    static_content_count_dict = {}

    for static_content_key in SolutionStaticContent.get_all_keys():
        service_email = static_content_key.parent().name()
        if service_email not in static_content_count_dict:
            static_content_count_dict[service_email] = 1
        else:
            static_content_count_dict[service_email] += 1

    unanswered_question_count_dict = {}

    # find the oldest, unanswered question per customer and add it to the statistics
    for unanswered_question in SolutionInboxMessage.get_all_unanswered_questions(
            5):
        service_email = unanswered_question.service_user.email()
        if unanswered_question.question_asked_timestamp != 0:
            if not service_email in unanswered_question_count_dict:
                unanswered_question_count_dict[
                    service_email] = unanswered_question.question_asked_timestamp
            elif unanswered_question.question_asked_timestamp < unanswered_question_count_dict[
                    service_email]:
                unanswered_question_count_dict[
                    service_email] = unanswered_question.question_asked_timestamp

    # dict with as keys the app id from the city, value the statistics of this city.
    statistics = {}
    for customer in Customer.all():
        if len(customer.app_ids) != 0:
            service_email = customer.service_email
            if customer.app_id not in statistics:
                stats = AssociationStatistic(key_name=customer.app_id)
                stats.generated_on = current_date
                statistics[customer.app_id] = stats
            else:
                stats = statistics[customer.app_id]
            if not service_email:
                logging.error(
                    u'Association customer %s(%d) has no service_email!',
                    customer.name, customer.id)
                continue
            stats.customer_emails.append(service_email)

            if service_email in broadcast_count_dict:
                stats.broadcasts_last_month.append(
                    broadcast_count_dict[customer.service_email])
            else:
                stats.broadcasts_last_month.append(0)

            if service_email in future_event_count_dict:
                stats.future_events_count.append(
                    future_event_count_dict[service_email])
            else:
                stats.future_events_count.append(0)

            if service_email in static_content_count_dict:
                stats.static_content_count.append(
                    static_content_count_dict[service_email])
            else:
                stats.static_content_count.append(0)

            if service_email in unanswered_question_count_dict:
                stats.last_unanswered_questions_timestamps.append(
                    unanswered_question_count_dict[service_email])
            else:
                stats.last_unanswered_questions_timestamps.append(0)

    for chunk in chunks(statistics.values(), 200):
        db.put(chunk)
コード例 #12
0
def _all_customers(keys_only=True):
    return Customer.all(keys_only=keys_only)
コード例 #13
0
def _all_customers():
    return Customer.all()
コード例 #14
0
def _get_customers_by_organization_type(organization_type, app_id):
    return Customer.all(keys_only=True).filter('organization_type =',
                                               organization_type).filter(
                                                   'app_ids =', app_id)