本文整理汇总了Python中bootcamp.activities.models.Activity.save方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.save方法的具体用法?Python Activity.save怎么用?Python Activity.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bootcamp.activities.models.Activity
的用法示例。
在下文中一共展示了Activity.save方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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: setUp
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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()
示例9: execute_upload
# 需要导入模块: from bootcamp.activities.models import Activity [as 别名]
# 或者: from bootcamp.activities.models.Activity import save [as 别名]
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