def edit(request, *args, **kwargs):
  if request.params.key:
    item = db.get(request.params.key)
    if item:
      return {'op':'save', 'form': MagicSet.getFormClass(request)(instance=item)}
    else:
      request.status = 'Item does not exists'
      request.redirect(request.get_url())
  else:
    return {'op':'insert' ,'form':MagicSet.getFormClass(request)()}
def edit(request, *args, **kwargs):
    if request.params.key:
        item = db.get(request.params.key)
        if item:
            return {"op": "upd", "form": MagicSet.getFormClass(request)(instance=item)}
        else:
            request.status = "Item does not exists"
            request.redirect(request.get_url())
    else:
        request.status = "Key not provided"
        return {"op": "ins", "form": MagicSet.getFormClass(request)()}
def edit(request, *args, **kwargs):
    if request.params.key:
        item = db.get(request.params.key)
        if item:
            return {
                'op': 'upd',
                'form': MagicSet.getFormClass(request)(instance=item)
            }
        else:
            request.status = 'Item does not exists'
            request.redirect(request.get_url())
    else:
        request.status = 'Key not provided'
        return {'op': 'ins', 'form': MagicSet.getFormClass(request)()}
def save(request, *args, **kwargs):
    if request.params.key:
        item = db.get(request.params.key)
    form = MagicSet.getFormClass(request)(data=request.POST, instance=item)
    if form.is_valid():
        result = form.save(commit=False)
        result.put()
        request.status = 'Item is saved'
    else:
        request.status = 'Form is not Valid'
    request.redirect(request.get_url())
def save(request, *args, **kwargs):
    if request.params.key:
        item = db.get(request.params.key)
    form = MagicSet.getFormClass(request)(data=request.POST, instance=item)
    if form.is_valid():
        result=form.save(commit=False)
        result.put()
        request.status = 'Item is saved'
    else:
        request.status = 'Form is not Valid'
    request.redirect(request.get_url())