Пример #1
0
 def sidebar(self, context):
     user = context.get('user', None)
     viewing_user = context.get('viewing_user', None)
     if not viewing_user and not user.is_authenticated():
         return ''
     else:
         user = viewing_user or user
         replies = str(Post.active().filter(text__contains="@"+user.username).count())
         posts = str(Post.active().filter(user=user).count())
         url = reverse('contrib.replies.views.replies')
         return self.script +\
                 '<a href="'+url+'">'+_('Replies')+'</a>: '+replies+\
                 ' | '+_('Sweets')+': '+posts
Пример #2
0
 def sidebar(self, context):
     user = context.get('user', None)
     viewing_user = context.get('viewing_user', None)
     if not viewing_user and not user.is_authenticated():
         return ''
     else:
         user = viewing_user or user
         replies = str(Post.active().filter(text__contains="@" +
                                            user.username).count())
         posts = str(Post.active().filter(user=user).count())
         url = reverse('contrib.replies.views.replies')
         return self.script +\
                 '<a href="'+url+'">'+_('Replies')+'</a>: '+replies+\
                 ' | '+_('Sweets')+': '+posts
Пример #3
0
def get_replies(request, user_name=None):
    if user_name is None:
        user_name = request.user.username
    q = Q(text__contains = "@"+user_name)
    latest_post_list = Post.active().filter(q).order_by('-pub_date')

    return latest_post_list
Пример #4
0
def public_timeline(request=None, paginated=True):
    if not request:
        request = Request_moc(None)

    latest_post_list = Post.active().order_by('-pub_date')
    if paginated:
        latest_post_list = paginate_list(request, latest_post_list)

    return latest_post_list
Пример #5
0
def public_timeline(request=None, paginated=True):
    if not request:
        request = Request_moc(None)

    latest_post_list = Post.active().order_by('-pub_date')
    if paginated:
        latest_post_list = paginate_list(request, latest_post_list)

    return latest_post_list
Пример #6
0
def new_post(user, text, request=None):
    if not request:
        request = Request_moc(user)

    post = Post(text=text, user=user, pub_date=datetime.datetime.now())

    intercepted = False

    # hook for pluggins for intercepting messages. This can cancel posting them.
    for p in ublogging.plugins:
        if not intercepted:
            intercepted = p.posting(request, post)

    if not intercepted:
        post.save()
        for p in ublogging.plugins:
            p.posted(request, post)
    else:
        post = None

    return post
Пример #7
0
def new_post(user, text, request=None):
    if not request:
        request = Request_moc(user)

    post = Post(text=text, user=user, pub_date=datetime.datetime.now())

    intercepted = False

    # hook for pluggins for intercepting messages. This can cancel posting them.
    for p in ublogging.plugins:
        if not intercepted:
            intercepted = p.posting(request, post)

    if not intercepted:
        post.save()
        for p in ublogging.plugins:
            p.posted(request, post)
    else:
        post = None

    return post
Пример #8
0
    def down_user_karma(self):
        from contrib.karma.models import Karma
        from ublogging.models import Post
        all = Karma.objects.exclude(karma=0.0)
        for karma in all:
            n = Post.active().filter(user=karma.user,
                            pub_date__gt=DATE).count()

            ratio = RATIO2
            if n:
                ratio = RATIO1

            karma.karma = karma.karma * ratio
            karma.save()
Пример #9
0
def messages(request, group_name):
    g = Group.objects.get(name__iexact=group_name)
    q = Q()
    for user_temp in g.users.all():
        q = q | Q(user=user_temp.user)
    latest_post_list = Post.active().filter(q).order_by('-pub_date')
    paginator = Paginator(latest_post_list, 10)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        latest_post_list = paginator.page(page)
    except (EmptyPage, InvalidPage):
        latest_post_list = paginator.page(paginator.num_pages)

    return render_to_response('status/index.html',
                              {'latest_post_list': latest_post_list},
                              context_instance=RequestContext(request))
