def save(self, request):
     """
     Saves a new comment and sends any notification emails.
     """
     comment = self.get_comment_object()
     obj = comment.content_object
     if request.user.is_authenticated():
         comment.user = request.user
     comment.by_author = request.user == getattr(obj, "user", None)
     comment.ip_address = ip_for_request(request)
     comment.replied_to_id = self.data.get("replied_to")
     comment.save()
     comment_was_posted.send(sender=comment.__class__,
                             comment=comment,
                             request=request)
     notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
     if notify_emails:
         subject = ugettext("New comment for: ") + str(obj)
         context = {
             "comment": comment,
             "comment_url": add_cache_bypass(comment.get_absolute_url()),
             "request": request,
             "obj": obj,
         }
         send_mail_template(subject, "email/comment_notification",
                            settings.DEFAULT_FROM_EMAIL, notify_emails,
                            context)
     return comment
Beispiel #2
0
 def save(self, request):
     """
     Saves a new comment and sends any notification emails.
     """
     comment = self.get_comment_object()
     obj = comment.content_object
     if request.user.is_authenticated():
         comment.user = request.user
     comment.by_author = request.user == getattr(obj, "user", None)
     comment.ip_address = ip_for_request(request)
     comment.replied_to_id = self.data.get("replied_to")
     comment.save()
     comment_was_posted.send(sender=comment.__class__, comment=comment,
                             request=request)
     notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
     if notify_emails:
         subject = _("New comment for: ") + str(obj)
         context = {
             "comment": comment,
             "comment_url": add_cache_bypass(comment.get_absolute_url()),
             "request": request,
             "obj": obj,
         }
         send_mail_template(subject, "email/comment_notification",
                            settings.DEFAULT_FROM_EMAIL, notify_emails,
                            context)
     return comment
    def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        comment = self.get_comment_object()
        obj = comment.content_object
        if request.user.is_authenticated():
            comment.user = request.user
            comment.user_name = best_name(comment.user)

        comment.by_author = request.user == getattr(obj, "user", None)
        comment.ip_address = ip_for_request(request)
        comment.replied_to_id = self.data.get("replied_to")
        comment.save()
        comment_was_posted.send(sender=comment.__class__, comment=comment,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        notify_emails.append(obj.user.email)
        reply_to_comment = comment.replied_to
        if reply_to_comment is not None:
            notify_emails.append(reply_to_comment.user.email)
        if notify_emails:
            subject = "[HydroShare Support] New comment by {c_name} for: {res_obj}".format(
                c_name=comment.user_name, res_obj=str(obj))
            context = {
                "comment": comment,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(subject, "email/comment_notification",
                               settings.DEFAULT_FROM_EMAIL, notify_emails,
                               context)

        return comment
Beispiel #4
0
    def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        comment = self.get_comment_object()
        obj = comment.content_object
        comment.user = request.user
        user_name = request.user.get_full_name()
        if not user_name:
            user_name = request.user.username

        comment.user_name = user_name
        # comment.email = request.user.email

        comment.by_author = request.user == getattr(obj, "user", None)
        comment.ip_address = ip_for_request(request)
        comment.replied_to_id = self.data.get("replied_to")

        # Mezzanine's duplicate check that also checks `replied_to_id`.
        lookup = {
            "content_type": comment.content_type,
            "object_pk": comment.object_pk,
            "user_name": comment.user_name,
            "user_email": comment.user_email,
            "user_url": comment.user_url,
            "replied_to_id": comment.replied_to_id,
        }
        for duplicate in self.get_comment_model().objects.filter(**lookup):
            if (duplicate.submit_date.date() == comment.submit_date.date() and
                    duplicate.comment == comment.comment):
                return duplicate

        comment.save()
        comment_was_posted.send(sender=comment.__class__, comment=comment,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        if notify_emails:
            subject = ugettext("New comment for: ") + str(obj)
            context = {
                "comment": comment,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(subject, "email/comment_notification",
                               settings.DEFAULT_FROM_EMAIL, notify_emails,
                               context)
        return comment
Beispiel #5
0
    def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        comment = self.get_comment_object()
        obj = comment.content_object
        if is_authenticated(request.user):
            comment.user = request.user
        comment.by_author = request.user == getattr(obj, "user", None)
        comment.ip_address = ip_for_request(request)
        comment.replied_to_id = self.data.get("replied_to")

        # Mezzanine's duplicate check that also checks `replied_to_id`.
        lookup = {
            "content_type": comment.content_type,
            "object_pk": comment.object_pk,
            "user_name": comment.user_name,
            "user_email": comment.user_email,
            "user_url": comment.user_url,
            "replied_to_id": comment.replied_to_id,
        }
        for duplicate in self.get_comment_model().objects.filter(**lookup):
            if (duplicate.submit_date.date() == comment.submit_date.date()
                    and duplicate.comment == comment.comment):
                return duplicate

        comment.save()
        comment_was_posted.send(sender=comment.__class__,
                                comment=comment,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        if notify_emails:
            subject = ugettext("New comment for: ") + str(obj)
            context = {
                "comment": comment,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(
                subject,
                "email/comment_notification",
                settings.DEFAULT_FROM_EMAIL,
                notify_emails,
                context,
            )
        return comment
Beispiel #6
0
    def save(self, request):
        """
        Saves a new comment and sends any notification emails.
        """
        post_data = request.POST
        review = self.get_comment_object()
        obj = review.content_object
        if request.user.is_authenticated():
            review.user = request.user
            review.user_name = review.user.username
        review.by_author = request.user == getattr(obj, "user", None)
        review.ip_address = ip_for_request(request)
        review.replied_to_id = self.data.get("replied_to")

        requiredreviewrating_name = obj.get_requiredreviewratingfield_name()
        requiredreviewrating_manager = getattr(obj, requiredreviewrating_name)
        optionalreviewrating_name = obj.get_optionalreviewratingfield_name()
        optionalreviewrating_manager = getattr(obj, optionalreviewrating_name)
        
        if request.user.is_authenticated():
            requiredreviewrating_instance = RequiredReviewRating(user=request.user)
        else:
            requiredreviewrating_instance = RequiredReviewRating()

        if request.user.is_authenticated():
            optionalreviewrating_instance = OptionalReviewRating(user=request.user)
        else:
            optionalreviewrating_instance = OptionalReviewRating()

        if (post_data.get("title")):
            review.title = post_data.get("title")
        if (post_data.get("overall_value")):
            review.overall_value = post_data.get("overall_value")
            requiredreviewrating_instance.overall_value = review.overall_value
        if (post_data.get("price_value")):
            review.price_value = post_data.get("price_value")
            requiredreviewrating_instance.price_value = review.price_value
        if (post_data.get("website_ex_value")):
            review.website_ex_value = post_data.get("website_ex_value")
            requiredreviewrating_instance.website_ex_value = review.website_ex_value
        if (post_data.get("quality_value")):
            review.quality_value = post_data.get("quality_value")
            requiredreviewrating_instance.quality_value = review.quality_value
        if (post_data.get("service_value")):
            review.service_value = post_data.get("service_value")
            requiredreviewrating_instance.service_value = review.service_value
        if (post_data.get("shop_again")):
            review.shop_again = post_data.get("shop_again")
            requiredreviewrating_instance.shop_again = review.shop_again
        if (post_data.get("exchange_value")):
            review.exchange_value = post_data.get("exchange_value")
            optionalreviewrating_instance.exchange_value = review.exchange_value
        review.save()
        
        if isinstance(obj, BlogPost):
            blog_category = post_data.get("category")
            bought_category  = None
            bought_category = BlogCategory.objects.get(slug=slugify(blog_category))
            review.bought_category.add(bought_category)

        # the primary key for review will be generated when it is saved
        # and the reviewrating will need to store that primary key
        requiredreviewrating_instance.commentid = review.pk        
        requiredreviewrating_manager.add(requiredreviewrating_instance)
            
        if post_data.get("exchange_value"):
            optionalreviewrating_instance.commentid = review.pk
            optionalreviewrating_manager.add(optionalreviewrating_instance)
        
        comment_was_posted.send(sender=review.__class__, comment=review,
                                request=request)
        notify_emails = split_addresses(settings.COMMENTS_NOTIFICATION_EMAILS)
        if notify_emails:
            subject = _("New comment for: ") + unicode(obj)
            context = {
                "comment": review,
                "comment_url": add_cache_bypass(comment.get_absolute_url()),
                "request": request,
                "obj": obj,
            }
            send_mail_template(subject, "email/comment_notification",
                               settings.DEFAULT_FROM_EMAIL, notify_emails,
                               context, fail_silently=settings.DEBUG)
        return review