Пример #1
0
def synchronize_threadinformation(verbosity=-1):
    """ Will synchronize the 'ThreadInformation' objects. """
    from sphene.sphboard.models import Category, ThreadInformation, Post, THREAD_TYPE_DEFAULT

    # First find all threads ...
    if verbosity >= 2:
        print("Synchronizing ThreadInformation ...")
    all_threads = Post.objects.filter( thread__isnull = True )

    for thread in all_threads:
        # Find corresponding ThreadInformation
        try:
            thread_info = ThreadInformation.objects.type_default().filter( root_post = thread ).get()
        except ThreadInformation.DoesNotExist:
            thread_info = ThreadInformation( root_post = thread,
                                             category = thread.category,
                                             thread_type = THREAD_TYPE_DEFAULT )

        thread_info.update_cache()
        thread_info.save()
Пример #2
0
def synchronize_threadinformation(verbosity = -1):
    """ Will synchronize the 'ThreadInformation' objects. """
    from sphene.sphboard.models import Category, ThreadInformation, Post, THREAD_TYPE_DEFAULT
    
    # First find all threads ...
    if verbosity >= 2:
        print "Synchronizing QueryInformation ..."
    all_threads = Post.objects.filter( thread__isnull = True )

    for thread in all_threads:
        # Find corresponding ThreadInformation
        try:
            thread_info = ThreadInformation.objects.type_default().filter( root_post = thread ).get()
        except ThreadInformation.DoesNotExist:
            thread_info = ThreadInformation( root_post = thread,
                                             category = thread.category,
                                             thread_type = THREAD_TYPE_DEFAULT )

        thread_info.update_cache()
        thread_info.save()
Пример #3
0
def move(request, group, thread_id):
    thread = get_object_or_404(Post, pk = thread_id)
    if not thread.allow_moving():
        raise PermissionDenied()

    annotation = None
    if thread.is_annotated():
        try:
            annotation = thread.annotation.get()
        except PostAnnotation.DoesNotExist:
            # Ignore for now ..
            pass
    if request.method == 'POST':
        form = MoveAndAnnotateForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            newcategory = data['category']

            threadinfo = thread.get_threadinformation()
            threadinfo.thread_type = THREAD_TYPE_MOVED
            threadinfo.save()

            try:
                newthreadinfo = ThreadInformation.objects.get( root_post = thread,
                                                               category = newcategory,
                                                               thread_type = THREAD_TYPE_MOVED )
            except ThreadInformation.DoesNotExist:
                newthreadinfo = ThreadInformation( root_post = thread,
                                                   category = newcategory, )

            newthreadinfo.thread_type = THREAD_TYPE_DEFAULT
            newthreadinfo.update_cache()
            newthreadinfo.save()

            thread.set_annotated(True)

            if annotation is None:
                annotation = PostAnnotation( post = thread, )
            annotation.body = data['body']
            annotation.hide_post = False
            annotation.markup = data['markup']
            annotation.save()

            thread.category = newcategory
            thread.save()

            request.user.message_set.create( message = ugettext(u'Moved thread into new category.') )

            return HttpResponseRedirect( thread.get_absolute_url() )
        
    else:
        form = MoveAndAnnotateForm()

    if POST_MARKUP_CHOICES[0][0] == 'bbcode':
        category_name = '[url=%s]%s[/url].' % (thread.category.get_absolute_url(), thread.category.name)
    else:
        category_name = thread.category.name
    form.fields['body'].initial = _(u'This query was moved from the category %(category_name)s') % {'category_name':category_name}

    return render_to_response( "sphene/sphboard/move.html",
                               { 'thread': thread,
                                 'form': form,
                                 },
                               context_instance = RequestContext(request))
Пример #4
0
def move(request, group, thread_id):
    thread = get_object_or_404(Post, pk=thread_id)
    if not thread.allow_moving():
        raise PermissionDenied()

    annotation = None
    if thread.is_annotated():
        try:
            annotation = thread.annotation.get()
        except PostAnnotation.DoesNotExist:
            # Ignore for now ..
            pass
    if request.method == 'POST':
        form = MoveAndAnnotateForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            newcategory = data['category']
            info_link = data['info_link']

            threadinfo = thread.get_threadinformation()

            if info_link:
                threadinfo.thread_type = THREAD_TYPE_MOVED
                threadinfo.save()
            else:
                threadinfo.delete()

            try:
                newthreadinfo = ThreadInformation.objects.get(
                    root_post=thread,
                    category=newcategory,
                    thread_type=THREAD_TYPE_MOVED)
            except ThreadInformation.DoesNotExist:
                newthreadinfo = ThreadInformation(
                    root_post=thread,
                    category=newcategory,
                )

            newthreadinfo.thread_type = THREAD_TYPE_DEFAULT
            newthreadinfo.update_cache()
            newthreadinfo.save()

            thread.set_annotated(True)

            if annotation is None:
                annotation = PostAnnotation(post=thread, )
            annotation.body = data['body']
            annotation.hide_post = False
            annotation.markup = data['markup']
            annotation.save()

            thread.category = newcategory
            thread.save()

            # update category of thread's posts
            thread.replies().update(category=newcategory)

            messages.success(
                request, message=ugettext(u'Moved thread into new category.'))

            return HttpResponseRedirect(thread.get_absolute_url())

    else:
        form = MoveAndAnnotateForm()

    if POST_MARKUP_CHOICES[0][0] == 'bbcode':
        category_name = '[url=%s]%s[/url].' % (
            thread.category.get_absolute_url(), thread.category.name)
    else:
        category_name = thread.category.name
    form.fields['body'].initial = _(
        u'This thread was moved from the category %(category_name)s') % {
            'category_name': category_name
        }

    return render_to_response("sphene/sphboard/move.html", {
        'thread': thread,
        'form': form,
    },
                              context_instance=RequestContext(request))