Ejemplo n.º 1
0
def auto_select_media(request, *args, **kwargs):
    provider_id = getattr(settings, 'PROVIDER_ID')
    provider_website = getattr(settings, 'WEBSITE_NAME')
    provider = Member.objects.get(pk=provider_id)
    member = request.user
    # Delete any prior "RUNNING" ContentUpdate for this member
    ContentUpdate.objects.filter(member=member, status=ContentUpdate.RUNNING).delete()

    movies_max_load = request.GET.get('movies_max_load')
    series_max_load = request.GET.get('series_max_load')
    unit = getattr('unit', 'SALES_UNIT', SalesConfig.DATA_VOLUME)
    base_categories_slugs = request.GET.get('base_categories_slugs')
    preferred_categories_slugs = request.GET.get('preferred_categories_slugs')
    base_categories_slugs = base_categories_slugs.split(',') if base_categories_slugs else []
    preferred_categories_slugs = preferred_categories_slugs.split(',') if base_categories_slugs else []
    movies_max_load = int(movies_max_load)
    series_max_load = int(series_max_load)
    movies_exclude_list_ids = []
    series_exclude_list = []
    for update in ContentUpdate.objects.filter(member=member).exclude(status=ContentUpdate.RUNNING):
        movies_exclude_list_ids.extend([movie.id for movie in update.movies_add_list])
        series_exclude_list.extend(get_series_from_episodes(update.series_episodes_add_list))
    media_selection = collect_movies(movies_max_load, unit, base_categories_slugs,
                                     preferred_categories_slugs, movies_exclude_list_ids)
    media_selection.extend(collect_series(series_max_load, unit, series_exclude_list))
    add_list = []
    add_list_size = 0
    add_list_duration = 0
    for item in media_selection:
        add_list_size += item.size
        add_list_duration += item.duration
        filenames = item.filename.split(',')  # Some movies have filename in multiple parts separated by comma
        for filename in filenames:
            filename = filename.strip()
            add_list.append(filename)
    update = ContentUpdate(member=member, status=ContentUpdate.RUNNING, provider=provider, provider_website=provider_website,
                           add_list=','.join(add_list), add_list_size=add_list_size, add_list_duration=add_list_duration)
    update.movies_add_list = []
    update.series_episodes_add_list = []
    current_series = None
    for media in media_selection:
        if type(media).__name__ == "Movie":
            update.cost += media.price
            update.movies_add_list.append(media)
        elif type(media).__name__ == "SeriesEpisode":
            if current_series != media.series:
                update.cost += media.series.price
                current_series = media.series
            update.series_episodes_add_list.append(media)
    update.save()
Ejemplo n.º 2
0
def get_repo_setup_files(request, *args, **kwargs):
    if request.user.is_authenticated():
        provider_id = getattr(settings, 'PROVIDER_ID')
        provider = Member.objects.get(pk=provider_id)
        member = request.user
    else:
        username = request.GET.get('username')
        password = request.GET.get('password')
        provider = authenticate(username=username, password=password)
        if not provider:
            response = {'error': "Could not authenticate user %s with password." % username}
            return HttpResponse(json.dumps(response), 'content-type: text/json')

        operator_username = request.GET.get('operator_username')
        try:
            member = Member.objects.get(email=operator_username)
        except Member.DoesNotExist:
            response = {'error': "Member not found with username %s" % operator_username}
            return HttpResponse(json.dumps(response), 'content-type: text/json')

    movies_max_load = request.GET.get('movies_max_load')
    series_max_load = request.GET.get('series_max_load')
    unit = getattr('unit', 'SALES_UNIT', SalesConfig.DATA_VOLUME)
    base_categories_slugs = request.GET.get('base_categories_slugs')
    preferred_categories_slugs = request.GET.get('preferred_categories_slugs')
    base_categories_slugs = base_categories_slugs.split(',') if base_categories_slugs else []
    preferred_categories_slugs = preferred_categories_slugs.split(',') if base_categories_slugs else []
    movies_max_load = int(movies_max_load)
    series_max_load = int(series_max_load)
    media_selection = collect_movies(movies_max_load, unit, base_categories_slugs, preferred_categories_slugs)
    media_selection.extend(collect_series(series_max_load, unit))
    response = []
    add_list = []
    add_list_size = 0
    add_list_duration = 0
    for item in media_selection:
        add_list_size += item.size
        add_list_duration += item.duration
        filenames = item.filename.split(',')  # Some movies have filename in multiple parts separated by comma
        response.append(item.to_dict())
        for filename in filenames:
            filename = filename.strip()
            add_list.append(filename)
    update = ContentUpdate(member=member, status=ContentUpdate.DELIVERED, provider=provider,
                           add_list=','.join(add_list), add_list_size=add_list_size, add_list_duration=add_list_duration)
    update.movies_add_list = []
    update.series_episodes_add_list = []
    current_series = None
    for media in media_selection:
        if type(media).__name__ == "Movie":
            update.cost += media.price
            update.movies_add_list.append(media)
            media.orders += 1
            media.fake_orders += 1
            media.save()
        elif type(media).__name__ == "SeriesEpisode":
            if current_series != media.series:
                update.cost += media.price
                current_series = media.series
            update.series_episodes_add_list.append(media)
            media.orders += 1
            media.fake_orders += 1
            media.save()
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        # Copy the ContentUpdate object to the Operator database
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update.save(using=database)
    sync_changes(update)
    return HttpResponse(json.dumps(response), 'content-type: text/json')