Пример #10
0
def messages(request,group_name):
    g = Group.objects.get(name__iexact=group_name)
    q = Q()
    for user_temp in g.users.all():
        q = q | Q(user = user_temp.user)
    latest_post_list = Post.active().filter(q).order_by('-pub_date')
    paginator = Paginator(latest_post_list, 10)

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    try:
        latest_post_list = paginator.page(page)
    except (EmptyPage, InvalidPage):
        latest_post_list = paginator.page(paginator.num_pages)

    return render_to_response('status/index.html', {
            'latest_post_list': latest_post_list
        }, context_instance=RequestContext(request))
Пример #11
0
def refresh_index(request, lastid=1, latest_post_list=None):
    url = request.META.get('HTTP_REFERER', '/public_timeline')
    usere = r'(.*)/user/(?P<username>[^\?\/]*)'
    publice = r'(.*)/public_timeline'
    lastid = int(lastid)
    if not lastid:
        lastid = 1

    user_timeline = re.match(usere, url)
    public_timeline = re.match(publice, url)
    if latest_post_list:
        pass
    elif user_timeline:
        latest_post_list = uapi.user_timeline(user_timeline.group('username'),
                                              request,
                                              paginated=False)
    elif public_timeline:
        latest_post_list = uapi.public_timeline(request, paginated=False)
    else:
        try:
            latest_post_list = uapi.own_timeline(request, paginated=False)
        except:
            latest_post_list = uapi.public_timeline(request, paginated=False)

    try:
        lastpost = Post.active().get(pk=lastid)
        if request.GET.get('viewmore', False):
            filter = Q(pub_date__lt=lastpost.pub_date)
            latest_post_list = latest_post_list.filter(
                filter)[:settings.POST_PER_PAGE]
        else:
            filter = Q(pub_date__gt=lastpost.pub_date)
            latest_post_list = latest_post_list.filter(filter)

        return render_to_response('status/refresh.html',
                                  {'latest_post_list': latest_post_list},
                                  context_instance=RequestContext(request))
    except:
        return HttpResponse("")
Пример #12
0
def refresh_index(request, lastid=1, latest_post_list=None):
    url = request.META.get('HTTP_REFERER', '/public_timeline')
    usere = r'(.*)/user/(?P<username>[^\?\/]*)'
    publice = r'(.*)/public_timeline'
    lastid=int(lastid)
    if not lastid:
        lastid = 1

    user_timeline = re.match(usere, url)
    public_timeline = re.match(publice, url)
    if latest_post_list:
        pass
    elif user_timeline:
        latest_post_list = uapi.user_timeline(user_timeline.group('username'), request, paginated=False)
    elif public_timeline:
        latest_post_list = uapi.public_timeline(request, paginated=False)
    else:
        try:
            latest_post_list = uapi.own_timeline(request, paginated=False)
        except:
            latest_post_list = uapi.public_timeline(request, paginated=False)

    try:
        lastpost = Post.active().get(pk=lastid)
        if request.GET.get('viewmore', False):
            filter = Q(pub_date__lt=lastpost.pub_date)
            latest_post_list = latest_post_list.filter(filter)[:settings.POST_PER_PAGE]
        else:
            filter = Q(pub_date__gt=lastpost.pub_date)
            latest_post_list = latest_post_list.filter(filter)

        return render_to_response('status/refresh.html',
                                {'latest_post_list': latest_post_list },
                                context_instance=RequestContext(request))
    except:
        return HttpResponse("")
Пример #13
0
def show_statuses(request, query, paginated=True):
    latest_post_list = Post.active().filter(query).order_by('-pub_date')
    if paginated:
        latest_post_list = paginate_list(request, latest_post_list)

    return latest_post_list
Пример #14
0
def show_statuses(request, query, paginated=True):
    latest_post_list = Post.active().filter(query).order_by('-pub_date')
    if paginated:
        latest_post_list = paginate_list(request, latest_post_list)

    return latest_post_list