示例#1
0
def addProperty(request, name="", anUser=None):
    """Add a property for a non anonymous user.
    """
    try:
        if anUser is None:
            theUser = request.user
        else:
            theUser = anUser
        if theUser.is_anonymous():
            return False
        try:
            un = UserProperty.objects.get(user=theUser, name=name)
            un.value = 1
        except UserProperty.DoesNotExist:
            un = UserProperty(user=theUser, name=name, value=1)
        un.save()
        return True
    except:
        return False
示例#2
0
def incUserProperty(request, name="", anUser=None, incrementBy=1):
    """
    Works for non anonymous users only.
    """
    try:
        if anUser is None:
            theUser = request.user
        else:
            theUser = anUser
        if theUser.is_anonymous():
            return False
        try:
            un = UserProperty.objects.get(user=theUser, name=name)
        except UserProperty.DoesNotExist:
            un = UserProperty(user=theUser, name=name, value=0)
        un.value += incrementBy
        un.save()
        return True
    except:
        return False
示例#3
0
def setIntegerProperty(request, name="", value=0, anUser=None):
    """
    The user must not be an anonymous user!   
    """
    try:
        if anUser is None:
            theUser = request.user
        else:
            theUser = anUser
        if theUser.is_anonymous():
            return False
        try:
            un = UserProperty.objects.get(user=theUser, name=name)
            un.value = value
        except UserProperty.DoesNotExist:
            un = UserProperty(user=theUser, name=name, value=value)
        un.save()
        return True
    except:
        pass
    return False