Example #1
0
def get_working_flowgram(user):
    profile = user.get_profile()

    try:
        log.debug("get_working_flowgram for user %s with working_flowgram_id = %s" % (str(user.id), profile.working_flowgram_id))
        
        if profile.just_published and profile.working_flowgram_id != "":
            log.critical("User %s has just_published AND working_flowgram_id = %s." % (user, profile.working_flowgram_id))

        working_flowgram = None
        if profile.working_flowgram_id != "":
            working_flowgram = Flowgram.objects.get(id=profile.working_flowgram_id)

        if profile.just_published or (working_flowgram and not permissions.can_edit(user, working_flowgram)):
            flowgram = new_flowgram(user)
            set_working_flowgram(user, flowgram)
            
            profile.just_published = False
            profile.save()
            
            return (flowgram, True)
    
        if working_flowgram:
            return (working_flowgram, False)
    except Flowgram.DoesNotExist:
        pass

    # Finally, return their latest-modified Flowgram if one exists, or else a new flowgram
    try:
        return (Flowgram.objects.filter(owner=user, published=False).latest('modified_at'), False)
    except Flowgram.DoesNotExist:
        flowgram = new_flowgram(user)
        set_working_flowgram(user, flowgram)
        
        return (flowgram, True)
Example #2
0
def save_builtin_avatar(profile, name):
    if not name in BUILTIN_AVATARS:
        log.critical("Tried to save unknown avatar %s to %'s profile" % (name, profile.user))
        return
    profile.avatar = name
    profile.avatar_builtin = True
    profile.save()
    
Example #3
0
def get_post_token_value(request):
    from django.contrib.csrf.middleware import _make_token
    from flowgram.core import log
    
    try:
        session_id = request.COOKIES[settings.SESSION_COOKIE_NAME]
    except KeyError:
        log.critical("get_post_token found no sessionid for authenticated user %s" % request.user)
        return error_response.create(get(request, 'enc', 'json'), 'Session cookie required')

    return _make_token(session_id)
Example #4
0
 def delete(self):
     log.critical("UserProfile %s deletion blocked" % self.id)
     raise Exception