示例#1
0
def request_item(request, id):
    """Gets an instance of particular record if exists, else creates it. Updates arrays of the tuple."""
    obj, created = Record.objects.get_or_create(user=request.user, item=Item.objects.get(id=id))
    obj.save()
    period = Item.objects.get(id=id).period
    common.update_record(request.user.id, id, period)
    return HttpResponse("OK")
示例#2
0
def request_item(request, id):
    """Gets an instance of particular record if exists, else creates it. Updates arrays of the tuple."""
    obj, created = Record.objects.get_or_create(user=request.user,
                                                item=Item.objects.get(id=id))
    obj.save()
    period = Item.objects.get(id=id).period
    common.update_record(request.user.id, id, period)
    return HttpResponse('OK')
示例#3
0
def add_record(request):
    """Creates an instance of a form, sets omitted value and saves and object if valid.
       Executes raw update SQL query to populate arrays of the tuple with temporal data."""
    form = AddRecordForm(request.POST or None)

    if form.is_valid():
        obj = form.save(commit=False)
        item = obj.item
        period = item.period
        record = Record.objects.filter(user=request.user.id, item=obj.item.id)
        if record.count() == 0:
            obj.save()

        common.update_record(request.user.id, obj.item.id, period)
        return {"form": AddRecordForm()}

    return {"form": form}
示例#4
0
def add_record(request):
    """Creates an instance of a form, sets omitted value and saves and object if valid.
       Executes raw update SQL query to populate arrays of the tuple with temporal data."""
    form = AddRecordForm(request.POST or None)

    if form.is_valid():
        obj = form.save(commit=False)
        item = obj.item
        period = item.period
        record = Record.objects.filter(user=request.user.id, item=obj.item.id)
        if record.count() == 0:
            obj.save()

        common.update_record(request.user.id, obj.item.id, period)
        return {'form': AddRecordForm()}

    return {'form': form}