コード例 #1
0
ファイル: views.py プロジェクト: tristan/hydrant
def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    f = get_object_or_404(Forum, slug=forum)
    t = Thread(
        forum=f,
        title=request.POST.get('title'),
    )
    t.save()
    p = Post(
        thread=t,
        author=request.user,
        body=request.POST.get('body'),
        time=datetime.now(),
    )
    p.save()
    if request.POST.get('subscribe',False):
        s = Subscription(
            author=request.user,
            thread=t
            )
        s.save()
    return HttpResponseRedirect(t.get_absolute_url())
コード例 #2
0
ファイル: views.py プロジェクト: zoek1/firey
def create_thread(request):
    data = json.loads(request.body)
    title = data.get('title')
    description = data.get('description')
    location = data.get('location')
    precision = data.get('precision')
    joining = data.get('joining')
    joining_value = data.get('joiningValue')
    publishing = data.get('publishing')
    publishing_value = data.get('publishingValue')
    thread_id = data.get('threadId')
    thread_name = data.get('threadName')
    moderator = data.get('moderator')
    is_open = data.get('is_open')
    space = data.get('space')
    did = data.get('did')

    thread = Thread(title=title, description=description, location=location, precision=precision,
                    joining_policy=joining, joining_value=joining_value,
                    publishing_policy=publishing, publishing_value=publishing_value,
                    thread_id=thread_id, thread_name=thread_name, moderator=moderator, is_open=is_open,
                    space=space, did=did)
    thread.save()

    sub = Subscription(thread=thread, address=moderator)
    sub.save()

    return JsonResponse(to_dict(thread), status=201)
