示例#1
0
def device(request, key):
    print "device"

    user = authenticate(request)

    try:
        device = Device.objects.get(key=key)

        if request.method == "PUT":
            report_data = request.read()
            report = Report(device=device, data=report_data)
            report.save()
            return HttpResponse()

        if device.lost == True:
            response = "<device>\n<status>\n<missing>%s</missing>\n</status>" % device.lost \
                        + "<configuration>\n<current_release>0.5.3</current_release>\n" \
                        + "<post_url>http://localhost/report/%s.xml</post_url>\n" % device.key \
                        + "<delay>20</delay>\n<auto_update>true</auto_update>\n</configuration>\n" \
                        + "<modules>\n" + '<module type="action" active="true" name="system" version="1.5"/>' + "\n" \
                        + '<module type="action" active="true" name="webcam" version="1.5"/>\n</modules>' \
                        + "\n</device>"

            return HttpResponseNotFound(response)
        else:
            response = '<device><status><missing>%s</missing></status>' % device.lost \
                        + '<configuration><current_release>0.5.3</current_release>' \
                        + '<delay>20</delay><auto_update>true</auto_update></configuration>' \
                        + '<modules><module type="action" active="true" name="system" version="1.5"/>' \
                        + '<module type="action" active="true" name="webcam" version="1.5"/></modules></device>'
            return HttpResponse(response)
    except Exception, e:
        print e
示例#2
0
def report(request, key):
    print "report"

    user = authenticate(request)

    try:
        device = Device.objects.get(key=key)
        report = Report(device=device, data=request.POST)
        report.save()
        print request.FILES
        for report_file, data_file in request.FILES.items():
            new_file = ReportFile(report=report)
            new_file.save()
            new_file.filename.save(key + "-" + data_file, ContentFile(request.FILES[report_file].read()))
    except Exception, e:
        print e