Пример #1
0
def user_timeline(request, user_pk):
    get_activities_num = 80
    per_page = 15
    enricher = Enrich(
        fields=['actor', 'object', 'bet_event', 'total_bet', 'event'])
    logger.debug("getting timeline feed...")
    user_timeline = stream_client.feed(FeedNames.timeline, user_pk)
    # we collect a number of activities and then we can filter or paginate them as we want
    activities = user_timeline.get(limit=get_activities_num)['results']
    # next_activities = user_timeline.get(limit=50, id_lt=activities[-1]['id'])['results']
    # enriched activities is a list of stream_django.enrich.EnrichedActivity instances (they have __getitem__, __iter__)
    enriched_activities = enricher.enrich_activities(activities)
    # # add_isopen_to_tb_enriched_activities(enriched_activities)
    paginator = Paginator(enriched_activities, per_page)
    enriched_activities = zakanda.utils.paginate(request, paginator,
                                                 enriched_activities)
    # enriched_activities_2 = enricher.enrich_activities(next_activities)
    enriched_activities_2 = None
    # # add_isopen_to_tb_enriched_activities(enriched_activities_2)

    context = {
        'enriched_activities': enriched_activities,
        'enriched_activities_2': enriched_activities_2,
        'not_started': games.models.Event.not_started
    }
    return TemplateResponse(request, 'feeds/timeline.html', context)
Пример #2
0
def user_notification_timeline(request, user_id):
    # todo high don't allow others to see the notifications of another user by changing the url (same with tips)
    # TODO high more button to load the next activities
    # I use the low level client (stream_client) instead of the high level feedmanager of the stream django app
    # without specific reason so I can use the feedmanager instead
    get_activities_num = 80
    per_page = 12
    user_notification_feed = stream_client.feed(FeedNames.notification,
                                                user_id)
    # it seems that first the activities are collected and then they are marked as seen. This way I can
    # check if an activity is currently seen or not
    activities = user_notification_feed.get(limit=get_activities_num,
                                            mark_seen=True,
                                            mark_read=True)['results']
    # next_activities = user_notification_feed.get(limit=get_activities_num, id_lt=activities[-1]['id'])['results']
    enricher = Enrich(
        fields=['actor', 'object', 'bet_event', 'total_bet', 'event'])
    enriched_activities = enricher.enrich_aggregated_activities(activities)
    paginator = Paginator(enriched_activities, per_page)
    enriched_activities = zakanda.utils.paginate(request, paginator,
                                                 enriched_activities)
    context = {
        'enriched_activities': enriched_activities,
        'not_started': games.models.Event.not_started
    }
    return TemplateResponse(request, 'feeds/timeline.html', context)
Пример #3
0
    def get(self, request, *args, **kwargs):
        if request.GET.get('partial') == 'activities':
            # activities
            try:
                project = self.get_object()
                enricher = Enrich((
                    'actor',
                    'target',
                ))
                feed = feed_manager.get_challenge_feed(challenge_id=project.pk)
                activities = feed.get(limit=6)['results']
                enriched = enricher.enrich_activities(activities)
                return render(request, 'projects/_activities.html',
                              {'activities': enriched})
            except Exception:
                return HttpResponse()

        if request.GET.get('partial') == 'completed':
            # current user status
            data = {'completed': False}
            try:
                user = request.user
                if not user.is_authenticated():
                    raise Exception('not authenticated')

                project = self.get_object()
                user_project = UserProject.objects.get(project=project,
                                                       user=request.user)
                data['complete'] = user_project.is_complete()
            except Exception:
                pass
            return JsonResponse(data)

        return super().get(request, *args, **kwargs)
Пример #4
0
def profile_feed(request, username=None):
    enricher = Enrich()
    user = User.objects.get(username=username)
    feed = feed_manager.get_user_feed(user.id)
    activities = feed.get(limit=25)['results']
    enricher.enrich_activities(activities)
    context = {'activities': activities}
    return render(request, 'tweets.html', context)