コード例 #3
0
def newthread(request, forum):
    """
	Rudimentary post function - this should probably use 
	newforms, although not sure how that goes when we're updating 
	two models.

	Only allows a user to post if they're logged in.
	"""
    if not request.user.is_authenticated():
        return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, request.path))

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        formset = AttachFileFormset(request.POST, request.FILES)
        if form.is_valid() and formset.is_valid():
            t = Thread(
                forum=f,
                author=request.user,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()

            formset.instance = p
            formset.save()

            if form.cleaned_data.get('subscribe', False):
                s = Subscription(author=request.user, thread=t)
                s.save()
            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()
        formset = AttachFileFormset()

    return render_to_response(
        'forum/newthread.html',
        RequestContext(request, {
            'form': form,
            'formset': formset,
            'forum': f,
            'active': 7,
        }))
コード例 #4
0
ファイル: views.py プロジェクト: RockHoward/django-forum
def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()

    f = get_object_or_404(Forum, slug=forum)
    
    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(
                forum=f,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()
    
            if form.cleaned_data.get('subscribe', False):
                s = Subscription(
                    author=request.user,
                    thread=t
                    )
                s.save()
            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response('forum/newthread.html',
        RequestContext(request, {
            'form': form,
            'forum': f,
        }))
コード例 #5
0
ファイル: views.py プロジェクト: silky/mldata
def newthread(request, forum):
    """Post a new thread.

    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.

    @param forum: forum slug to create new thread for.
    @type forum: string
    @return: a view to post a new thread
    @rtype: Django response
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (reverse("user_signin"), request.path))

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    preview = False
    if request.method == "POST":
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            if request.POST.has_key("preview"):
                preview = {"title": form.cleaned_data["title"], "body": form.cleaned_data["body"]}
            else:
                t = Thread(forum=f, title=form.cleaned_data["title"])
                t.save()

                p = Post(thread=t, author=request.user, body=form.cleaned_data["body"], time=datetime.now())
                p.save()

                if form.cleaned_data.get("subscribe", False):
                    s = Subscription(author=request.user, thread=t)
                    s.save()
                return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response(
        "forum/thread_new.html",
        RequestContext(request, {"form": form, "forum": f, "preview": preview, "section": forum}),
    )
コード例 #6
0
ファイル: views.py プロジェクト: zoek1/firey
def subscribe_thread(request):
    data = json.loads(request.body)
    print(data)
    address = data.get('address')
    thread = int(data.get('thread'))

    thread = get_object_or_404(Thread, id=thread)

    try:
        sub = thread.subscribers.get(address=address)
        print('existed')
        print(sub)
    except Subscription.DoesNotExist:
        sub = Subscription(thread=thread, address=address)
        sub.save()
        print('Subscribed')

    return JsonResponse(to_dict(thread), status=201)
コード例 #7
0
ファイル: views.py プロジェクト: encorehu/django-forum
    def post(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            return HttpResponseForbidden()

        self.object = None

        form_class = self.get_form_class()
        form       = self.get_form(form_class)

        if form.is_valid():
            self.object = form.save(commit=False)
            self.object.forum = self.forum
            self.object.title = form.cleaned_data['title']
            self.object.save()

            post = Post(thread = self.object,
                        author = request.user,
                        body = form.cleaned_data['body'],
                        time=timezone.now()
                        )
            post.save()

            self.object.latest_post_time=post.time
            #self.object.posts +=1 #wrong, 1 more
            self.object.save()

            if form.cleaned_data.get('subscribe', False):
                s = Subscription(
                    author=request.user,
                    thread=self.object,
                    )
                s.save()
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

        self.object = None
        return super(ThreadCreateView, self).post(request, *args, **kwargs)
コード例 #8
0
    def post(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            return HttpResponseForbidden()

        self.object = None

        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            self.object = form.save(commit=False)
            self.object.forum = self.forum
            self.object.title = form.cleaned_data['title']
            self.object.save()

            post = Post(thread=self.object,
                        author=request.user,
                        body=form.cleaned_data['body'],
                        time=timezone.now())
            post.save()

            self.object.latest_post_time = post.time
            #self.object.posts +=1 #wrong, 1 more
            self.object.save()

            if form.cleaned_data.get('subscribe', False):
                s = Subscription(
                    author=request.user,
                    thread=self.object,
                )
                s.save()
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

        self.object = None
        return super(ThreadCreateView, self).post(request, *args, **kwargs)
コード例 #9
0
def newthread(request, forum):
    """Post a new thread.

    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.

    @param forum: forum slug to create new thread for.
    @type forum: string
    @return: a view to post a new thread
    @rtype: Django response
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('%s?next=%s' %
                                    (reverse('user_signin'), request.path))

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    preview = False
    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            if request.POST.has_key('preview'):
                preview = {
                    'title': form.cleaned_data['title'],
                    'body': form.cleaned_data['body']
                }
            else:
                t = Thread(
                    forum=f,
                    title=form.cleaned_data['title'],
                )
                t.save()

                p = Post(
                    thread=t,
                    author=request.user,
                    body=form.cleaned_data['body'],
                    time=datetime.now(),
                )
                p.save()

                if form.cleaned_data.get('subscribe', False):
                    s = Subscription(author=request.user, thread=t)
                    s.save()
                return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response(
        'forum/thread_new.html',
        RequestContext(request, {
            'form': form,
            'forum': f,
            'preview': preview,
            'section': forum,
        }))
コード例 #10
0
ファイル: views.py プロジェクト: tristan/hydrant
def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    body = request.POST.get('body', False)
    p = Post(
        thread=t, 
        author=request.user,
        body=body,
        time=datetime.now(),
        )
    p.save()

    sub = Subscription.objects.filter(thread=t, author=request.user)
    if request.POST.get('subscribe',False):
        if not sub:
            s = Subscription(
                author=request.user,
                thread=t
                )
            s.save()
    else:
        if sub:
            sub.delete()

    # Subscriptions are updated now send mail to all the authors subscribed in
    # this thread.
    mail_subject = ''
    try:
        mail_subject = settings.FORUM_MAIL_PREFIX 
    except AttributeError:
        mail_subject = '[Forum]'

    mail_from = ''
    try:
        mail_from = settings.FORUM_MAIL_FROM
    except AttributeError:
        mail_from = settings.DEFAULT_FROM_EMAIL

    mail_tpl = loader.get_template('forum/notify.txt')
    c = Context({
        'body': wordwrap(striptags(body), 72),
        'site' : Site.objects.get_current(),
        'thread': t,
        })

    #email = EmailMessage('Hello', 'Body goes here', '*****@*****.**',
    #            ['*****@*****.**', '*****@*****.**'], ['*****@*****.**'],
    #                        headers = {'Reply-To': '*****@*****.**'})
    email = EmailMessage(
            subject=mail_subject+' '+striptags(t.title),
            body= mail_tpl.render(c),
            from_email=mail_from,
            to=[mail_from],
            bcc=[s.author.email for s in t.subscription_set.all()],)
    email.send(fail_silently=True)

    return HttpResponseRedirect(p.get_absolute_url())
コード例 #11
0
ファイル: views.py プロジェクト: feitianyiren/ddtcms
def newthread(request, forum):
    """
    Rudimentary post function - this should probably use
    newforms, although not sure how that goes when we're updating
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
    	return HttpResponseForbidden()

    if request.method == 'POST':
        form = CreateThreadForm(data=request.POST, files=request.FILES)
        #return HttpResponseRedirect('/POST'+str(request.FILES['file']))
        #return HttpResponseRedirect('/POST'+str(form.is_valid()))
        if form.is_valid():
            t = Thread(
                forum=f,
                author=request.user,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()

            if form.cleaned_data.get('subscribe', False):
                s = Subscription(
                    author=request.user,
                    thread=t
                    )
                s.save()

            for attachedfilefield in form.files:
                #file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
                attachment_file = form.files[attachedfilefield]
                attach=Attachment()
                attach.handle_uploaded_attachment(p,
                    attachment_file,
                    attached_by = request.user,
                    title = attachment_file.name,
                    summary = t.title                   
                    )                  

            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response('forum/newthread.html',
        RequestContext(request, {
            'form': form,
            'forum': f,
        }))
コード例 #12
0
ファイル: views.py プロジェクト: encorehu/django-forum
    def post(self, request, *args, **kwargs):
        """
        If a thread isn't closed, and the user is logged in, post a reply
        to a thread. Note we don't have "nested" replies at this stage.
        """
        if not request.user.is_authenticated():
            return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, request.path))

        if self.thread.closed:
            return HttpResponseServerError()

        self.object = None
        form_class = self.get_form_class()
        form       = self.get_form(form_class)

        if form.is_valid():
            self.object = form.save(commit=False)
            self.object.thread = self.thread
            self.object.author = request.user
            self.object.time   = timezone.now()
            self.object.save()

            sub = Subscription.objects.filter(thread=self.thread, author=request.user)
            if form.cleaned_data.get('subscribe',False):
                if not sub:
                    s = Subscription(
                        author=request.user,
                        thread=self.thread
                        )
                    s.save()
            else:
                if sub:
                    sub.delete()

            if self.thread.subscription_set.count() > 0:
                # Subscriptions are updated now send mail to all the authors subscribed in
                # this thread.
                mail_subject = ''
                try:
                    mail_subject = settings.FORUM_MAIL_PREFIX
                except AttributeError:
                    mail_subject = '[Forum]'

                mail_from = ''
                try:
                    mail_from = settings.FORUM_MAIL_FROM
                except AttributeError:
                    mail_from = settings.DEFAULT_FROM_EMAIL

                mail_tpl = loader.get_template('forum/notify.txt')
                c = Context({
                    'body': wordwrap(striptags(body), 72),
                    'site' : Site.objects.get_current(),
                    'thread': self.thread,
                    })

                email = EmailMessage(
                        subject=mail_subject+' '+striptags(self.thread.title),
                        body= mail_tpl.render(c),
                        from_email=mail_from,
                        bcc=[s.author.email for s in self.thread.subscription_set.all()],)
                email.send(fail_silently=True)
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

        self.object = None
        return super(PostCreateView, self).post(request, *args, **kwargs)
コード例 #13
0
ファイル: views.py プロジェクト: silky/mldata
def reply(request, thread):
    """Post a reply.

    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.

    @param thread: thread id to reply to
    @type thread: integer
    @return: a view to post a reply
    @rtype: Django response
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (reverse("user_signin"), request.path))
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            if request.POST.has_key("preview"):
                preview = {"body": form.cleaned_data["body"]}
            else:
                body = form.cleaned_data["body"]
                p = Post(thread=t, author=request.user, body=body, time=datetime.now())
                p.save()

                sub = Subscription.objects.filter(thread=t, author=request.user)
                if form.cleaned_data.get("subscribe", False):
                    if not sub:
                        s = Subscription(author=request.user, thread=t)
                        s.save()
                else:
                    if sub:
                        sub.delete()

                if t.subscription_set.count() > 0:
                    # Subscriptions are updated now send mail to all the authors subscribed in
                    # this thread.
                    mail_subject = ""
                    try:
                        mail_subject = settings.FORUM_MAIL_PREFIX
                    except AttributeError:
                        mail_subject = "[Forum]"

                    mail_from = ""
                    try:
                        mail_from = settings.FORUM_MAIL_FROM
                    except AttributeError:
                        mail_from = settings.DEFAULT_FROM_EMAIL

                    mail_tpl = loader.get_template("forum/notify.txt")
                    c = RequestContext(
                        {"body": wordwrap(striptags(body), 72), "site": Site.objects.get_current(), "thread": t}
                    )

                    email = EmailMessage(
                        subject=mail_subject + " " + striptags(t.title),
                        body=mail_tpl.render(c),
                        from_email=mail_from,
                        bcc=[s.author.email for s in t.subscription_set.all()],
                    )
                    email.send(fail_silently=True)

                return HttpResponseRedirect(p.get_absolute_url())
    else:
        preview = False
        form = ReplyForm()

    return render_to_response(
        "forum/reply.html",
        RequestContext(request, {"form": form, "forum": t.forum, "thread": t, "preview": preview, "section": "forum"}),
    )
コード例 #14
0
ファイル: views.py プロジェクト: feitianyiren/ddtcms
def edit(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t,
                author=request.user,
                body=body,
                time=datetime.now(),
                )
            p.save()

            sub = Subscription.objects.filter(thread=t, author=request.user)
            if form.cleaned_data.get('subscribe',False):
                if not sub:
                    s = Subscription(
                        author=request.user,
                        thread=t
                        )
                    s.save()
            else:
                if sub:
                    sub.delete()

            # Subscriptions are updated now send mail to all the authors subscribed in
            # this thread.
            mail_subject = ''
            try:
                mail_subject = settings.FORUM_MAIL_PREFIX
            except AttributeError:
                mail_subject = '[Forum]'

            mail_from = ''
            try:
                mail_from = settings.FORUM_MAIL_FROM
            except AttributeError:
                mail_from = settings.DEFAULT_FROM_EMAIL

            mail_tpl = loader.get_template('forum/notify.txt')
            c = Context({
                'body': wordwrap(striptags(body), 72),
                'site' : Site.objects.get_current(),
                'thread': t,
                })

            email = EmailMessage(
                    subject=mail_subject+' '+striptags(t.title),
                    body= mail_tpl.render(c),
                    from_email=mail_from,
                    to=[mail_from],
                    bcc=[s.author.email for s in t.subscription_set.all()],)
            email.send(fail_silently=True)

            for attachedfilefield in form.files:
                #file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
                attachment_file = form.files[attachedfilefield]
                attach=Attachment()
                attach.handle_uploaded_attachment(p,
                    attachment_file,
                    request.user,
                    attachment_file.name,
                    t.title
                    )

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        post_id = request.GET.get('pid', 0)
        if post_id ==0:
            return HttpResponseServerError(_("The Post Do Not Exist"))
        try:
            p = Post.objects.all().get(id=post_id)
        except Post.DoesNotExist:
            raise Http404(_("Not Found"))
        
        body=p.body
        initial = {'subscribe': True,
            'body':body}
        form = ReplyForm(initial=initial)

    return render_to_response('forum/edit.html',
        RequestContext(request, {
            'form': form,
            'post': p
        }))
コード例 #15
0
def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, request.path))
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t,
                author=request.user,
                body=body,
                time=datetime.now(),
            )
            p.save()

            sub = Subscription.objects.filter(thread=t, author=request.user)
            if form.cleaned_data.get('subscribe', False):
                if not sub:
                    s = Subscription(author=request.user, thread=t)
                    s.save()
            else:
                if sub:
                    sub.delete()

            if t.subscription_set.count() > 0:
                # Subscriptions are updated now send mail to all the authors subscribed in
                # this thread.
                mail_subject = ''
                try:
                    mail_subject = settings.FORUM_MAIL_PREFIX
                except AttributeError:
                    mail_subject = '[Forum]'

                mail_from = ''
                try:
                    mail_from = settings.FORUM_MAIL_FROM
                except AttributeError:
                    mail_from = settings.DEFAULT_FROM_EMAIL

                mail_tpl = loader.get_template('forum/notify.txt')
                c = Context({
                    'body': wordwrap(striptags(body), 72),
                    'site': Site.objects.get_current(),
                    'thread': t,
                })

                email = EmailMessage(
                    subject=mail_subject + ' ' + striptags(t.title),
                    body=mail_tpl.render(c),
                    from_email=mail_from,
                    bcc=[s.author.email for s in t.subscription_set.all()],
                )
                email.send(fail_silently=True)

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response(
        'forum/reply.html',
        RequestContext(request, {
            'form': form,
            'forum': t.forum,
            'thread': t,
        }))
