Example #1
0
def addCategory(request):
    resp = {}
    app = VoteApplication.objects.filter(id=request.GET.get('appid'))
    if (app.count() == 0):
        resp['code'] = 'application does not exist. check code'
        return HttpResponse(json.dumps(resp), content_type='application/json')
    else:
        app = app[0]
    user = VoteUser.objects.filter(userkey=request.GET.get('userkey'))[0]
    if (user is None):
        resp['code'] = 'authentication error'
        return HttpResponse(json.dumps(resp), content_type='application/json')
    cat = VoteCategory()
    cat.color = request.GET.get('color')
    cat.name = request.GET.get('name')
    cat.parent = VoteCategory.objects.filter(id=request.GET.get('parentid'))[0]
    cat.catType = request.GET.get('catType')  # cat.parent.catType
    cat.languageCode = request.GET.get('lang')
    cat.creation = datetime.now()
    cat.creator = user
    cat.application = app

    cat.save()
    resp['id'] = cat.id
    return HttpResponse(json.dumps(resp), content_type='application/json')
Example #2
0
def createRootCategory(lang, app, parent, user):
    cat = VoteCategory()
    cat.name = app.name
    cat.parent = parent
    cat.catType = -1  # cat.parent.catType -
    cat.languageCode = lang
    cat.creation = datetime.now()
    cat.creator = user
    cat.application = app

    cat.save()
    cat.parent = cat
    cat.save()