示例#1
0
def create_spotfix(request):
    try:
        spot_image = request.FILES['spot_image']
        latitude = request.POST['latitude']
        longitude = request.POST['longitude']
        address = request.POST['address']
        description = request.POST['description']
        starttime = request.POST['starttime']
        phone_num = request.POST['phone_num'] 
        min_required = request.POST['min_required'] if 'min_required' in request.POST else 1
      
        userprofile = UserProfile.objects.get(id = request.user.id)
        userprofile.phone_num = phone_num
        userprofile.spotfix_created = userprofile.spotfix_created + 1
        userprofile.save()
 
        new_spotfix = SpotFix(**{
            'name': request.POST['title'] if 'title' in request.POST else '',
            'starttime': starttime,
            'description': description,
            'address': address,
            'latitude': latitude,
            'longitude': longitude,
            'user_id': request.user.id,
            'min_required': min_required
        });
        new_spotfix.save()

        new_joiniee = JoinedSpotFix(**{
            'spotfix_id': new_spotfix.id,
            'user_id': request.user.id,
            'initiator': True
        })
        new_joiniee.save()
   
        #for spot_image in request.FILES: 
        content_file = ContentFile(spot_image.read())
        new_spot_image = SpotFixImages()
        new_spot_image.spotfix = new_spotfix
        new_spot_image.image.save(spot_image.name, content_file)
        new_spot_image.save()

        return HttpResponse(json.dumps({
            'status': 1,
            'msg': 'Success'
        }))
    except Exception, e:
        print str(e)
        return HttpResponse(json.dumps({
            'status': 0,
            'msg': str(e)
        }))
示例#2
0
def report_spotfix(request):
    spotfix_id = request.POST['sf_id']
    rsf = SpotFix.objects.get(id = spotfix_id)
    rsf.status = 'C'
    rsf.reported_user_id = request.user.id
    rsf.endtime = request.POST['endtime']   
    rsf.save()
    print request.POST
    print request.FILES.getlist('spotfix_image')
    for spot_image in request.FILES.getlist('spotfix_image'):
        content_file = ContentFile(spot_image.read())
        new_spot_image = SpotFixImages()
        new_spot_image.spotfix = rsf
        new_spot_image.state = 'A'
        new_spot_image.image.save(spot_image.name, content_file)
        new_spot_image.save()
    return HttpResponse(json.dumps({
        'status': 1
    }))