コード例 #16
0
def reply(request, thread, flag_partner=False):
	"""
	If a thread isn't closed, and the user is logged in, post a reply
	to a thread. Note we don't have "nested" replies at this stage.
	"""
	if flag_partner:
		if request.user.is_authenticated() and request.user.get_profile().is_partner():pass
		else:
			messages.add_message(request, messages.ERROR, 'Пожалуйста, авторизируйтесь как партнер.')
			return redirect('/accounts/login/?next=%s' % request.path)
			
	if not request.user.is_authenticated():
		return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, request.path))
	t = get_object_or_404(Thread, pk=thread)
	if t.closed:
		return HttpResponseServerError()
	if not Forum.objects.has_access(t.forum, request.user.groups.all()):
		return HttpResponseForbidden()

	if request.method == "POST":
		form = ReplyForm(request.POST)
		formset = AttachFileFormset(request.POST, request.FILES)
		if form.is_valid() and formset.is_valid():
			p = Post(
				thread=t,
				author=request.user,
				body=form.cleaned_data['body'],
				time=datetime.now(),
			)
			p.save()
			
			formset.instance = p
			formset.save()

			sub = Subscription.objects.filter(thread=t, author=request.user)
			if form.cleaned_data.get('subscribe',False):
				if not sub:
					s = Subscription(author=request.user, thread=t)
					s.save()
			else:
				if sub: sub.delete()

			if t.subscription_set.count() > 0:
				mail_subject = ''
				try: mail_subject = settings.FORUM_MAIL_PREFIX 
				except AttributeError: mail_subject = '[Forum]'

				mail_from = ''
				try: mail_from = settings.FORUM_MAIL_FROM
				except AttributeError: mail_from = settings.DEFAULT_FROM_EMAIL

				mail_tpl = loader.get_template('forum/notify.txt')
				body = form.cleaned_data['body']
				c = Context({
					'body': wordwrap(striptags(body), 72),
					'site' : Site.objects.get_current(),
					'thread': t,
				})

				email = EmailMessage(
					subject=mail_subject+' '+striptags(t.title),
					body= mail_tpl.render(c),
					from_email=mail_from,
					bcc=[s.author.email for s in t.subscription_set.all()],)
				email.send(fail_silently=True)

			return HttpResponseRedirect(p.get_absolute_url())
	else:
		form = ReplyForm()
		formset = AttachFileFormset()
    
	return render_to_response('forum/reply.html',
		RequestContext(request, {
			'form': form,
			'formset': formset,
			'forum': t.forum,
			'thread': t,
			'flag_partner':flag_partner
		}))
