Пример #1
0
def post(request):
    """
    Parameters:
        a: Action
        t: Type
        p: Parameters
        d: Data(Optional)

    Response:
        rc: Return code
        msg: message
    """
    # initial the responsor request
    returnobj = default_returnobj.copy()
    form = RequestForm(request.POST, request.FILES)

    # Error handler
    if not form.is_valid():
        returnobj['rc'] = 1
        returnobj['msg'] = form.errors
        return HttpResponse(simplejson.dumps(returnobj))

    p = form.cleaned_data['p']
    # Get the uploaded file contents
    if form.cleaned_data.get('d'):
        # If the file is loaded with generic POST method
        d = form.cleaned_data['d']
        mime_type = d.content_type
        file_name = p.get('file_name', 'untitiled.' + mime_type.split('/')[1])
    else:
        returnobj['rc'] = 1
        returnobj['msg'] = 'File(Parameter "d") is necessary by uploading'
        return HttpResponse(simplejson.dumps(returnobj))

    # Get the phone info
    phone = None
    pi = p.get('phone_info')
    if pi:
        phone, create = PhoneInfo.objects.get_or_create(device_id = pi['device_id'])
        phone.model = pi.get('model')
        phone.android_version = pi.get('android_version')
        phone.phone_number = pi.get('phone_number')
        phone.save()

    # Save the data
    desc = p.get('desc')
    latitude, longitude = p.get('latitude'), p.get('longitude')
    data = Data.objects.create(
        phone = phone,
        file_name = file_name,
        mime_type = mime_type,
        desc = desc,
        ip_address = request.META['REMOTE_ADDR'],
        latitude = latitude,
        longitude = longitude,
    )
    data.data.save(file_name, request.FILES['d'])
    data.save()
    data.generate_thumbnails()
    return HttpResponse(simplejson.dumps(returnobj))
Пример #2
0
def request_post(request):
    if request.method == "POST":
        form = RequestForm(request.POST)

        if form.is_valid():
            redirect_to = resolve_url('/partime/manage/')
            user = get_user(request)
            form.save(user)
            return HttpResponseRedirect(redirect_to)
    else:
        form = RequestForm()
    return render(request, 'partime/request/request_post.html', {'form': form, 'url': 'partime:request_post'})
Пример #3
0
def create_request(request):
    form = RequestForm(request.POST or None)
    num_req = Exchange.objects.filter(receiver=request.user.id).count()
    if num_req >= 1:
        messages.error(request, "Looks like you've already created a request")
        return redirect('/exchange/participate/dashboard')
    else:
        if request.POST and form.is_valid():
            gift_request = form.gift_request(request)
            print "GIFT", gift_request
            return HttpResponseRedirect('/exchange/participate/dashboard')
        return render(request, 'exchange/participate/create_request.html')
Пример #4
0
def make_request(request):
	if request.method == "POST":
		form = RequestForm(request.POST)
		if form.is_valid():
			post = form.save(commit=False)
			post.poster = request.user
			post.posted_on = datetime.now()
			post.email = request.POST['email']
			post.save()
			return HttpResponseRedirect('/')
	else:
		form = RequestForm()
	return render(request, 'make_request.html', {'form': form})
Пример #5
0
def add(request, employee_id):
	employee = get_object_or_404(Employee, pk=employee_id)
	if request.method == 'POST':
		form = RequestForm(request.POST)
		if form.is_valid():
			new_entry = form.save(commit=False)
			new_entry.user = Employee.objects.get(pk=employee_id)
			new_entry.save()
			return HttpResponseRedirect(reverse('employees:detail', args=(employee_id,)))
	else:
		print "not valid - returning"
		form = RequestForm()
	return render(request, 'employees/add.html', {'form': form, 'employee': employee})
Пример #6
0
def request_update(request, id):
    user = get_user(request)
    user_info = get_user_info(user)
    instance = get_object_or_404(Request, id=id, employee=user_info)
    if request.method == "POST":
        form = RequestForm(request.POST, instance=instance)

        if form.is_valid():
            redirect_to = resolve_url('/partime/manage/')
            form.save()
            return HttpResponseRedirect(redirect_to)
    else:
        form = RequestForm(instance=instance)
    return render(request, 'partime/request/request_post.html', {'form': form, 'url': 'partime:request_update', 'id': id})
Пример #7
0
def bid_request (request, template_name="alerts/alert-form.html"):
	page_title = 'Product Bid Request'

	if request.method =='POST':
		form = RequestForm (request.POST)
		if form.is_valid():
			req = form.save(commit=False)
			req.user = request.user 
			req.save()
                      

			return HttpResponseRedirect('/request-success/')
	else:
		form = RequestForm()
	return render_to_response(template_name, locals(), context_instance = RequestContext(request))
Пример #8
0
def bid_request(request, template_name="alerts/alert-form.html"):
    page_title = 'Product Bid Request'

    if request.method == 'POST':
        form = RequestForm(request.POST)
        if form.is_valid():
            req = form.save(commit=False)
            req.user = request.user
            req.save()

            return HttpResponseRedirect('/request-success/')
    else:
        form = RequestForm()
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))