Пример #5
0
def notifications(request):
    user = request.user

    notification_feed = feed_manager.get_notification_feed(user.id)
    notification_stats = notification_feed.get(limit=10, mark_seen=True)
    enricher = Enrich()
    notifications = enricher.enrich_aggregated_activities(
        notification_stats['results'])

    return render(request, 'activity/aggregated/report.html',
                  {'notifications': notifications})
Пример #6
0
 def get(self, request):
     if request.GET.get('partial') == 'activities':
         try:
             enricher = Enrich(('actor', 'object', 'target'))
             feed = feed_manager.get_global_challenge_feed()
             activities = feed.get(limit=10)['results']
             enriched = enricher.enrich_aggregated_activities(activities)
             return render(request, 'base/_activities.html',
                           {'activities': enriched})
         except Exception as e:
             return HttpResponse()
     return super().get(request)
Пример #7
0
 def get(self, request):
     user = self.request.user
     if request.GET.get('partial') == 'notifications':
         try:
             enricher = Enrich(('actor', 'object', 'target',))
             feed = feed_manager.get_notification_feed(user.id)
             activities = feed.get(limit=10)['results']
             enriched = enricher.enrich_aggregated_activities(activities)
         except Exception:
             enriched = []
         finally:
             return render(request, 'account/_notifications_card_content.html', {'notifications': enriched})
     return super().get(request)
Пример #8
0
def user_aggregated_timeline(request, user_pk):
    get_activities_num = 80
    per_page = 15
    user_aggr_timeline = stream_client.feed(FeedNames.timeline_aggregated,
                                            user_pk)
    activities = user_aggr_timeline.get(limit=get_activities_num)['results']
    # logger.debug("activities: %s", activities['activities'])
    enricher = Enrich(
        fields=['actor', 'object', 'bet_event', 'total_bet', 'event'])
    enriched_activities = enricher.enrich_aggregated_activities(activities)
    paginator = Paginator(enriched_activities, per_page)
    enriched_activities = zakanda.utils.paginate(request, paginator,
                                                 enriched_activities)
    feeds.utils.print_enriched_aggr_activities(enriched_activities)
    context = {
        'enriched_activities': enriched_activities,
        'not_started': games.models.Event.not_started
    }
    return TemplateResponse(request, 'feeds/timeline.html', context)
Пример #9
0
 def get(self, request):
     user = self.request.user
     if request.GET.get("partial") == "notifications":
         try:
             enricher = Enrich(
                 (
                     "actor",
                     "object",
                     "target",
                 )
             )
             feed = feed_manager.get_notification_feed(user.id)
             activities = feed.get(limit=10)["results"]
             enriched = enricher.enrich_aggregated_activities(activities)
         except Exception:
             enriched = []
         finally:
             return render(
                 request,
                 "account/_notifications_card_content.html",
                 {"notifications": enriched},
             )
     return super().get(request)
Пример #10
0
from django.views.generic.edit import CreateView
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from stream_django.enrich import Enrich
from stream_django.feed_manager import feed_manager
from stream_twitter.forms import FollowForm
from stream_twitter.models import Follow
from stream_twitter.models import Tweet, Hashtag
from pytutorial import settings
import random

enricher = Enrich()


class TimelineView(CreateView):
    model = Tweet
    fields = ['text']
    success_url = "/timeline/"

    def form_valid(self, form):
        form.instance.user = self.request.user
        return super(TimelineView, self).form_valid(form)

    def get(self, request):
        feeds = feed_manager.get_news_feeds(request.user.id)
        activities = feeds.get('timeline').get()['results']
        activities = enricher.enrich_activities(activities)
        hashtags = Hashtag.objects.order_by('-occurrences')
        context = {
            'activities': activities,
Пример #11
0
 def setUp(self):
     feed_manager.enable_model_tracking()
     self.User = get_user_model()
     self.bogus = self.User.objects.create()
     self.enricher = Enrich()