コード例 #17
0
    def post(self, request, *args, **kwargs):
        """
        If a thread isn't closed, and the user is logged in, post a reply
        to a thread. Note we don't have "nested" replies at this stage.
        """
        if not request.user.is_authenticated():
            return HttpResponseRedirect('%s?next=%s' %
                                        (LOGIN_URL, request.path))

        if self.thread.closed:
            return HttpResponseServerError()

        self.object = None
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        if form.is_valid():
            self.object = form.save(commit=False)
            self.object.thread = self.thread
            self.object.author = request.user
            self.object.time = timezone.now()
            self.object.save()

            sub = Subscription.objects.filter(thread=self.thread,
                                              author=request.user)
            if form.cleaned_data.get('subscribe', False):
                if not sub:
                    s = Subscription(author=request.user, thread=self.thread)
                    s.save()
            else:
                if sub:
                    sub.delete()

            if self.thread.subscription_set.count() > 0:
                # Subscriptions are updated now send mail to all the authors subscribed in
                # this thread.
                mail_subject = ''
                try:
                    mail_subject = settings.FORUM_MAIL_PREFIX
                except AttributeError:
                    mail_subject = '[Forum]'

                mail_from = ''
                try:
                    mail_from = settings.FORUM_MAIL_FROM
                except AttributeError:
                    mail_from = settings.DEFAULT_FROM_EMAIL

                mail_tpl = loader.get_template('forum/notify.txt')
                c = Context({
                    'body': wordwrap(striptags(body), 72),
                    'site': Site.objects.get_current(),
                    'thread': self.thread,
                })

                email = EmailMessage(
                    subject=mail_subject + ' ' + striptags(self.thread.title),
                    body=mail_tpl.render(c),
                    from_email=mail_from,
                    bcc=[
                        s.author.email
                        for s in self.thread.subscription_set.all()
                    ],
                )
                email.send(fail_silently=True)
            return self.form_valid(form)
        else:
            return self.form_invalid(form)

        self.object = None
        return super(PostCreateView, self).post(request, *args, **kwargs)
