當前位置: 首頁>>代碼示例>>Python>>正文


Python models.Activity類代碼示例

本文整理匯總了Python中bootcamp.activities.models.Activity的典型用法代碼示例。如果您正苦於以下問題:Python Activity類的具體用法?Python Activity怎麽用?Python Activity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Activity類的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

    def setUp(self):
        self.user = get_user_model().objects.create_user(
            username='test_user',
            email='[email protected]',
            password='top_secret'
        )
        self.other_user = get_user_model().objects.create_user(
            username='other_test_user',
            email='[email protected]',
            password='top_secret'
        )
        self.feed = Feed.objects.create(
            user=self.user,
            post='A not so long text',
            likes=0,
            comments=0
        )

        self.feed2 = Feed.objects.create(
            user=self.user,
            post='Another text',
            likes=0,
            comments=0
        )

        self.feed.comment(self.other_user, 'my comment')

        like = Activity(activity_type=Activity.LIKE, feed=self.feed.id, user=self.other_user)
        like.save()
        self.user.profile.notify_liked(self.feed)
開發者ID:ghsaheb,項目名稱:Bootcamp,代碼行數:30,代碼來源:test_models.py

示例2: like

def like(request):
    feed_id = request.POST['feed']
    feed = Feed.objects.get(pk=feed_id)
    user = request.user
    like = Activity.objects.filter(activity_type=Activity.LIKE, feed=feed_id, user=user)
    if like:
        like.delete()
    else:
        like = Activity(activity_type=Activity.LIKE, feed=feed_id, user=user)
        like.save()
    return HttpResponse(feed.calculate_likes())
開發者ID:lucasmg,項目名稱:bootcamp,代碼行數:11,代碼來源:views.py

示例3: favorite

def favorite(request):
    question_id = request.POST['question']
    question = Question.objects.get(pk=question_id)
    user = request.user
    activity = Activity.objects.filter(activity_type=Activity.FAVORITE, user=user, question=question_id)
    if activity:
        activity.delete()
    else:
        activity = Activity(activity_type=Activity.FAVORITE, user=user, question=question_id)
        activity.save()
    return HttpResponse(question.calculate_favorites())
開發者ID:lucasmg,項目名稱:bootcamp,代碼行數:11,代碼來源:views.py

示例4: vote

def vote(request):
    answer_id = request.POST['answer']
    answer = Answer.objects.get(pk=answer_id)
    vote = request.POST['vote']
    user = request.user
    activity = Activity.objects.filter(Q(activity_type=Activity.UP_VOTE) | Q(activity_type=Activity.DOWN_VOTE), user=user, answer=answer_id)
    if activity:
        activity.delete()
    if vote in [Activity.UP_VOTE, Activity.DOWN_VOTE]:
        activity = Activity(activity_type=vote, user=user, answer=answer_id)
        activity.save()
    return HttpResponse(answer.calculate_votes())
開發者ID:maxpinto,項目名稱:Ptz,代碼行數:12,代碼來源:views.py

示例5: like

def like(request):
    kpop_id = request.POST['kpop']
    kpop = Kpop.objects.get(pk=kpop_id)
    user = request.user
    like = Activity.objects.filter(activity_type=Activity.LIKE, kpop=kpop_id, user=user)
    if like:
        user.profile.unotify_liked(kpop)
        like.delete()
    else:
        like = Activity(activity_type=Activity.LIKE, kpop=kpop_id, user=user)
        like.save()
        user.profile.notify_liked(kpop)
    return HttpResponse(kpop.calculate_likes())
開發者ID:namkim,項目名稱:bootcamp,代碼行數:13,代碼來源:views.py

示例6: like

def like(request):
    feed_id = request.POST['feed']
    feed = Feed.objects.get(pk=feed_id)
    user = request.user
    like = Activity.objects.filter(activity_type=Activity.LIKE, feed=feed_id,
                                   user=user)
    if like:
        user.profile.unotify_liked(feed)
        like.delete()

    else:
        like = Activity(activity_type=Activity.LIKE, feed=feed_id, user=user)
        like.save()
        user.profile.notify_liked(feed)
        Notification.set_notify(user.username)

    return HttpResponse(feed.calculate_likes())
