Exemplo n.º 1
0
def refresh_cache(user):
    """
    Function to be called when change user nickname.
    """
    profile = get_first_object_or_none(Profile.objects.filter(user=user))
    nickname = profile.nickname if profile else user.split('@')[0]
    cache.set(NICKNAME_CACHE_PREFIX + user, nickname, NICKNAME_CACHE_TIMEOUT)
Exemplo n.º 2
0
def refresh_cache(user):
    """
    Function to be called when change user nickname.
    """
    profile = get_first_object_or_none(Profile.objects.filter(user=user))
    nickname = profile.nickname if profile else user.split('@')[0]
    cache.set(NICKNAME_CACHE_PREFIX+user, nickname, NICKNAME_CACHE_TIMEOUT)
Exemplo n.º 3
0
def refresh_cache(username):
    """
    Function to be called when change user nickname.
    """
    profile = get_first_object_or_none(Profile.objects.filter(user=username))
    nickname = profile.nickname if profile else username.split('@')[0]

    key = normalize_cache_key(username, NICKNAME_CACHE_PREFIX)
    cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
Exemplo n.º 4
0
def refresh_cache(username):
    """
    Function to be called when change user nickname.
    """
    profile = get_first_object_or_none(Profile.objects.filter(user=username))
    nickname = profile.nickname if profile else username.split('@')[0]

    key = normalize_cache_key(username, NICKNAME_CACHE_PREFIX)
    cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
Exemplo n.º 5
0
def email2nickname(value):
    if not value:
        return ''
    
    nickname = cache.get(NICKNAME_CACHE_PREFIX+value)
    if not nickname:
        profile = get_first_object_or_none(Profile.objects.filter(user=value))
        nickname = profile.nickname if profile else value.split('@')[0]
        cache.set(NICKNAME_CACHE_PREFIX+value, nickname, NICKNAME_CACHE_TIMEOUT)
    return nickname
Exemplo n.º 6
0
def email2nickname(value):
    """
    Return nickname or short email.
    """
    if not value:
        return ''

    key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
    nickname = cache.get(key)
    if not nickname:
        profile = get_first_object_or_none(Profile.objects.filter(user=value))
        nickname = profile.nickname if profile else value.split('@')[0]
        cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
    return nickname
Exemplo n.º 7
0
def email2nickname(value):
    """
    Return nickname or short email.
    """
    if not value:
        return ''

    key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
    nickname = cache.get(key)
    if not nickname:
        profile = get_first_object_or_none(Profile.objects.filter(user=value))
        nickname = profile.nickname if profile else value.split('@')[0]
        cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
    return nickname
Exemplo n.º 8
0
def msg_reply_new(request):
    notes = UserNotification.objects.filter(to_user=request.user.username)
    grpmsg_reply_list = [ n.detail for n in notes if \
                              n.msg_type == 'grpmsg_reply']

    group_msgs = []
    for msg_id in grpmsg_reply_list:
        try:
            m = GroupMessage.objects.get(id=msg_id)
        except GroupMessage.DoesNotExist:
            continue
        else:
            # get group name
            group = get_group(m.group_id)
            if not group:
                continue
            m.group_name = group.group_name
            
            # get attachement
            attachment = get_first_object_or_none(m.messageattachment_set.all())
            if attachment:
                path = attachment.path
                if path == '/':
                    repo = get_repo(attachment.repo_id)
                    if not repo:
                        continue
                    attachment.name = repo.name
                else:
                    attachment.name = os.path.basename(path)
                m.attachment = attachment

            # get message replies
            reply_list = MessageReply.objects.filter(reply_to=m)
            m.reply_cnt = reply_list.count()
            if m.reply_cnt > 3:
                m.replies = reply_list[m.reply_cnt - 3:]
            else:
                m.replies = reply_list

            group_msgs.append(m)

    # remove new group msg reply notification
    UserNotification.objects.filter(to_user=request.user.username,
                                    msg_type='grpmsg_reply').delete()
    
    return render_to_response("group/new_msg_reply.html", {
            'group_msgs': group_msgs,
            }, context_instance=RequestContext(request))
Exemplo n.º 9
0
def email2nickname(value):
    """
    Return nickname if it exists and it's not an empty string,
    otherwise return short email.
    """
    if not value:
        return ''

    key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
    cached_nickname = cache.get(key)
    if cached_nickname and cached_nickname.strip():
        return cached_nickname.strip()

    profile = get_first_object_or_none(Profile.objects.filter(user=value))
    if profile is not None and profile.nickname and profile.nickname.strip():
        nickname = profile.nickname.strip()
    else:
        nickname = value.split('@')[0]

    cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
    return nickname
Exemplo n.º 10
0
def email2nickname(value):
    """
    Return nickname if it exists and it's not an empty string,
    otherwise return short email.
    """
    if not value:
        return ''

    key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
    cached_nickname = cache.get(key)
    if cached_nickname and cached_nickname.strip():
        return cached_nickname.strip()

    profile = get_first_object_or_none(Profile.objects.filter(user=value))
    if profile is not None and profile.nickname and profile.nickname.strip():
        nickname = profile.nickname.strip()
    else:
        nickname = value.split('@')[0]

    cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
    return nickname
Exemplo n.º 11
0
def msgreply_save_handler(sender, instance, **kwargs):
    """
    Handle sending notification to '@<user>' when reply messages.
    """
    from_email = instance.from_email
    reply_msg =  instance.message
    group_msg =  instance.reply_to
    to_user = ''

    from seahub.base.templatetags.seahub_tags import at_pattern
    m = re.match(at_pattern, reply_msg)
    if m:
        nickname_or_emailprefix = m.group()[1:]
        for member in get_group_members(group_msg.group_id):
            # For every group member, get his username and nickname if
            # it exists, check whether match.
            username = member.user_name
            if username == from_email:
                continue
            
            p = get_first_object_or_none(
                Profile.objects.filter(user=username))
            nickname = p.nickname if p else ''
            if nickname == nickname_or_emailprefix or \
                    username.split('@')[0] == nickname_or_emailprefix:
                to_user = username
                break

        if to_user:
            # Send notification to the user if he replies someone else'
            # message.
            try:
                UserNotification.objects.get(to_user=to_user,
                                             msg_type='grpmsg_reply',
                                             detail=group_msg.id)
            except UserNotification.DoesNotExist:
                n = UserNotification(to_user=to_user,
                                     msg_type='grpmsg_reply',
                                     detail=group_msg.id)
                n.save()