本文整理汇总了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)
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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')
示例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)
示例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()
示例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