開發者ID:DAS2016-1,項目名稱:bootcamp,代碼行數:17,代碼來源:views.py

示例7: question_vote

def question_vote(request):
    question_id = request.POST['question']
    question = Question.objects.get(pk=question_id)
    vote = request.POST['vote']
    user = request.user
    activity = Activity.objects.filter(
        Q(activity_type=Activity.UP_VOTE) | Q(activity_type=Activity.DOWN_VOTE),  # noqa: E501
        user=user, question=question_id)
    if activity:
        activity.delete()

    if vote in [Activity.UP_VOTE, Activity.DOWN_VOTE]:
        activity = Activity(activity_type=vote,
                            user=user, question=question_id)
        activity.save()

    return HttpResponse(question.calculate_votes())
開發者ID:ghsaheb,項目名稱:Bootcamp,代碼行數:17,代碼來源:views.py

示例8: test_activity_monthly_statistic

 def test_activity_monthly_statistic(self):
     activity_one = Activity.objects.create(
         user=self.user,
         activity_type='L'
     )
     activity_two = Activity.objects.create(
         user=self.user,
         activity_type='L'
     )
     activity_three = Activity.objects.create(
         user=self.user,
         activity_type='L'
     )
     self.assertTrue(isinstance(activity_one, Activity))
     self.assertTrue(isinstance(activity_two, Activity))
     self.assertTrue(isinstance(activity_three, Activity))
     self.assertEqual(Activity.monthly_activity(self.user)[0],
                      '[{}]'.format(Activity.objects.all().count()))
     self.assertEqual(Activity.monthly_activity(self.other_user)[0], '0')
開發者ID:ghsaheb,項目名稱:Bootcamp,代碼行數:19,代碼來源:test_models.py

示例9: profile

def profile(request, username):
    page_user = get_object_or_404(User, username=username)
    all_feeds = Feed.get_feeds().filter(user=page_user)
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    if feeds:  # pragma: no cover
        from_feed = feeds[0].id

    feeds_count = Feed.objects.filter(user=page_user).count()
    article_count = Article.objects.filter(create_user=page_user).count()
    article_comment_count = ArticleComment.objects.filter(
        user=page_user).count()
    question_count = Question.objects.filter(user=page_user).count()
    answer_count = Answer.objects.filter(user=page_user).count()
    activity_count = Activity.objects.filter(user=page_user).count()
    messages_count = Message.objects.filter(
        Q(from_user=page_user) | Q(user=page_user)).count()
    data, datepoints = Activity.daily_activity(page_user)
    data = {
        'page_user': page_user,
        'feeds_count': feeds_count,
        'article_count': article_count,
        'article_comment_count': article_comment_count,
        'question_count': question_count,
        'global_interactions': activity_count + article_comment_count + answer_count + messages_count,  # noqa: E501
        'answer_count': answer_count,
        'bar_data': [
            feeds_count, article_count, article_comment_count, question_count,
            answer_count, activity_count],
        'bar_labels': json.dumps('["Feeds", "Articles", "Comments", "Questions", "Answers", "Activities"]'),  # noqa: E501
        'line_labels': datepoints,
        'line_data': data,
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1
        }
    return render(request, 'core/profile.html', data)
開發者ID:ghsaheb,項目名稱:Bootcamp,代碼行數:38,代碼來源:views.py

