예제 #1
0
    def get_view(self, request):
        moderated_items = registry.get_by_user(request.user)

        ctx = {
            "moderated_item": registry.get_by_name(self.name),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagCreateAliasForm(request.POST)
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data

                tag = cleaned_data['tag']
                aliases = cleaned_data['aliases']

                already_added = TagAlias.objects.filter(tag=tag)
                for added in already_added:
                    if added.name in aliases:
                        aliases.remove(added.name)
                    else:
                        added.delete()

                for alias in aliases:
                    TagAlias.objects.create(tag=tag, name=alias)

                messages.add_message(request, messages.INFO,
                                     _("Alias created!"))
                return redirect(self.get_absolute_url())

        else:
            ctx['form'] = TagCreateAliasForm()

        return render(request, 'moderation/tag_aliases/create.html', ctx)
예제 #2
0
    def testRegistry(self):
        self.assertRaises(AttributeError, registry.register, User)
        self.assertRaises(AttributeError, registry.register, User())

        self.assertEqual(
            registry.get_by_name('test-moderated-object').get_name(),
            'test-moderated-object')
예제 #3
0
    def get_view( self, request ):
        moderated_items = registry.get_by_user( request.user )

        ctx = {
            "moderated_item": registry.get_by_name( self.name ),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        lang = settings.LANGUAGE_CODE
        to_lang = TagTranslation.to_lang()
        
        if request.method == 'POST':
            for f, t in request.POST.items():
                TagTranslation.create_translation( f, t )
        
            if request.is_ajax():
                return HttpResponse( json.dumps( { 'success': True  } ) )

        kwargs = {
            "%s__isnull" % to_lang: False
        }
        translated = [ t[lang] for t in TagTranslation.objects.filter( **kwargs ).values( lang ) ]
        ctx['items'] = Tag.objects.all().exclude( name__in=translated ).order_by( 'weight' )
        ctx['lang'] = lang
        ctx['to_lang'] = to_lang

        return render( request, 'moderation/tag_translation/list.html', ctx )
예제 #4
0
    def get_view(self, request):
        moderated_items = registry.get_by_user(request.user)

        ctx = {
            "moderated_item": registry.get_by_name(self.name),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        lang = settings.LANGUAGE_CODE
        to_lang = TagTranslation.to_lang()

        if request.method == 'POST':
            for f, t in request.POST.items():
                TagTranslation.create_translation(f, t)

            if request.is_ajax():
                return HttpResponse(json.dumps({'success': True}))

        kwargs = {"%s__isnull" % to_lang: False}
        translated = [
            t[lang]
            for t in TagTranslation.objects.filter(**kwargs).values(lang)
        ]
        ctx['items'] = Tag.objects.all().exclude(
            name__in=translated).order_by('weight')
        ctx['lang'] = lang
        ctx['to_lang'] = to_lang

        return render(request, 'moderation/tag_translation/list.html', ctx)
예제 #5
0
    def get_view( self, request ):
        moderated_items = registry.get_by_user( request.user )

        ctx = {
            "moderated_item": registry.get_by_name( self.name ),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagTranslationForm( request.POST )
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data
                
                f = cleaned_data['f']
                t = cleaned_data['t']

                TagTranslation.create_translation( f, t )

                messages.add_message( request, messages.INFO, _( "Tag translated!" ) )
                return redirect( self.get_absolute_url() )

        else: 
            ctx['form'] = TagTranslationForm()

        return render( request, 'moderation/tag_translation/create.html', ctx )
예제 #6
0
    def get_view( self, request ):
        moderated_items = registry.get_by_user( request.user )

        ctx = {
            "moderated_item": registry.get_by_name( self.name ),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagCreateAliasForm( request.POST )
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data
                
                tag = cleaned_data['tag']
                aliases = cleaned_data['aliases']

                already_added = TagAlias.objects.filter( tag=tag )
                for added in already_added:
                    if added.name in aliases:
                        aliases.remove( added.name )
                    else:
                        added.delete()
               
                for alias in aliases:
                    TagAlias.objects.create( tag=tag, name=alias )
                
                messages.add_message( request, messages.INFO, _( "Alias created!" ) )
                return redirect( self.get_absolute_url() )

        else: 
            ctx['form'] = TagCreateAliasForm()

        return render( request, 'moderation/tag_aliases/create.html', ctx )
예제 #7
0
    def get_view(self, request):
        moderated_items = registry.get_by_user(request.user)

        ctx = {
            "moderated_item": registry.get_by_name(self.name),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagTranslationForm(request.POST)
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data

                f = cleaned_data['f']
                t = cleaned_data['t']

                TagTranslation.create_translation(f, t)

                messages.add_message(request, messages.INFO,
                                     _("Tag translated!"))
                return redirect(self.get_absolute_url())

        else:
            ctx['form'] = TagTranslationForm()

        return render(request, 'moderation/tag_translation/create.html', ctx)
예제 #8
0
def moderate_item( request, model ):
    moderated_item = registry.get_by_name( model )
    if moderated_item is None:
        raise Http404

    if request.user.has_perm( moderated_item.permission ):
        if isinstance( moderated_item, ModeratorTool ):
            return moderated_item.get_view( request )

        template = "moderation/index.html"
        moderated_items = registry.get_by_user( request.user )
        args = {
            "moderated_item": moderated_item,
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools'],
        }
        if request.method == 'POST':
            try:
                if 'reject' in request.POST and not 'confirmed' in request.POST:
                    item_id = request.POST.get( 'id', None )
                    if item_id is None:
                        raise ModerationException( "Unknown item ..." )

                    template = "moderation/reject.html"
                    args['form'] = RejectForm()
                    args['item'] = moderated_item.get_by_pk( int( item_id ) )

                else:
                    process_action( request, moderated_item )

            except ModerationException, e:
                request.user.message_set.create( message=str( e ) )

        return render_to_response( template, args, context_instance=RequestContext( request ) )
예제 #9
0
    def get_view(self, request):
        moderated_items = registry.get_by_user(request.user)

        ctx = {
            "moderated_item": registry.get_by_name(self.name),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagRenameForm(request.POST)
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data

                tag_a_name = cleaned_data['tagA']
                tag_a_tag = Tag.objects.get(name=tag_a_name)
                tag_a_count = self._get_tagged_objects_count(tag_a_tag)

                tag_b_name = cleaned_data['tagB']
                tag_b_tag = None
                try:
                    tag_b_tag = Tag.objects.get(name=tag_b_name)
                except Tag.DoesNotExist:
                    pass
                tag_b_count = self._get_tagged_objects_count(
                    tag_b_tag) if tag_b_tag else 0

                if not 'confirm' in request.POST:
                    ctx['to_confirm'] = {
                        'tagA': {
                            'name': tag_a_name,
                            'count': tag_a_count,
                        },
                        'tagB': {
                            'name': tag_b_name,
                            'count': tag_b_count,
                        }
                    }

                else:

                    rename_tag.delay(tag_a_name, tag_b_name, request.user)

                    messages.add_message(
                        request, messages.INFO,
                        _("your task will be executed in the background, you will be informed when it's finished"
                          ))
                    return redirect(self.get_absolute_url())

        else:
            ctx['form'] = TagRenameForm()

        return render(request, 'moderation/rename_tag/create.html', ctx)
예제 #10
0
 def get_context_data( self, *args, **kwargs ):
     context = super( ModerationEditFeaturesView, self ).get_context_data( *args, **kwargs )
     moderated_items = registry.get_by_user( self.request.user )
     context.update({
         "all"            : self.request.method == 'GET' and self.request.GET.get( 'all', False ),
         "tag"            : self.request.method == 'GET' and self.request.GET.get( 'tag', '' ),
         "moderated_item" : registry.get_by_name( "film-features" ),
         "moderated_items": moderated_items['items'],
         "moderator_tools": moderated_items['tools'],
         "from_moderation": True,
     })
     return context
예제 #11
0
    def setUp( self ):
        super( TaggingToolsTestCase, self ).setUp()
        # ..
        self.admin = User.objects.create_user( "admin", "*****@*****.**", "admin" )
        self.admin.is_superuser = True
        self.admin.save()

        self.client = Client( follow=True )

        self.rename_tag = registry.get_by_name( 'rename-tag' )
        self.alias_tag = registry.get_by_name( 'alias-tag' )

        self.film1 = Film()
        self.film1.title = "Battlefield Earth II"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "battlefirld-earth-ii"
        self.film1.release_year = 2010
        self.film1.production_country_list = "USA"
        self.film1.save()
        self.film1.save_tags( "komedia, kosmos, test" )

        self.film2 = Film()
        self.film2.title = "Battlefield Earth III"
        self.film2.type = Object.TYPE_FILM
        self.film2.permalink = "battlefirld-earth-iii"
        self.film2.release_year = 2011
        self.film2.production_country_list = "USA"
        self.film2.save()
        self.film2.save_tags( "komedia, kosmos, test" )

        self.film3 = Film()
        self.film3.title = "Battlefield Earth IV"
        self.film3.type = Object.TYPE_FILM
        self.film3.permalink = "battlefirld-earth-iv"
        self.film3.release_year = 2012
        self.film3.production_country_list = "Italy"
        self.film3.save()
        self.film3.save_tags( "komedia romantyczna, kosmos, test" )

        self.tag1 = Tag.objects.create( name='ciekawy' )
예제 #12
0
    def setUp( self ):
        super( TaggingToolsTestCase, self ).setUp()
        # ..
        self.admin = User.objects.create_user( "admin", "*****@*****.**", "admin" )
        self.admin.is_superuser = True
        self.admin.save()

        self.client = Client( follow=True )

        self.rename_tag = registry.get_by_name( 'rename-tag' )
        self.alias_tag = registry.get_by_name( 'alias-tag' )

        self.film1 = Film()
        self.film1.title = "Battlefield Earth II"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "battlefirld-earth-ii"
        self.film1.release_year = 2010
        self.film1.production_country_list = "USA"
        self.film1.save()
        self.film1.save_tags( "komedia, kosmos, test" )

        self.film2 = Film()
        self.film2.title = "Battlefield Earth III"
        self.film2.type = Object.TYPE_FILM
        self.film2.permalink = "battlefirld-earth-iii"
        self.film2.release_year = 2011
        self.film2.production_country_list = "USA"
        self.film2.save()
        self.film2.save_tags( "komedia, kosmos, test" )

        self.film3 = Film()
        self.film3.title = "Battlefield Earth IV"
        self.film3.type = Object.TYPE_FILM
        self.film3.permalink = "battlefirld-earth-iv"
        self.film3.release_year = 2012
        self.film3.production_country_list = "Italy"
        self.film3.save()
        self.film3.save_tags( "komedia romantyczna, kosmos, test" )

        self.tag1 = Tag.objects.create( name='ciekawy' )
예제 #13
0
def rss_feed(request, model, status=ModeratedObject.STATUS_UNKNOWN):
    moderated_item = registry.get_by_name(model)
    if status is not ModeratedObject.STATUS_ACCEPTED and not request.user.has_perm(moderated_item.permission):
        return HttpResponse("Permission danied")

    items = moderated_item.get_queryset(status)[:20]

    t = loader.get_template(moderated_item.get_rss_template_name())
    c = Context({"items": items, "moderated_item": moderated_item, "status": status})
    response = HttpResponse(mimetype="application/rss+xml")
    response.write(t.render(c))

    return response
예제 #14
0
    def get_view( self, request ):
        moderated_items = registry.get_by_user( request.user )

        ctx = {
            "moderated_item": registry.get_by_name( self.name ),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagRenameForm( request.POST )
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data
                
                tag_a_name = cleaned_data['tagA']
                tag_a_tag = Tag.objects.get( name=tag_a_name )
                tag_a_count = self._get_tagged_objects_count( tag_a_tag )
                
                tag_b_name = cleaned_data['tagB']
                tag_b_tag = None
                try:
                    tag_b_tag = Tag.objects.get( name=tag_b_name )
                except Tag.DoesNotExist:
                    pass
                tag_b_count = self._get_tagged_objects_count( tag_b_tag ) if tag_b_tag else 0

                if not 'confirm' in request.POST:
                    ctx['to_confirm'] = {
                        'tagA': {
                            'name' : tag_a_name,
                            'count': tag_a_count,
                        },
                        'tagB': {
                            'name' : tag_b_name,
                            'count': tag_b_count,
                        }
                    }

                else:
                    
                    rename_tag.delay( tag_a_name, tag_b_name, request.user )
                    
                    messages.add_message( request, messages.INFO, _( "your task will be executed in the background, you will be informed when it's finished" ) )
                    return redirect( self.get_absolute_url() )

        else: 
            ctx['form'] = TagRenameForm()

        return render( request, 'moderation/rename_tag/create.html', ctx )
예제 #15
0
파일: feeds.py 프로젝트: manlan2/filmaster
def rss_feed( request, model, status=ModeratedObject.STATUS_UNKNOWN ):
    moderated_item = registry.get_by_name( model )
    if status is not ModeratedObject.STATUS_ACCEPTED \
       and not request.user.has_perm( moderated_item.permission ):
        return HttpResponse( 'Permission danied' )

    items = moderated_item.get_queryset( status )[:20]

    t = loader.get_template( moderated_item.get_rss_template_name() )
    c = Context( 
        { 'items': items, 'moderated_item': moderated_item, 'status': status } 
    )
    response = HttpResponse( mimetype='application/rss+xml' )
    response.write( t.render( c ) )
    
    return response
예제 #16
0
 def get_context_data(self, *args, **kwargs):
     context = super(ModerationEditFeaturesView,
                     self).get_context_data(*args, **kwargs)
     moderated_items = registry.get_by_user(self.request.user)
     context.update({
         "all":
         self.request.method == 'GET'
         and self.request.GET.get('all', False),
         "tag":
         self.request.method == 'GET' and self.request.GET.get('tag', ''),
         "moderated_item":
         registry.get_by_name("film-features"),
         "moderated_items":
         moderated_items['items'],
         "moderator_tools":
         moderated_items['tools'],
         "from_moderation":
         True,
     })
     return context
예제 #17
0
파일: views.py 프로젝트: manlan2/filmaster
def moderate_item(request, model):
    moderated_item = registry.get_by_name(model)
    if moderated_item is None:
        raise Http404

    if request.user.has_perm(moderated_item.permission):
        if isinstance(moderated_item, ModeratorTool):
            return moderated_item.get_view(request)

        template = "moderation/index.html"
        moderated_items = registry.get_by_user(request.user)
        args = {
            "moderated_item": moderated_item,
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools'],
        }
        if request.method == 'POST':
            try:
                if 'reject' in request.POST and not 'confirmed' in request.POST:
                    item_id = request.POST.get('id', None)
                    if item_id is None:
                        raise ModerationException("Unknown item ...")

                    template = "moderation/reject.html"
                    args['form'] = RejectForm()
                    args['item'] = moderated_item.get_by_pk(int(item_id))

                else:
                    process_action(request, moderated_item)

            except ModerationException, e:
                request.user.message_set.create(message=str(e))

        return render_to_response(template,
                                  args,
                                  context_instance=RequestContext(request))
예제 #18
0
파일: views.py 프로젝트: thuvh/filmmaster
 def setUp( self ):
     super( ViewsTest, self ).setUp()
     # ..
     self.client = Client( follow=True )
     self.mi = registry.get_by_name( 'test-moderated-object' )
예제 #19
0
    def testRegistry( self ):
        self.assertRaises( AttributeError, registry.register, User )
        self.assertRaises( AttributeError, registry.register, User() )

        self.assertEqual( registry.get_by_name( 'test-moderated-object' ).get_name(),
                         'test-moderated-object' )
예제 #20
0
    def get_view( self, request ):
        moderated_items = registry.get_by_user( request.user )

        ctx = {
            "moderated_item": registry.get_by_name( self.name ),
            "moderated_items": moderated_items['items'],
            "moderator_tools": moderated_items['tools']
        }

        if request.method == 'POST':
            ctx['form'] = TagRenameForm( request.POST )
            if ctx['form'].is_valid():
                cleaned_data = ctx['form'].cleaned_data
                
                tag_a_name = cleaned_data['tagA']
                tag_a_tag = Tag.objects.get( name=tag_a_name )
                tag_a_count = self._get_tagged_objects_count( tag_a_tag )
                
                tag_b_name = cleaned_data['tagB']
                tag_b_tag = None
                try:
                    tag_b_tag = Tag.objects.get( name=tag_b_name )
                except Tag.DoesNotExist:
                    pass
                tag_b_count = self._get_tagged_objects_count( tag_b_tag ) if tag_b_tag else 0

                if not 'confirm' in request.POST:
                    ctx['to_confirm'] = {
                        'tagA': {
                            'name' : tag_a_name,
                            'count': tag_a_count,
                        },
                        'tagB': {
                            'name' : tag_b_name,
                            'count': tag_b_count,
                        }
                    }

                else:
                    
                    with transaction.commit_on_success():
                        # create tag b if not exists
                        if tag_b_tag is None:
                            tag_b_tag = Tag.objects.create( name=tag_b_name )
     
                        # replace tags
                        for obj in TaggedItem.objects.filter( tag=tag_a_tag ):
                            # if objects is already tagged with tag 'a' 
                            #   we must remove this relation
                            try:
                                ti = TaggedItem.objects.get( tag=tag_b_tag, content_type=obj.content_type, object_id=obj.object_id )
                                ti.delete()

                            except TaggedItem.DoesNotExist:
                                pass

                            obj.tag = tag_b_tag
                            obj.save()
                            
                            # update object localized tag_list
                            if isinstance( obj.object, ObjectLocalized ):
                                obj.object.tag_list = ', '.join( [ tag.name for tag in Tag.objects.get_for_object( obj.object ) ] )
                                obj.object.save()

                        # remove tag a
                        tag_a_tag.delete()
                        
                    messages.add_message( request, messages.INFO, _( "Tag renamed!" ) )
                    return redirect( self.get_absolute_url() )

        else: 
            ctx['form'] = TagRenameForm()

        return render( request, 'moderation/rename_tag/create.html', ctx )
예제 #21
0
 def setUp(self):
     super(ViewsTest, self).setUp()
     # ..
     self.client = Client(follow=True)
     self.mi = registry.get_by_name('test-moderated-object')