ajax.py 595 Bytes
# -*- coding: utf-8 -*-

from django.contrib.auth.models import User, Group
from common.decorators import ajax
from dictionary.models import Vocabulary


@ajax(method='post')
def set_group(request, user_id, group_id, set):
    user = User.objects.get(pk=user_id)
    group = Group.objects.get(pk=group_id)
    if set:
        user.groups.add(group)
    else:
        user.groups.remove(group)
    return {}


@ajax(method='post')
def save_default_owner(request, vocab_id):
    us = request.user.usersettings
    us.default_owner = Vocabulary.objects.get(pk=vocab_id)
    us.save()
    return {}