コード例 #18
0
ファイル: views.py プロジェクト: RockHoward/django-forum
def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t, 
                author=request.user,
                body=body,
                time=datetime.now(),
                )
            p.save()

            sub = Subscription.objects.filter(thread=t, author=request.user)
            if form.cleaned_data.get('subscribe',False):
                if not sub:
                    s = Subscription(
                        author=request.user,
                        thread=t
                        )
                    s.save()
            else:
                if sub:
                    sub.delete()

            # Subscriptions are updated now send mail to all the authors subscribed in
            # this thread.
            mail_subject = ''
            try:
                mail_subject = settings.FORUM_MAIL_PREFIX 
            except AttributeError:
                mail_subject = '[Forum]'

            mail_from = ''
            try:
                mail_from = settings.FORUM_MAIL_FROM
            except AttributeError:
                mail_from = settings.DEFAULT_FROM_EMAIL

            mail_tpl = loader.get_template('forum/notify.txt')
            c = Context({
                'body': wordwrap(striptags(body), 72),
                'site' : Site.objects.get_current(),
                'thread': t,
                })

            email = EmailMessage(
                    subject=mail_subject+' '+striptags(t.title),
                    body= mail_tpl.render(c),
                    from_email=mail_from,
                    to=[mail_from],
                    bcc=[s.author.email for s in t.subscription_set.all()],)
            email.send(fail_silently=True)

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()
    
    return render_to_response('forum/reply.html',
        RequestContext(request, {
            'form': form,
            'forum': t.forum,
            'thread': t,
        }))
