Beispiel #1
0
def confirm_order(request, *args, **kwargs):
    member = request.user
    if not member.profile.is_vod_operator:
        return HttpResponse(json.dumps({'error': "Only VoD operators may order movies."}))
    last_prepayment = member.profile.get_last_retail_prepayment()
    items = request.GET.get('items')
    info = generate_add_list_info(items)
    sales_config = SalesConfig.objects.all()[0]
    add_list_size = info['add_list_size']
    add_list_duration = info['add_list_duration']
    if not last_prepayment:
        return HttpResponse(json.dumps({'error': _("You don't have any retail bundle. Contact your vendor.")}))
    if sales_config.unit == SalesConfig.BROADCASTING_TIME:
        if last_prepayment.balance < add_list_duration:
            return HttpResponse(json.dumps({'error': _("Your update bundle contains only %d hours." % (last_prepayment.balance / 60))}))
    else:
        if last_prepayment.balance < add_list_size:
            return HttpResponse(json.dumps({'error': _("Your update bundle contains only %.2f GB." % (last_prepayment.balance / 1000.0))}))
    try:
        update = ContentUpdate.objects.get(member=member, status=ContentUpdate.PENDING)
    except ContentUpdate.DoesNotExist:
        update = ContentUpdate.objects.create(member=member)
    add_media_to_update(items, update)
    update.add_list = (update.add_list + ',' + info['add_list']).strip(',')
    update.add_list_size += add_list_size
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update.save(using=database)
    return HttpResponse(json.dumps({'success': True}))
Beispiel #2
0
 def test_add_media_to_update(self):
     serialized_items = '56eb6d04b37b3379b531e081|movie,56eb6d04b37b3379b531e082|movie,' \
                        '56eb6d04b37b3379b531e083|movie,56eb6d04b37b3379b531e061|seriesepisode,' \
                        '56eb6d04b37b3379b531e062|seriesepisode,56eb6d04b37b3379b531e063|seriesepisode,'
     member = Member.objects.get(pk='56eb6d04b37b3379b531e012')
     update = ContentUpdate.objects.create(member=member)
     add_media_to_update(serialized_items, update)
     expected_movies_add_list = [Movie.objects.get(pk=pk) for pk in ('56eb6d04b37b3379b531e081', '56eb6d04b37b3379b531e082', '56eb6d04b37b3379b531e083')]
     expected_episodes_add_list = [SeriesEpisode.objects.get(pk=pk) for pk in ('56eb6d04b37b3379b531e061', '56eb6d04b37b3379b531e062', '56eb6d04b37b3379b531e063')]
     self.assertEqual(update.movies_add_list, expected_movies_add_list)
     self.assertEqual(update.series_episodes_add_list, expected_episodes_add_list)
Beispiel #3
0
def confirm_order(request, *args, **kwargs):
    member = request.user
    if not member.profile.is_vod_operator:
        return HttpResponse(
            json.dumps({'error': "Only VoD operators may order movies."}))
    last_prepayment = member.profile.get_last_retail_prepayment()
    items = request.GET.get('items')
    info = generate_add_list_info(items)
    sales_config = SalesConfig.objects.all()[0]
    add_list_size = info['add_list_size']
    add_list_duration = info['add_list_duration']
    if not last_prepayment:
        return HttpResponse(
            json.dumps({
                'error':
                _("You don't have any retail bundle. Contact your vendor.")
            }))
    if sales_config.unit == SalesConfig.BROADCASTING_TIME:
        if last_prepayment.balance < add_list_duration:
            return HttpResponse(
                json.dumps({
                    'error':
                    _("Your update bundle contains only %d hours." %
                      (last_prepayment.balance / 60))
                }))
    else:
        if last_prepayment.balance < add_list_size:
            return HttpResponse(
                json.dumps({
                    'error':
                    _("Your update bundle contains only %.2f GB." %
                      (last_prepayment.balance / 1000.0))
                }))
    try:
        update = ContentUpdate.objects.get(member=member,
                                           status=ContentUpdate.PENDING)
    except ContentUpdate.DoesNotExist:
        update = ContentUpdate.objects.create(member=member)
    add_media_to_update(items, update)
    update.add_list = (update.add_list + ',' + info['add_list']).strip(',')
    update.add_list_size += add_list_size
    update.save()
    if not getattr(settings, 'UNIT_TESTING', False):
        service_id = getattr(settings, 'IKWEN_SERVICE_ID')
        database = Service.objects.get(pk=service_id).database
        update.save(using=database)
    return HttpResponse(json.dumps({'success': True}))