Exemplo n.º 1
0
def comment_submit(request, post_slug=""):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            if post_slug:
                post = Post.objects.get(slug=post_slug)
                comment.post = post
            comment.save()

            # Notification
            body = "replied to your [post]("+comment.post.get_absolute_url()+")<br/>"\
                   + comment.body
            message = Message(from_user=comment.author,
                              to_user=comment.post.author,
                              body=body)
            message.save()
            
            return HttpResponseRedirect(post.get_absolute_url())
        else:
            # If error
            prev_url = request.GET.get('next', '/')
            return HttpResponseRedirect(prev_url)
    else:
        # If not post
        prev_url = request.GET.get('next', '/')
        return HttpResponseRedirect(prev_url)
Exemplo n.º 2
0
def subscribe(request, username):
    profile = User.objects.get(username=username)
    if not request.user.is_anonymous():
        user = request.user
        user.subscribed_to.add(profile)
        user.save()
        # Notification
        message = Message(from_user=user,
                          to_user=profile,
                          body="subscribed to your stories!")
        message.save()
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    else:
        return HttpResponseRedirect('/login/')    
Exemplo n.º 3
0
def subscribe(request, username):
    profile = User.objects.get(username=username)
    if not request.user.is_anonymous():
        user = request.user
        user.subscribed_to.add(profile)
        user.save()
        # Notification
        message = Message(from_user=user,
                          to_user=profile,
                          body="subscribed to your stories!")
        message.save()
        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
    else:
        return HttpResponseRedirect('/login/')
Exemplo n.º 4
0
def send_template_sms(sender, receiver, template_name, context, autosave=True):
    message = Message()
    message.method = Message.SMS
    message.sender = sender
    message.receiver = receiver

    context['sender_address'] = sender
    context['receiver_address'] = receiver
    context.update(site_url(None))

    content = render_to_string(template_name, context).strip()
    message.content = content
    if autosave:
        message.save()
    return message
Exemplo n.º 5
0
def send_template_sms(sender, receiver, template_name, context, autosave=True):
    message = Message()
    message.method = Message.SMS
    message.sender = sender
    message.receiver = receiver

    context['sender_address'] = sender
    context['receiver_address'] = receiver
    context.update(site_url(None))

    content = render_to_string(template_name, context).strip()
    message.content = content
    if autosave:
        message.save()
    return message
Exemplo n.º 6
0
def send_template_mail(sender, receiver, template_name, context, autosave=True):
    message = Message()
    message.sender = sender
    message.receiver = receiver

    context['sender_address'] = sender
    context['receiver_address'] = receiver
    context.update(site_url(None))
    raw_content = render_to_string(template_name, context).strip()

    subject, _, content = raw_content.partition('\n=====\n')
    message.subject = subject
    message.content = content
    if autosave:
        message.save()
    return message
Exemplo n.º 7
0
def subscribe(request, username):
    userprofile = User.objects.get(username=username)
    if not request.user.is_anonymous():
        user = request.user
        user.subscribed_to.add(userprofile)
        user.save()
        # Notification
        message = Message(from_user=user,
                          to_user=userprofile,
                          message_type="subscriber")
        message.save()
        userprofile.new_notifications = True
        userprofile.save()
        
        return HttpResponseRedirect(request.META.get('HTTP_REFERER')) 
    else:
        return HttpResponseRedirect('/login/')    
Exemplo n.º 8
0
def send_template_mail(sender,
                       receiver,
                       template_name,
                       context,
                       autosave=True):
    message = Message()
    message.sender = sender
    message.receiver = receiver

    context['sender_address'] = sender
    context['receiver_address'] = receiver
    context.update(site_url(None))
    raw_content = render_to_string(template_name, context).strip()

    subject, _, content = raw_content.partition('\n=====\n')
    message.subject = subject
    message.content = content
    if autosave:
        message.save()
    return message
Exemplo n.º 9
0
def comment_submit(request, comment_id):
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.parent = Comment.objects.get(id=comment_id)
            comment.post = comment.parent.post
            comment.save()
            # Send Email
            # send_comment_email_notification(comment)
            # if comment.parent.author.email_comments:
            #     commentauthor = comment.author.username
            #     topic = commentauthor + " has replied to your comment"
            #     body = commentauthor + " has replied to your comment\n" +\
            #            "http://fictionhub.io"+comment.post.get_absolute_url()+ "\n" +\
            #            "'" + comment.body[:64] + "...'"
            #     body += "\n\nYou can manage your email notifications in preferences:\n" +\
            #             "http://fictionhub.io/preferences/"
            #     try:
            #         email = comment.parent.author.email
            #         send_mail(topic, body, '*****@*****.**', [email], fail_silently=False)
            #     except:
            #         pass
            # Notification
            message = Message(
                from_user=request.user,
                to_user=comment.parent.author,
                story=comment.post,
                comment=comment,
                message_type="reply",
            )
            message.save()
            comment.parent.author.new_notifications = True
            comment.parent.author.save()

            comment_url = request.GET.get("next", "/") + "#id-" + str(comment.id)
            return HttpResponseRedirect(comment_url)
        else:
            # return HttpResponse("string")
            return render(request, "posts/create.html", {"form": form})