コード例 #19
0
ファイル: views.py プロジェクト: feitianyiren/ddtcms
def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t,
                author=request.user,
                body=body,
                time=datetime.now(),
                )
            p.save()

            sub = Subscription.objects.filter(thread=t, author=request.user)
            if form.cleaned_data.get('subscribe',False):
                if not sub:
                    s = Subscription(
                        author=request.user,
                        thread=t
                        )
                    s.save()
            else:
                if sub:
                    sub.delete()

            # Subscriptions are updated now send mail to all the authors subscribed in
            # this thread.
            mail_subject = ''
            try:
                mail_subject = settings.FORUM_MAIL_PREFIX
            except AttributeError:
                mail_subject = '[Forum]'

            mail_from = ''
            try:
                mail_from = settings.FORUM_MAIL_FROM
            except AttributeError:
                mail_from = settings.DEFAULT_FROM_EMAIL

            mail_tpl = loader.get_template('forum/notify.txt')
            c = Context({
                'body': wordwrap(striptags(body), 72),
                'site' : Site.objects.get_current(),
                'thread': t,
                })

            email = EmailMessage(
                    subject=mail_subject+' '+striptags(t.title),
                    body= mail_tpl.render(c),
                    from_email=mail_from,
                    to=[mail_from],
                    bcc=[s.author.email for s in t.subscription_set.all()],)
            email.send(fail_silently=True)

##            data={'title': t.title,
##                'summary': t.title,
##                'attached_timestamp':datetime.now()
##                }
##            attachment_form=AttachmentForm(data=data,files=form.files)
##            a=attachment_form.errors
##            content_type =ContentType.objects.get_for_model(Post)
##            object_id = p.id
##            ffs=form.files
##            debug()
##            if attachment_form.is_valid():
##                attachment = attachment_form.save(commit=False)
##                attachment.content_type = content_type
##                attachment.object_id = object_id
##                attachment.attached_by = request.user
##                attachment.save()

#            for attachedfilefield in form.files:
#                #file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
#                attachment_file = form.files[attachedfilefield]
#                file_path =os.path.join(ATTACHMENT_DIR, randomfilename(attachment_file.name))
#                (mimetype, encoding) = mimetypes.guess_type(file_path)
#
#                try:
#                    mime_type = mimetype
#                except:
#                    mime_type = 'text/plain'
#
#                attach=Attachment(
#                    content_type =ContentType.objects.get_for_model(Post),
#                    object_id = p.id,
#                    title = attachment_file.name,
#                    summary = t.title,
#                    attached_by = request.user,
#                    )
#                attach.save_uploaded_file(attachment_file)
#                attach.save()


            for attachedfilefield in form.files:
                #file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
                attachment_file = form.files[attachedfilefield]
                attach=Attachment()
                attach.handle_uploaded_attachment(p,
                    attachment_file,
                    request.user,
                    attachment_file.name,
                    t.title
                    )

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response('forum/reply.html',
        RequestContext(request, {
            'form': form,
            'forum': t.forum,
            'thread': t,
        }))