Exemple #1
0
    def send(self, url, parsed_instance):

        xform = parsed_instance.instance.xform
        rows = [parsed_instance.to_dict_for_mongo()]

        # prefix meta columns names for bamboo
        prefix = (u'%(id_string)s_%(id)s' % {
            'id_string': xform.id_string,
            'id': xform.id
        })

        for row in rows:
            for col, value in row.items():
                if col.startswith('_') or col.startswith('meta_') \
                    or col.startswith('meta/'):
                    new_col = (u'%(prefix)s%(col)s' % {
                        'prefix': prefix,
                        'col': col
                    })
                    row.update({new_col: value})
                    del (row[col])

        # create dataset on bamboo first (including current submission)
        if not xform.bamboo_dataset:
            dataset_id = get_new_bamboo_dataset(xform, force_last=True)
            xform.bamboo_dataset = dataset_id
            xform.save()
        else:
            dataset = Dataset(connection=Connection(url=get_bamboo_url(xform)),
                              dataset_id=xform.bamboo_dataset)
            dataset.update_data(rows=rows)
Exemple #2
0
def link_to_bamboo(request, username, id_string):
    xform = get_object_or_404(XForm,
                              user__username=username, id_string=id_string)
    owner = xform.user
    from utils.bamboo import get_new_bamboo_dataset, delete_bamboo_dataset

    audit = {
        'xform': xform.id_string
    }

    # try to delete the dataset first (in case it exists)
    if xform.bamboo_dataset and delete_bamboo_dataset(xform):
        xform.bamboo_dataset = u''
        xform.save()
        audit_log(Actions.BAMBOO_LINK_DELETED, request.user, owner,
            _("Bamboo link deleted on '%(id_string)s'.")
            % {'id_string': xform.id_string}, audit, request)

    # create a new one from all the data
    dataset_id = get_new_bamboo_dataset(xform)

    # update XForm
    xform.bamboo_dataset = dataset_id
    xform.save()

    audit_log(Actions.BAMBOO_LINK_CREATED, request.user, owner,
        _("Bamboo link created on '%(id_string)s'.") %\
        {
            'id_string': xform.id_string,
        }, audit, request)

    return HttpResponseRedirect(reverse(show, kwargs={
        'username': username,
        'id_string': id_string
    }))
Exemple #3
0
def link_to_bamboo(request, username, id_string):
    xform = get_object_or_404(XForm, user__username=username, id_string=id_string)

    from utils.bamboo import get_new_bamboo_dataset

    dataset_id = get_new_bamboo_dataset(xform)
    xform.bamboo_dataset = dataset_id
    xform.save()

    return HttpResponseRedirect(reverse(show, kwargs={"username": username, "id_string": id_string}))
Exemple #4
0
    def send(self, url, parsed_instance):

        xform = parsed_instance.instance.xform
        rows = [parsed_instance.to_dict_for_mongo()]

        # create dataset on bamboo first (including current submission)
        if not xform.bamboo_dataset:
            dataset_id = get_new_bamboo_dataset(xform, force_last=True)
            xform.bamboo_dataset = dataset_id
            xform.save()
        else:
            dataset = Dataset(connection=Connection(url=get_bamboo_url(xform)),
                              dataset_id=xform.bamboo_dataset)
            dataset.update_data(rows=rows)
Exemple #5
0
    def send(self, url, parsed_instance):

        xform = parsed_instance.instance.xform

        # create dataset on bamboo first (including current submission)
        if not xform.bamboo_dataset:
            dataset_id = get_new_bamboo_dataset(xform)
            xform.bamboo_dataset = dataset_id
            xform.save()
        else:
            post_data = simplejson.dumps(parsed_instance.to_dict_for_mongo())
            url = ("%(root)sdatasets/%(dataset)s"
            	   % {'root': url,
            	   	  'dataset': parsed_instance.instance.xform.bamboo_dataset})
            requests.put(url, data=post_data,
        				  headers={"Content-Type": "application/json"})
Exemple #6
0
    def send(self, url, parsed_instance):

        xform = parsed_instance.instance.xform
        rows = [parsed_instance.to_dict_for_mongo()]

        # prefix meta columns names for bamboo
        prefix = u"%(id_string)s_%(id)s" % {"id_string": xform.id_string, "id": xform.id}

        for row in rows:
            for col, value in row.items():
                if col.startswith("_") or col.startswith("meta_") or col.startswith("meta/"):
                    new_col = u"%(prefix)s%(col)s" % {"prefix": prefix, "col": col}
                    row.update({new_col: value})
                    del (row[col])

        # create dataset on bamboo first (including current submission)
        if not xform.bamboo_dataset:
            dataset_id = get_new_bamboo_dataset(xform, force_last=True)
            xform.bamboo_dataset = dataset_id
            xform.save()
        else:
            dataset = Dataset(connection=Connection(url=get_bamboo_url(xform)), dataset_id=xform.bamboo_dataset)
            dataset.update_data(rows=rows)