Esempio n. 1
0
def save(request):
    response = {}
    bibs = json.loads(request.POST['bibs'])
    status = 200
    response['id_translations'] = []
    for b_id in list(bibs.keys()):
        bib = bibs[b_id]
        if request.POST['is_new'] == 'true':
            inserting_obj = {
                'entry_owner_id': request.user.id,
                'entry_key': bib['entry_key'][-64:],
                'bib_type': bib['bib_type'],
                'entry_cat': bib['entry_cat'],
                'fields': bib['fields']
            }
            similar = Entry.objects.filter(**inserting_obj).first()
            if similar:
                response['id_translations'].append([b_id, similar.id])
            else:
                the_entry = Entry(**inserting_obj)
                the_entry.save()
                response['id_translations'].append([b_id, the_entry.id])

        else:
            the_entry = Entry.objects.get(id=b_id)
            the_entry.entry_key = bib['entry_key'][-64:]
            the_entry.bib_type = bib['bib_type']
            the_entry.entry_cat = bib['entry_cat']
            the_entry.fields = bib['fields']
            the_entry.save()
            response['id_translations'].append([b_id, the_entry.id])
    return JsonResponse(response, status=status)
Esempio n. 2
0
def save(request):
    response = {}
    bibs = json.loads(request.POST["bibs"])
    status = 200
    response["id_translations"] = []
    for b_id in list(bibs.keys()):
        bib = bibs[b_id]
        if request.POST["is_new"] == "true":
            inserting_obj = {
                "entry_owner_id": request.user.id,
                "entry_key": bib["entry_key"][-64:],
                "bib_type": bib["bib_type"],
                "cats": bib["cats"],
                "fields": bib["fields"],
            }
            similar = Entry.objects.filter(**inserting_obj).first()
            if similar:
                response["id_translations"].append([b_id, similar.id])
            else:
                the_entry = Entry(**inserting_obj)
                the_entry.save()
                response["id_translations"].append([b_id, the_entry.id])

        else:
            the_entry = Entry.objects.get(id=b_id)
            the_entry.entry_key = bib["entry_key"][-64:]
            the_entry.bib_type = bib["bib_type"]
            the_entry.cats = bib["cats"]
            the_entry.fields = bib["fields"]
            the_entry.save()
            response["id_translations"].append([b_id, the_entry.id])
    return JsonResponse(response, status=status)
Esempio n. 3
0
def save_js(request):
    response = {}
    status = 405
    if request.is_ajax() and request.method == 'POST':
        bibs = json.loads(request.POST['bibs'])
        status = 200
        owner_id = request.user.id
        if 'owner_id' in request.POST:
            requested_owner_id = int(request.POST['owner_id'])
            # If the user has write access to at least one document of the
            # document owning user, we allow him to add new and edit
            # bibliography entries of the document owner.
            if AccessRight.objects.filter(
                document__owner_id=requested_owner_id,
                user_id=request.user.id,
                rights__in=CAN_UPDATE_DOCUMENT
            ).count() > 0:
                owner_id = requested_owner_id
        response['id_translations'] = []
        for b_id in bibs.keys():
            bib = bibs[b_id]
            if request.POST['is_new'] == 'true':
                inserting_obj = {
                    'entry_owner_id': owner_id,
                    'entry_key': bib['entry_key'][-64:],
                    'bib_type': bib['bib_type'],
                    'entry_cat': bib['entry_cat'],
                    'fields': bib['fields']
                }
                similar = Entry.objects.filter(**inserting_obj)
                if len(similar) == 0:
                    the_entry = Entry(**inserting_obj)
                    the_entry.save()
                    response['id_translations'].append([b_id, the_entry.id])
                else:
                    response['id_translations'].append([b_id, similar[0].id])
            else:
                the_entry = Entry.objects.get(id=b_id)
                the_entry.entry_key = bib['entry_key'][-64:]
                the_entry.bib_type = bib['bib_type']
                the_entry.entry_cat = bib['entry_cat']
                the_entry.fields = bib['fields']
                the_entry.save()
                response['id_translations'].append([b_id, the_entry.id])
    return JsonResponse(
        response,
        status=status
    )
Esempio n. 4
0
def save_js(request):
    response = {}
    status = 405
    if request.is_ajax() and request.method == 'POST':
        bibs = json.loads(request.POST['bibs'])
        status = 200
        owner_id = request.user.id
        if 'owner_id' in request.POST:
            requested_owner_id = int(request.POST['owner_id'])
            # If the user has write access to at least one document of another
            # user, we allow him to add new and edit bibliography entries of
            # this user.
            if len(
                    AccessRight.objects.filter(
                        document__owner=requested_owner_id,
                        user=request.user.id,
                        rights='w')) > 0:
                owner_id = requested_owner_id
        response['id_translations'] = []
        for b_id in bibs.keys():
            bib = bibs[b_id]
            if request.POST['is_new'] == 'true':
                inserting_obj = {
                    'entry_owner_id': owner_id,
                    'entry_key': bib['entry_key'],
                    'bib_type': bib['bib_type'],
                    'entry_cat': bib['entry_cat'],
                    'fields': bib['fields']
                }
                similar = Entry.objects.filter(**inserting_obj)
                if len(similar) == 0:
                    the_entry = Entry(**inserting_obj)
                    the_entry.save()
                    response['id_translations'].append([b_id, the_entry.id])
                else:
                    response['id_translations'].append([b_id, similar[0].id])
            else:
                the_entry = Entry.objects.get(id=b_id)
                the_entry.entry_key = bib['entry_key']
                the_entry.bib_type = bib['bib_type']
                the_entry.entry_cat = bib['entry_cat']
                the_entry.fields = bib['fields']
                the_entry.save()
                response['id_translations'].append([b_id, the_entry.id])
    return JsonResponse(response, status=status)
Esempio n. 5
0
def save_js(request):
    response = {}
    status = 405
    if request.is_ajax() and request.method == 'POST':
        bibs = json.loads(request.POST['bibs'])
        status = 200
        response['id_translations'] = []
        for b_id in list(bibs.keys()):
            bib = bibs[b_id]
            if request.POST['is_new'] == 'true':
                inserting_obj = {
                    'entry_owner_id': request.user.id,
                    'entry_key': bib['entry_key'][-64:],
                    'bib_type': bib['bib_type'],
                    'entry_cat': bib['entry_cat'],
                    'fields': bib['fields']
                }
                similar = Entry.objects.filter(**inserting_obj).first()
                if similar:
                    response['id_translations'].append([b_id, similar.id])
                else:
                    the_entry = Entry(**inserting_obj)
                    the_entry.save()
                    response['id_translations'].append([b_id, the_entry.id])

            else:
                the_entry = Entry.objects.get(id=b_id)
                the_entry.entry_key = bib['entry_key'][-64:]
                the_entry.bib_type = bib['bib_type']
                the_entry.entry_cat = bib['entry_cat']
                the_entry.fields = bib['fields']
                the_entry.save()
                response['id_translations'].append([b_id, the_entry.id])
    return JsonResponse(
        response,
        status=status
    )