Пример #1
0
 def save_model(self, request, obj, form, change):
     if obj.status == ContentUpdate.RUNNING:
         return
     if obj.status == ContentUpdate.AUTHORIZED:
         obj.provider = request.user
     elif obj.status == ContentUpdate.DELIVERED:
         sync_changes(obj)
     super(ContentUpdateAdmin, self).save_model(request, obj, form, change)
Пример #2
0
def get_repo_files_update(request, *args, **kwargs):
    username = request.GET.get('username')
    password = request.GET.get('password')
    provider = authenticate(email=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')
    available_space = request.GET.get('available_space')
    operator_username = request.GET.get('operator_username')
    try:
        member = Member.objects.get(email=operator_username)
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update = ContentUpdate.objects.get(member=member,
                                           status=ContentUpdate.AUTHORIZED)
    except Member.DoesNotExist:
        response = {
            'error': "Member not found with username %s" % operator_username
        }
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    except ContentUpdate.DoesNotExist:
        response = {
            'error':
            "No update placed by member with username %s" % operator_username
        }
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    total_available_space = int(available_space) + update.delete_list_size
    if total_available_space < update.add_list_size:
        needed_space = update.add_list_size - total_available_space
        if needed_space >= 1000:
            needed_space_str = "%.2f GB" % (needed_space / 1000.0)
        else:
            needed_space_str = "%d MB" % needed_space
        response = {
            'error':
            "Insufficient space on drive to run this update, Need %s more." %
            needed_space_str
        }
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    latest_prepayment = member.profile.get_last_retail_prepayment()
    latest_prepayment.balance -= update.add_list_size
    latest_prepayment.save()
    update.status = ContentUpdate.DELIVERED
    update.provider = provider
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        update.save(using=database)
    sync_changes(update)
    response = {
        'add_list': update.add_list.split(','),
        'delete_list': update.delete_list.split(',')
    }
    return HttpResponse(json.dumps(response), 'content-type: text/json')
Пример #3
0
def get_repo_files_update(request, *args, **kwargs):
    username = request.GET.get('username')
    password = request.GET.get('password')
    provider = authenticate(email=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')
    available_space = request.GET.get('available_space')
    operator_username = request.GET.get('operator_username')
    try:
        member = Member.objects.get(email=operator_username)
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update = ContentUpdate.objects.get(member=member, status=ContentUpdate.AUTHORIZED)
    except Member.DoesNotExist:
        response = {'error': "Member not found with username %s" % operator_username}
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    except ContentUpdate.DoesNotExist:
        response = {'error': "No update placed by member with username %s" % operator_username}
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    total_available_space = int(available_space) + update.delete_list_size
    if total_available_space < update.add_list_size:
        needed_space = update.add_list_size - total_available_space
        if needed_space >= 1000:
            needed_space_str = "%.2f GB" % (needed_space / 1000.0)
        else:
            needed_space_str = "%d MB" % needed_space
        response = {'error': "Insufficient space on drive to run this update, Need %s more." % needed_space_str}
        return HttpResponse(json.dumps(response), 'content-type: text/json')
    latest_prepayment = member.profile.get_last_retail_prepayment()
    latest_prepayment.balance -= update.add_list_size
    latest_prepayment.save()
    update.status = ContentUpdate.DELIVERED
    update.provider = provider
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        update.save(using=database)
    sync_changes(update)
    response = {
        'add_list': update.add_list.split(','),
        'delete_list': update.delete_list.split(',')
    }
    return HttpResponse(json.dumps(response), 'content-type: text/json')
Пример #4
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')
Пример #5
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')