Ejemplo n.º 3
0
def get_repo_setup_files(request, *args, **kwargs):
    if request.user.is_authenticated():
        provider_id = getattr(settings, 'PROVIDER_ID')
        provider = Member.objects.get(pk=provider_id)
        member = request.user
    else:
        username = request.GET.get('username')
        password = request.GET.get('password')
        provider = authenticate(username=username, password=password)
        if not provider:
            response = {
                'error':
                "Could not authenticate user %s with password." % username
            }
            return HttpResponse(json.dumps(response),
                                'content-type: text/json')

        operator_username = request.GET.get('operator_username')
        try:
            member = Member.objects.get(email=operator_username)
        except Member.DoesNotExist:
            response = {
                'error':
                "Member not found with username %s" % operator_username
            }
            return HttpResponse(json.dumps(response),
                                'content-type: text/json')

    movies_max_load = request.GET.get('movies_max_load')
    series_max_load = request.GET.get('series_max_load')
    unit = getattr('unit', 'SALES_UNIT', SalesConfig.DATA_VOLUME)
    base_categories_slugs = request.GET.get('base_categories_slugs')
    preferred_categories_slugs = request.GET.get('preferred_categories_slugs')
    base_categories_slugs = base_categories_slugs.split(
        ',') if base_categories_slugs else []
    preferred_categories_slugs = preferred_categories_slugs.split(
        ',') if base_categories_slugs else []
    movies_max_load = int(movies_max_load)
    series_max_load = int(series_max_load)
    media_selection = collect_movies(movies_max_load, unit,
                                     base_categories_slugs,
                                     preferred_categories_slugs)
    media_selection.extend(collect_series(series_max_load, unit))
    response = []
    add_list = []
    add_list_size = 0
    add_list_duration = 0
    for item in media_selection:
        add_list_size += item.size
        add_list_duration += item.duration
        filenames = item.filename.split(
            ','
        )  # Some movies have filename in multiple parts separated by comma
        response.append(item.to_dict())
        for filename in filenames:
            filename = filename.strip()
            add_list.append(filename)
    update = ContentUpdate(member=member,
                           status=ContentUpdate.DELIVERED,
                           provider=provider,
                           add_list=','.join(add_list),
                           add_list_size=add_list_size,
                           add_list_duration=add_list_duration)
    update.movies_add_list = []
    update.series_episodes_add_list = []
    current_series = None
    for media in media_selection:
        if type(media).__name__ == "Movie":
            update.cost += media.price
            update.movies_add_list.append(media)
            media.orders += 1
            media.fake_orders += 1
            media.save()
        elif type(media).__name__ == "SeriesEpisode":
            if current_series != media.series:
                update.cost += media.price
                current_series = media.series
            update.series_episodes_add_list.append(media)
            media.orders += 1
            media.fake_orders += 1
            media.save()
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        # Copy the ContentUpdate object to the Operator database
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update.save(using=database)
    sync_changes(update)
    return HttpResponse(json.dumps(response), 'content-type: text/json')