示例10: setUp

 def setUp(self):
     # creates a fictif user
     u = User()
     u.username = "testusername"
     u.password = "secretpassword"
     u.save()
     
     # create an activity related to that user
     activity = Activity()
     activity.user = u
     activity.activity_type = "Favorite"
     activity.date = timezone.now()
     
     # check we can save it to the database
     activity.save()
     
     # creates two fictif users
     u1 = User()
     u1.username = "testusername1"
     u1.password = "secretpassword1"
     u1.save()
     u2 = User()
     u2.username = "testusername2"
     u2.password = "secretpassword2"
     u2.save()
     
     # create one notification for each type of notification
     # Liked
     notifL = Notification()
     notifL.from_user = u1
     notifL.to_user = u2
     notifL.date = timezone.now()
     notifL.notification_type = 'Liked' # this is a like
     # save it to the database
     notifL.save()
     # Commented
     notifC = Notification()
     notifC.from_user = u1
     notifC.to_user = u2
     notifC.date = timezone.now()
     notifC.notification_type = 'Commented'
     # save it to the database
     notifC.save()
     # Favorited
     notifF = Notification()
     notifF.from_user = u1
     notifF.to_user = u2
     notifF.date = timezone.now()
     notifF.notification_type = 'Favorited'
     # save it to the database
     notifF.save()
     # Answered
     notifA = Notification()
     notifA.from_user = u1
     notifA.to_user = u2
     notifA.date = timezone.now()
     notifA.notification_type = 'Answered'
     # save it to the database
     notifA.save()
     # Accepted answer
     notifW = Notification()
     notifW.from_user = u1
     notifW.to_user = u2
     notifW.date = timezone.now()
     notifW.notification_type = 'Accepted Answer'
     # save it to the database
     notifW.save()
     # Edited article
     notifE = Notification()
     notifE.from_user = u1
     notifE.to_user = u2
     notifE.date = timezone.now()
     notifE.notification_type = 'Edited Article'
     # save it to the database
     notifE.save()
     # Also commented
     notifS = Notification()
     notifS.from_user = u1
     notifS.to_user = u2
     notifS.date = timezone.now()
     notifS.notification_type = 'Also Commented'
     # save it to the database
     notifS.save()
開發者ID:gvrossom,項目名稱:bootcamp,代碼行數:83,代碼來源:tests.py

示例11: execute_upload

    def execute_upload(self,request):
                import uuid
                form = self.form_class(request.POST, request.FILES)
                print request.FILES['file']
                if  form.is_valid():
                    print request.FILES['file']
                    resp = self.handle_uploaded_file(request.FILES['file'])
                    if resp['score'] < 100 :
                        button_type = 'btn-warning'
                    else:
                        button_type = 'btn-success'
                    self.uuid_index  = str(uuid.uuid4())


                    resp['score']= random.randint(1, 100)

                    model = Algorithm

                    run_rank = model.objects.filter(rating__gt=int(resp['score'])).order_by('ranking')
                    if len(run_rank) > 0:
                        rankobj = run_rank.last()
                        rank = rankobj.ranking + 1

                    else:
                        rank = 1

                    run_rank_low = model.objects.filter(rating__lte=int(resp['score']))
                    if len(run_rank_low) > 0 :
                        for i in run_rank_low:
                            i.ranking += 1
                            i.save()

                    else:
                        pass

                    
                   

                    b = Algorithm(run_id= self.uuid_index, name=request.user.username, user=request.user, ranking = rank, rating=resp['score'], button = button_type, time= resp['duration'], cpu=18)
                    b.save()
                    job_post = u'{0} has sent a job score: {1} rank: {2} :'.format(request.user.username,resp['score'], rank)
                    
                    resp = model.objects.all().order_by('ranking')
                    values = resp.values('run_id')
                    
                    for ind, item  in enumerate(values) :
                        if (item['run_id']) == self.uuid_index :
                            paging =  divmod(ind, 5)[0]

                    feed = Feed(user=request.user, post=job_post, job_link='/leaderboard?q=foo&flop=flip&page='+str(paging+1))
                    feed.save()


                    #request.user.profile.notify_job_done(b)      
                    

                    like = Activity(activity_type=Activity.RUN_PROCESSED, feed=feed.pk, user=request.user)
                    like.save()

                    user = request.user
                    user.profile.notify_liked_bis(feed)
                    

                    return paging
開發者ID:echopen,項目名稱:kit-soft,代碼行數:64,代碼來源:views.py


注:本文中的bootcamp.activities.models.Activity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。