本文整理匯總了Python中askbot.models.Activity類的典型用法代碼示例。如果您正苦於以下問題:Python Activity類的具體用法?Python Activity怎麽用?Python Activity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Activity類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_questions_needing_reminder
def get_questions_needing_reminder(self,
user = None,
activity_type = None,
recurrence_delay = None):
"""returns list of questions that need a reminder,
corresponding the given ``activity_type``
``user`` - is the user receiving the reminder
``recurrence_delay`` - interval between sending the
reminders about the same question
"""
from askbot.models import Activity#avoid circular import
question_list = list()
for question in self:
try:
activity = Activity.objects.get(
user = user,
question = question,
activity_type = activity_type
)
now = datetime.datetime.now()
if now < activity.active_at + recurrence_delay:
continue
except Activity.DoesNotExist:
activity = Activity(
user = user,
question = question,
activity_type = activity_type,
content_object = question,
)
activity.active_at = datetime.datetime.now()
activity.save()
question_list.append(question)
return question_list
示例2: remember_last_moderator
def remember_last_moderator(user):
act = get_last_mod_alert_activity()
if act:
act.content_object = user
act.save()
else:
act = Activity(
user=user,
content_object=user,
activity_type=const.TYPE_ACTIVITY_MODERATION_ALERT_SENT
)
act.save()
示例3: remember_last_moderator
def remember_last_moderator(user):
"""Save the the `user` as the one that was notified last"""
act = get_last_mod_alert_activity()
if act:
act.content_object = user
act.save()
else:
act = Activity(
user=user,
content_object=user,
activity_type=const.TYPE_ACTIVITY_MODERATION_ALERT_SENT
)
act.save()
示例4: record_post_update
def record_post_update(
post = None,
updated_by = None,
newly_mentioned_users = None,
timestamp = None,
created = False,
diff = None
):
"""Called when a post is updated. Arguments:
* ``newly_mentioned_users`` - users who are mentioned in the
post for the first time
* ``created`` - a boolean. True when ``post`` has just been created
* remaining arguments are self - explanatory
The method does two things:
* records "red envelope" recipients of the post
* sends email alerts to all subscribers to the post
"""
#todo: take into account created == True case
(activity_type, update_object) = post.get_updated_activity_data(created)
if post.is_comment():
#it's just a comment!
summary = post.text
else:
#summary = post.get_latest_revision().summary
summary = diff
update_activity = Activity(
user = updated_by,
active_at = timestamp,
content_object = post,
activity_type = activity_type,
question = post.get_origin_post(),
summary = summary
)
update_activity.save()
#what users are included depends on the post type
#for example for question - all Q&A contributors
#are included, for comments only authors of comments and parent
#post are included
recipients = post.get_response_receivers(
exclude_list = [updated_by, ]
)
update_activity.add_recipients(recipients)
#create new mentions
for u in newly_mentioned_users:
#todo: a hack - some users will not have record of a mention
#may need to fix this in the future. Added this so that
#recipients of the response who are mentioned as well would
#not get two notifications in the inbox for the same post
if u in recipients:
continue
Activity.objects.create_new_mention(
mentioned_whom = u,
mentioned_in = post,
mentioned_by = updated_by,
mentioned_at = timestamp
)
assert(updated_by not in recipients)
for user in (set(recipients) | set(newly_mentioned_users)):
user.update_response_counts()
#todo: weird thing is that only comments need the recipients
#todo: debug these calls and then uncomment in the repo
#argument to this call
notification_subscribers = post.get_instant_notification_subscribers(
potential_subscribers = recipients,
mentioned_users = newly_mentioned_users,
exclude_list = [updated_by, ]
)
#todo: fix this temporary spam protection plug
if created:
if not (updated_by.is_administrator() or updated_by.is_moderator()):
if updated_by.reputation < 15:
notification_subscribers = \
[u for u in notification_subscribers if u.is_administrator()]
send_instant_notifications_about_activity_in_post(
update_activity = update_activity,
post = post,
recipients = notification_subscribers,
)
示例5: get_updated_questions_for_user
#.........這裏部分代碼省略.........
#build list of comment and mention responses here
#it is separate because posts are not marked as changed
#when people add comments
#mention responses could be collected in the loop above, but
#it is inconvenient, because feed_type m_and_c bundles the two
#also we collect metadata for these here
try:
feed = user_feeds.get(feed_type='m_and_c')
if feed.should_send_now():
cutoff_time = feed.get_previous_report_cutoff_time()
comments = Post.objects.get_comments().filter(
added_at__lt=cutoff_time
).exclude(author=user).select_related('parent')
q_commented = list()
for c in comments:
post = c.parent
if post.author_id != user.pk:
continue
#skip is post was seen by the user after
#the comment posting time
q_commented.append(post.get_origin_post())
extend_question_list(
q_commented,
q_list,
cutoff_time=cutoff_time,
add_comment=True,
languages=languages
)
mentions = Activity.objects.get_mentions(
mentioned_at__lt=cutoff_time,
mentioned_whom=user
)
#print 'have %d mentions' % len(mentions)
#MM = Activity.objects.filter(activity_type = const.TYPE_ACTIVITY_MENTION)
#print 'have %d total mentions' % len(MM)
#for m in MM:
# print m
mention_posts = get_all_origin_posts(mentions)
q_mentions_id = [q.id for q in mention_posts]
q_mentions_A = Q_set_A.filter(id__in = q_mentions_id)
q_mentions_A.cutoff_time = cutoff_time
extend_question_list(
q_mentions_A,
q_list,
add_mention=True,
languages=languages
)
q_mentions_B = Q_set_B.filter(id__in = q_mentions_id)
q_mentions_B.cutoff_time = cutoff_time
extend_question_list(
q_mentions_B,
q_list,
add_mention=True,
languages=languages
)
except EmailFeedSetting.DoesNotExist:
pass
示例6: record_post_update
def record_post_update(
post = None,
updated_by = None,
newly_mentioned_users = None,
timestamp = None,
created = False
):
"""Called when a post is updated. Arguments:
* ``newly_mentioned_users`` - users who are mentioned in the
post for the first time
* ``created`` - a boolean. True when ``post`` has just been created
* remaining arguments are self - explanatory
The method does two things:
* records "red envelope" recipients of the post
* sends email alerts to all subscribers to the post
"""
#todo: take into account created == True case
(activity_type, update_object) = post.get_updated_activity_data(created)
update_activity = Activity(
user = updated_by,
active_at = timestamp,
content_object = post,
activity_type = activity_type,
question = post.get_origin_post()
)
update_activity.save()
#what users are included depends on the post type
#for example for question - all Q&A contributors
#are included, for comments only authors of comments and parent
#post are included
recipients = post.get_response_receivers(
exclude_list = [updated_by, ]
)
update_activity.add_recipients(recipients)
assert(updated_by not in recipients)
for user in set(recipients) | set(newly_mentioned_users):
user.increment_response_count()
user.save()
#todo: weird thing is that only comments need the recipients
#todo: debug these calls and then uncomment in the repo
#argument to this call
notification_subscribers = post.get_instant_notification_subscribers(
potential_subscribers = recipients,
mentioned_users = newly_mentioned_users,
exclude_list = [updated_by, ]
)
#todo: fix this temporary spam protection plug
if created:
if not (updated_by.is_administrator() or updated_by.is_moderator()):
if updated_by.reputation < 15:
notification_subscribers = \
[u for u in notification_subscribers if u.is_administrator()]
send_instant_notifications_about_activity_in_post(
update_activity = update_activity,
post = post,
recipients = notification_subscribers,
)
示例7: UserExtension
thread_pks = Vote.objects.filter(pk__in=self.votes.all()).declareds().values_list('voted_post__thread__pk', flat=True).distinct()
return Action.objects.filter(thread__pk__in=thread_pks)
User.add_to_class('ext_noattr', UserExtension())
#remove old attribute to prevent duplicates in the Activity fields.
#1- search 'activity_type' into the Activity local_fields and save the index
local_fields = Activity._meta.local_fields
for field in local_fields:
if field.name == 'activity_type':
index = local_fields.index(field)
break
#2- remove the found element from the local_fields list.
Activity._meta.local_fields.pop(index)
#3- add to class
Activity.add_to_class('activity_type', models.SmallIntegerField(choices = ae_const.TYPE_ACTIVITY_CHOICES))
#4- move the added field to the last index to the previous one
field = local_fields.pop()
local_fields.insert(index, field)
#5- clean cache(s)
#del Activity._meta._field_cache
#del Activity._meta._field_name_cache
#print("\n\nActivity._meta.local_fields: %s\n\n" % Activity._meta.local_fields)
示例8: record_post_update
def record_post_update(
post = None,
updated_by = None,
newly_mentioned_users = None,
timestamp = None,
created = False
):
"""Called when a post is updated. Arguments:
* ``newly_mentioned_users`` - users who are mentioned in the
post for the first time
* ``created`` - a boolean. True when ``post`` has just been created
* remaining arguments are self - explanatory
The method does two things:
* records "red envelope" recipients of the post
* sends email alerts to all subscribers to the post
"""
start_time = time.time()
#todo: take into account created == True case
(activity_type, update_object) = post.get_updated_activity_data(created)
update_activity = Activity(
user = updated_by,
active_at = timestamp,
content_object = post,
activity_type = activity_type,
question = post.get_origin_post()
)
update_activity.save()
#what users are included depends on the post type
#for example for question - all Q&A contributors
#are included, for comments only authors of comments and parent
#post are included
recipients = post.get_response_receivers(
exclude_list = [updated_by, ]
)
update_activity.add_recipients(recipients)
assert(updated_by not in recipients)
for user in (set(recipients) | set(newly_mentioned_users)):
user.update_response_counts()
#todo: weird thing is that only comments need the recipients
#todo: debug these calls and then uncomment in the repo
#argument to this call
pre_notif_time = time.time()
notification_subscribers = post.get_instant_notification_subscribers(
potential_subscribers = recipients,
mentioned_users = newly_mentioned_users,
exclude_list = [updated_by, ]
)
#todo: fix this temporary spam protection plug
if False:
if not (updated_by.is_administrator() or updated_by.is_moderator()):
if updated_by.reputation < 15:
notification_subscribers = \
[u for u in notification_subscribers if u.is_administrator()]
#Updater always gets an email
notification_subscribers.append(updated_by)
pre_email_time = time.time()
send_instant_notifications_about_activity_in_post(
update_activity = update_activity,
post = post,
recipients = notification_subscribers,
)
debug_str = "\nTitle: %s" % post.get_origin_post().title
debug_str += "\nEmailed%s\n" % get_subs_email(notification_subscribers)
#debug_str += " Pre-notif Time: %8.3f\n" % float(pre_notif_time - start_time)
#debug_str += " Sub Search Time: %8.3f\n" % float(pre_email_time - pre_notif_time)
#debug_str += " Email Time: %8.3f\n" % float(time.time() - pre_email_time)
debug_str += "Total Elapsed Time: %8.3f" % float(time.time() - start_time)
logging.critical(debug_str)
示例9: record_post_update_task
def record_post_update_task(
post_id,
post_content_type_id,
newly_mentioned_user_id_list = None,
updated_by_id = None,
timestamp = None,
created = False,
):
updated_by = User.objects.get(id = updated_by_id)
post_content_type = ContentType.objects.get(id = post_content_type_id)
post = post_content_type.get_object_for_this_type(id = post_id)
#todo: take into account created == True case
(activity_type, update_object) = post.get_updated_activity_data(created)
update_activity = Activity(
user = updated_by,
active_at = timestamp,
content_object = post,
activity_type = activity_type,
question = post.get_origin_post()
)
update_activity.save()
#what users are included depends on the post type
#for example for question - all Q&A contributors
#are included, for comments only authors of comments and parent
#post are included
recipients = post.get_response_receivers(
exclude_list = [updated_by, ]
)
update_activity.add_recipients(recipients)
assert(updated_by not in recipients)
newly_mentioned_users = User.objects.filter(
id__in = newly_mentioned_user_id_list
)
for user in set(recipients) | set(newly_mentioned_users):
user.increment_response_count()
user.save()
#todo: weird thing is that only comments need the recipients
#todo: debug these calls and then uncomment in the repo
#argument to this call
notification_subscribers = post.get_instant_notification_subscribers(
potential_subscribers = recipients,
mentioned_users = newly_mentioned_users,
exclude_list = [updated_by, ]
)
#todo: fix this temporary spam protection plug
if created:
if not (updated_by.is_administrator() or updated_by.is_moderator()):
if updated_by.reputation < 15:
notification_subscribers = \
[u for u in notification_subscribers if u.is_administrator()]
send_instant_notifications_about_activity_in_post(
update_activity = update_activity,
post = post,
recipients = notification_subscribers,
)