def save_activity(self, status=None, *args, **kwargs): """ Creates or updates an activity related to this article """ from film20.useractivity.models import UserActivity act = None # Checking if activity already exists for the given article, # if so update activity try: act = UserActivity.objects.get(post = self, user = self.user) # otherwise, create a new one except UserActivity.DoesNotExist: act = UserActivity() act.user = self.user act.activity_type = UserActivity.TYPE_POST act.post = self act.title = self.get_title() if self.lead: act.content = self.lead else: act.content = self.body rf = self.related_film.all() # special case: one film related with article - article is a review if len(rf) == 1: act.film_title = rf[0].get_title() act.film = rf[0] act.film_permalink = rf[0].permalink else: act.film = None act.film_title = None act.film_permalink = None act.username = self.user.username act.spoilers = self.spoilers act.status = self.status act.permalink = self.get_absolute_url() # legacy act.number_of_comments = self.number_of_comments if self.featured_note or self.is_published: act.featured = True else: act.featured = False if self.publish is not None: act.created_at = self.publish act.save()
def save_activity(self): """ Save new activity, if activity exists updates it """ from film20.useractivity.models import UserActivity if not self.content_object: raise Exception("ThreadedComment.save_activity: content_object" "missing for new commment") try: # Checking if activity already exists for given note, if so update activity act = UserActivity.objects.get(activity_type = UserActivity.TYPE_COMMENT, comment = self, user = self.user) act.content = self.comment act.title = self.content_object.get_comment_title() act.username = self.user.username act.is_first_post = self.is_first_post act.status = self.status if settings.ENSURE_OLD_STYLE_PERMALINKS: act.permalink = self.content_object.get_absolute_url_old_style() + "#" + str(self.id) else: act.permalink = self.content_object.get_absolute_url() + "#" + str(self.id) act.slug = self.content_object.get_slug() + "#" + str(self.id) act.number_of_comments = self.number_of_comments act.save() except UserActivity.DoesNotExist: # Activity does not exist - create a new one act = UserActivity() act.user = self.user act.username = self.user.username act.activity_type = UserActivity.TYPE_COMMENT act.comment = self # title for object related with comment act.title = self.content_object.get_comment_title() act.content = self.comment act.is_first_post = self.is_first_post act.status = self.status if settings.ENSURE_OLD_STYLE_PERMALINKS: act.permalink = self.content_object.get_absolute_url_old_style() + "#" + str(self.id) else: act.permalink = self.content_object.get_absolute_url() + "#" + str(self.id) act.slug = self.content_object.get_slug() + "#" + str(self.id) act.number_of_comments = self.number_of_comments act.save()
def save_activity(self): """ Save new activity """ from film20.useractivity.models import UserActivity try: # Checking if activity already exists for given externallink, if so update activity act = UserActivity.objects.get(link=self, user=self.user) act.url = self.url act.url_kind = self.url_kind act.video_thumb = getattr(self, "video_thumb", None) act.title = self.get_title() act.content = getattr(self, "excerpt", None) act.film = getattr(self, "film", None) act.film_title = self.film.get_title() act.film_permalink = self.film.permalink act.status = self.status act.permalink = self.get_absolute_url() act.number_of_comments = self.number_of_comments act.save() except UserActivity.DoesNotExist: # Activity does not exist - create a new one act = UserActivity() act.user = self.user act.username = self.user.username act.activity_type = UserActivity.TYPE_LINK act.link = self act.url = self.url act.url_kind = self.url_kind act.video_thumb = getattr(self, "video_thumb", None) act.title = self.get_title() act.content = getattr(self, "excerpt", None) act.film = getattr(self, "film", None) act.film_title = self.film.get_title() act.film_permalink = self.film.permalink act.status = self.status act.permalink = self.get_absolute_url() act.number_of_comments = self.number_of_comments act.save()