Exemplo n.º 1
0
 def testLocks(self):
     r = RepeatRecord(domain='test')
     r.save()
     r2 = RepeatRecord.get(r._id)
     self.assertTrue(r.acquire_lock(datetime.utcnow()))
     r3 = RepeatRecord.get(r._id)
     self.assertFalse(r2.acquire_lock(datetime.utcnow()))
     self.assertFalse(r3.acquire_lock(datetime.utcnow()))
     r.release_lock()
     r4 = RepeatRecord.get(r._id)
     self.assertTrue(r4.acquire_lock(datetime.utcnow()))
Exemplo n.º 2
0
 def post(self, request, domain):
     # Retriggers a repeat record
     record = RepeatRecord.get(request.POST.get('record_id'))
     record.fire(max_tries=1, force_send=True)
     return json_response({
         'success': record.succeeded,
         'failure_reason': record.failure_reason,
     })
Exemplo n.º 3
0
 def post(self, request, domain):
     # Retriggers a repeat record
     record = RepeatRecord.get(request.POST.get('record_id'))
     record.fire(max_tries=1, force_send=True)
     record.save()
     return json_response({
         'success': record.succeeded,
         'failure_reason': record.failure_reason,
     })
Exemplo n.º 4
0
    def get_record_or_404(request, domain, record_id):
        try:
            record = RepeatRecord.get(record_id)
        except ResourceNotFound:
            raise Http404()

        if record.domain != domain:
            raise Http404()

        return record
Exemplo n.º 5
0
    def get(self, request, domain):
        record = RepeatRecord.get(request.GET.get('record_id'))
        content_type = record.repeater.get_payload_generator(
            record.repeater.format_or_default_format()
        ).content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': u'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })
Exemplo n.º 6
0
    def get(self, request, domain):
        record = RepeatRecord.get(request.GET.get('record_id'))
        content_type = record.repeater.get_payload_generator(
            record.repeater.format_or_default_format()
        ).content_type
        try:
            payload = record.get_payload()
        except XFormNotFound:
            return json_response({
                'error': u'Odd, could not find payload for: {}'.format(record.payload_id)
            }, status_code=404)

        if content_type == 'text/xml':
            payload = indent_xml(payload)
        elif content_type == 'application/json':
            payload = json.dumps(json.loads(payload), indent=4)

        return json_response({
            'payload': payload,
            'content_type': content_type,
        })