示例#1
0
def _get_submissions(request, domain_id=0):
    submissions = Submission.objects.all().order_by('checksum')

    # domain_id=0 is a temporary hack until we get server-server authentication
    # working properly
    if domain_id != 0:
        try:
            domain = Domain.objects.get(id=domain_id)
        except Domain.DoesNotExist:
            logging.error("Domain with id %s could not found." % domain_id)
            return HttpResponseBadRequest("Domain with id %s could not found." % domain_id)
        submissions.filter(domain=domain)
    if not hasattr(settings, "RECEIVER_EXPORT_PATH"):
        logging.error("Please set 'export_path' in your cchq receiver settings.")
        return HttpResponseBadRequest("Please set 'export_path' in your cchq receiver settings.")
    export_dir = settings.RECEIVER_EXPORT_PATH
    # We check > 1 (instead of >0 ) since sync requests with no namespaces
    # to match will still POST some junk character
    if len(request.raw_post_data) > 1:
        try:
            stack_received = util.bz2_to_list(request.raw_post_data)
        except Exception, e:
            logging.error("Poorly formatted MD5 file. Expecting a bz2-compressed file of md5 values.")
            return HttpResponseBadRequest("Poorly formatted MD5 file. Expecting a bz2-compressed file of md5 values.")            
        stack_local = Submission.objects.all().distinct('checksum').order_by('checksum').values_list('checksum', flat=True)
        results = util.get_stack_diff(stack_received, stack_local)
        # this could get really large.... O_O
        submissions = Submission.objects.filter(checksum__in=results).distinct("checksum").order_by("checksum")
示例#2
0
 def create(self, request, template= 'api_/xforms.xml'):
     # CREATE is actually POST
     xforms = FormDefModel.objects.order_by('id')
     if not xforms:
         logging.info("No schemas have been registered.")
         return HttpResponse("No schemas have been registered.")
     if 'export_path' not in settings.RAPIDSMS_APPS['xformmanager']:
         logging.error("Please set 'export_path' " + \
                       "in your cchq xformmanager settings.")
         return HttpResponseBadRequest("Please set 'export_path' " + \
                                       "in your cchq xformmanager settings.")
     # We check > 1 (instead of >0 ) since sync requests with no namespaces
     # to match will still POST some junk character
     if len(request.raw_post_data) > 1:
         try:
             stack_received = util.bz2_to_list(request.raw_post_data)
         except Exception, e:
             logging.error("Poorly formatted MD5 file. Expecting a bz2-compressed file of md5 values.")
             return HttpResponseBadRequest("Poorly formatted MD5 file. Expecting a bz2-compressed file of md5 values.")            
         stack_local = FormDefModel.objects.all().order_by('target_namespace').values_list('target_namespace', flat=True)
         results = util.get_stack_diff(stack_received, stack_local)
         xforms = FormDefModel.objects.filter(target_namespace__in=results).order_by("target_namespace")
         if not xforms:
             logging.info("No new schemas have been registered.")
             return HttpResponse("No new schemas have been registered.")