예제 #1
0
파일: main.py 프로젝트: yezooz/crime-corp
def import_cars_from_gta(self):
    from crims.item.models import Item
    from crims.common.models import Car

    for car in Car.objects.filter(is_active=True, in_gta=True, in_crims=False):
        i = Item()
        i.type = 'vehicle'
        i.name = "%s %s" % (car.manuf, car.model)
        i.details = json.dumps(
            {'product_type': 'vehicle', 'product_id': int(car.id), 'year': car.year, 'engine': car.engine_up,
             'bhp': int(car.power_bhp)})
        i.image_filename = car.img
        i.is_active = False
        i.save()

        car.is_in_crims = True
        car.is_active_in_crims = i.is_active
        car.save()

    return HttpResponseRedirect('/intranet/')
예제 #2
0
파일: items.py 프로젝트: yezooz/crime-corp
def index(request):
    if request.GET.has_key('rebuild'):
        rethumbnail()
        return HttpResponse('rebuilded all thumbnails!')

    if request.method == 'POST':
        action = request.POST['action']

        if action == 'delete':
            item = Item.objects.get(pk=request.POST['id'])
            item.delete()
            return HttpResponse('deleted!')

        if action == 'update':
            item = Item.objects.get(pk=request.POST['id'])

            if request.POST['field'].strip().startswith('is_'):
                value = int(request.POST['value'])
            elif request.POST['field'].strip() == 'image_filename':
                url = request.POST['value'].strip()
                if url.startswith('http://'):
                    value = download_and_save(url, str(item.pk))
                elif url.startswith('like '):
                    img_id = url.replace('like ', '')
                    img_id = img_id[img_id.rfind('/') + 1:]

                    f_from = os.path.join(settings.MEDIA_ROOT, url.replace('like ', ''))
                    f_to = os.path.join(settings.MEDIA_ROOT, 'images', 'items') + '/' + str(item.pk) + '.jpg'
                    shutil.copyfile(f_from, f_to)
                    shutil.copyfile(f_from.replace('.jpg', '_l.jpg'), f_to.replace('.jpg', '_l.jpg'))
                    shutil.copyfile(f_from.replace('.jpg', '_m.jpg'), f_to.replace('.jpg', '_m.jpg'))
                    shutil.copyfile(f_from.replace('.jpg', '_s.jpg'), f_to.replace('.jpg', '_s.jpg'))

                    value = url.replace('like ', '').replace(img_id, str(item.pk) + '.jpg')
                else:
                    rethumbnail(str(item.pk) + '.jpg')
                    return HttpResponse('updated!')
            else:
                value = request.POST['value'].strip()

            item.__setattr__(request.POST['field'], value)
            item.save()

            return HttpResponse('updated!')

        if action == 'add':
            item = Item()
            for k, v in request.POST.iteritems():
                item.__setattr__(k, v)
            item.in_shop = False
            item.is_active = True
            item.save()
            return HttpResponseRedirect(reverse('intranet_items') + '?type=' + item.type)

    items = Item.objects.all()
    if request.GET.has_key('type'):
        items = items.filter(type=request.GET['type'])

    return render_to_response(
        'intranet/items_index.html', {
            'items': items.order_by('-type', 'attack', 'name'),
            'groups': settings.INVENTORY_TYPES,
            'tiers': (1, 2, 3, 4, 5, 6),
        }, context_instance=RequestContext(request)
    )