当前位置: 首页>>代码示例>>Python>>正文


Python utils.calculate_cloud函数代码示例

本文整理汇总了Python中tagging.utils.calculate_cloud函数的典型用法代码示例。如果您正苦于以下问题:Python calculate_cloud函数的具体用法?Python calculate_cloud怎么用?Python calculate_cloud使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了calculate_cloud函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

def index(request):
    select_detailed_source = SelecrSourceForm()
    source_points = Source.objects.exclude(point=None)
    searchform = SearchForm(request.GET)
    tagcloud = Tag.objects.cloud_for_model(Resource)
    qs = Resource.objects.filter(enabled=True).exclude(status="rejected")
    query = request.GET.get("q", None)
    if query != None:
        if query != "":
            qs = qs.filter(search_query_set(query))
        else:
            blankquery = True
        objects = []
        [objects.append(item) for item in qsfiltered]
        # treat querystring, remove page
        querystring = QueryDict(request.META.get("QUERY_STRING"))
        # handle pagination
        if "page" in request.GET:
            pageid = request.GET.get("page")
            if pageid:
                querystring._mutable = True
                del querystring["page"]
            querystring_nopage = querystring.urlencode()
        else:
            pageid = 1
            querystring_nopage = request.META.get("QUERY_STRING")

        paginator = Paginator(objects, CONTENT_PER_PAGE)

        try:
            page_obj = paginator.page(pageid)
        except TypeError:
            page_obj = paginator.page(1)
        except PageNotAnInteger:
            page_obj = paginator.page(1)
        except EmptyPage:
            page_obj = paginator.page(paginator.num_pages)
        object_list = page_obj.object_list
        return render_to_response("index.html", locals(), context_instance=RequestContext(request))

    else:
        # browse mode
        # featured list
        curricular_grades = CurricularGrade.objects.filter(parent=None)
        featured_list = (
            qs.filter(
                # category__code='video', thumbnails__gt=0
            )
            .order_by("?")
            .all()[0:2]
        )
        if featured_list.count() > 0:
            featured_list = featured_list.all()
        # tags
        tags_to_cloud = Tag.objects.usage_for_queryset(qs, counts=True)  # [0:20]
        calculate_cloud(tags_to_cloud, steps=5, distribution=LOGARITHMIC)
        query = ""
        # latest additions
        latest_additions = Resource.objects.filter(status="installed").order_by("-created")[0:5]
        return render_to_response("index.html", locals(), context_instance=RequestContext(request))
开发者ID:dudanogueira,项目名称:dudalibrary,代码行数:60,代码来源:views.py

示例2: get_context_data

 def get_context_data(self, **kwargs):
     tags = DjangoPerson.skilltags.cloud(steps=5)
     calculate_cloud(tags, 5)
     context = super().get_context_data(**kwargs)
     context.update({
         'tags': tags,
     })
     return context
开发者ID:django,项目名称:djangopeople,代码行数:8,代码来源:views.py

示例3: annotationview

def annotationview(request, asset_id, annot_id):
    annotation = get_object_or_404(SherdNote,
                                   pk=annot_id, asset=asset_id,
                                   asset__course=request.course)

    user = request.user
    if user.is_staff and request.GET.has_key('as'):
        user = get_object_or_404(User,username=request.GET['as'])

    if request.method in ("DELETE", "POST"):
        if request.method == "DELETE":
            redirect_to = reverse('asset-view', args=[asset_id])
        elif request.method == "POST":
            redirect_to = '.'

        form = request.GET.copy()
        form['next'] = redirect_to
        request.GET = form
        return annotation_dispatcher(request, annot_id)

    readonly = False
    if annotation.author != request.user:
        readonly = True
        
    asset = annotation.asset

    global_annotation = asset.global_annotation(user)

    if global_annotation == annotation:
        return HttpResponseRedirect(
            reverse('asset-view', args=[asset_id]))

    form = AnnotationForm(instance=annotation, prefix="annotation")

    tags = calculate_cloud(
        Tag.objects.usage_for_queryset(
            asset.sherdnote_set.all(), counts=True))
    user_tags = calculate_cloud(
        Tag.objects.usage_for_queryset(
            user.sherdnote_set.filter(
                asset__course=request.course),
            counts=True))

    comments = Comment and Comment.objects.for_model(asset) or None

    return {
        'annotation_form': form,
        'asset': asset,
        'comments': comments,
        'annotation': annotation,
        'global_annotation': global_annotation,
        'global_annotation_form': GlobalAnnotationForm(
            instance=global_annotation, prefix="annotation"),
        'tags': tags,
        'space_viewer':user,
        'user_tags': user_tags,
        'readonly': readonly,
        }
开发者ID:riadh001,项目名称:mediathread,代码行数:58,代码来源:views.py

示例4: test_invalid_distribution

 def test_invalid_distribution(self):
     try:
         calculate_cloud(self.tags, steps=5, distribution='cheese')
     except ValueError as ve:
         self.assertEqual(str(ve), 'Invalid distribution algorithm specified: cheese.')
     except Exception as e:
         raise self.failureException('the wrong type of exception was raised: type [%s] value [%s]' %\
             (str(type(e)), str(e)))
     else:
         raise self.failureException('a ValueError exception was supposed to be raised!')
开发者ID:crisish,项目名称:blog,代码行数:10,代码来源:tests.py

示例5: country_skill_cloud

def country_skill_cloud(request, country_code):
    country = get_object_or_404(Country, iso_code = country_code.upper())
    tags = Tag.objects.cloud_for_model(DjangoPerson, steps=5, filters={
        'country': country
    })
    calculate_cloud(tags, 5)
    return render(request, 'skills.html', {
        'tags': tags,
        'country': country
    })
开发者ID:KristianOellegaard,项目名称:djangopeople.net,代码行数:10,代码来源:views.py

示例6: render

 def render(self, djp, wrapper, prefix,
            for_model = None, steps = 4, min_count = None, **kwargs):
     try:
         formodel = ContentType.objects.get(id = int(for_model)).model_class()
     except:
         return u''
     
     steps     = int(steps)
     if min_count:
         min_count = int(min_count)
     site = get_site(djp.request.path)
     appmodel  = site.for_model(formodel)
     
     tags = self.get_tags(**kwargs)
     if tags:
         query = TaggedItem.objects.get_by_model(formodel,tags)
         query = self.model.objects.usage_for_queryset(query, counts=True)
         tags  = calculate_cloud(query)
     else:
         tags = Tag.objects.cloud_for_model(formodel,
                                            steps = steps,
                                            min_count = min_count)
     request = djp.request
     for tag in tags:
         try:
             tag.url = appmodel.tagurl(request, tag.name)
         except:
             tag.url = None
         if tag.count == 1:
             tag.times = 'time'
         else:
             tag.times = 'times'
     c = {'tags': tags}
     return loader.render_to_string(['bits/tag_cloud.html',
                                     'djpcms/bits/tag_cloud.html'],c)
开发者ID:strogo,项目名称:djpcms,代码行数:35,代码来源:plugins.py

示例7: container_view

def container_view(request):

    assets = [a for a in Asset.objects.filter(course=request.course).order_by('title')
              if a not in request.course.asset_set.archives()]

    from tagging.models import Tag
    all_tags = Tag.objects.usage_for_queryset(
        SherdNote.objects.filter(
            asset__course=request.course),
        counts=True)
    all_tags.sort(lambda a,b:cmp(a.name.lower(),b.name.lower()))
    all_tags = calculate_cloud(all_tags)

    for fil in filter_by:
        filter_value = request.GET.get(fil)
        if filter_value:
            assets = [asset for asset in assets
                      if filter_by[fil](asset, filter_value)]

    active_filters = dict((filter, request.GET.get(filter))
                          for filter in filter_by
                          if filter in request.GET)

    return {
        'assets':assets,
        'tags': all_tags,
        'active_filters': active_filters,
        'space_viewer':request.user,
        }
开发者ID:riadh001,项目名称:mediathread,代码行数:29,代码来源:views.py

示例8: tag_index

def tag_index(request, template_name="tagging_ext/index.html", min_size=0, limit=100):
    query = """
        SELECT tag_item.tag_id as tag_id, COUNT(tag_item.tag_id) as counter 
        FROM tagging_taggeditem as tag_item 
        INNER JOIN tagging_tag as tag ON (tag.id = tag_item.tag_id)
        GROUP BY tag.name,tag_id
        HAVING COUNT(tag.name) > %s
        ORDER BY tag.name
        LIMIT %s
    """

    cursor = connection.cursor()
    cursor.execute(query, [min_size, limit])

    tags = []

    for row in cursor.fetchall():
        try:
            tag = Tag.objects.get(id=row[0])
        except ObjectDoesNotExist:
            continue
            
        if ' ' in tag.name:
            continue
        
        tag.count = row[1]
        tags.append(tag)    

    tags = calculate_cloud(tags, steps=5, distribution=LOGARITHMIC)
        
    return render_to_response(template_name, {'tags': tags},
        context_instance=RequestContext(request))
开发者ID:joskid,项目名称:smeuhsocial,代码行数:32,代码来源:views.py

示例9: document_view

def document_view(request, document_id):
	if request.user.get_profile().is_lecturer:
		document = get_object_or_404(Document, Q(pk=document_id, is_lecturer_visible=True))
	else:
		document = get_object_or_404(Document, Q(pk=document_id))
	course = get_object_or_404(Course.objects.distinct('pk'), Q(pk=document.course.pk), Q(scopes__users__id=request.user.pk))
	category = Category.objects.get(Q(pk=course.category.pk))

	if document.is_etherpad:
		return HttpResponseRedirect(reverse("etherpad", args=[document.id]))

	comments = DocumentComment.objects.filter(document=document).order_by('pub_date')
	revisions = DocumentRevision.objects.filter(document=document).order_by('-pub_date')[1:]
	tags_raw = Tag.objects.usage_for_model(Document, counts=True)
	cloud_raw = calculate_cloud(tags_raw, steps=2)	
	tags = document.get_tags()
	cloud = [] 
	
	for tag in tags_raw:
		if tag in tags:
			cloud.insert(len(cloud) + 1, tag)

	if 'HTTP_USER_AGENT' in request.META:
		if request.META['HTTP_USER_AGENT'].find('MSIE') > 0:
			internet_explorer_warning = True
	
	return render_to_response("document.html", locals(), context_instance=RequestContext(request))		
开发者ID:vLj2,项目名称:docman,代码行数:27,代码来源:views.py

示例10: cloud_for_model

    def cloud_for_model(self, model, steps=4, distribution=LOGARITHMIC,
                        filters=None, min_count=None):
        """
        Obtain a list of tags associated with instances of the given
        Model, giving each tag a ``count`` attribute indicating how
        many times it has been used and a ``font_size`` attribute for
        use in displaying a tag cloud.

        ``steps`` defines the range of font sizes - ``font_size`` will
        be an integer between 1 and ``steps`` (inclusive).

        ``distribution`` defines the type of font size distribution
        algorithm which will be used - logarithmic or linear. It must
        be either ``tagging.utils.LOGARITHMIC`` or
        ``tagging.utils.LINEAR``.

        To limit the tags displayed in the cloud to those associated
        with a subset of the Model's instances, pass a dictionary of
        field lookups to be applied to the given Model as the
        ``filters`` argument.

        To limit the tags displayed in the cloud to those with a
        ``count`` greater than or equal to ``min_count``, pass a value
        for the ``min_count`` argument.
        """
        tags = list(self.usage_for_model(model, counts=True, filters=filters,
                                         min_count=min_count))
        return calculate_cloud(tags, steps, distribution)
开发者ID:django-tagtools,项目名称:djtt-tagging,代码行数:28,代码来源:models.py

示例11: pluginbrowser

def pluginbrowser(request):

    if request.method == 'POST':
        #This form actually should not be submitted via POST. It is done by javascript function with AJAX call.
        #So this block of code will not be executed.
        form = PluginSearchForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/')
    else:
        _dbobjects = get_my_plugins(request.user) | get_shared_plugins(request.user)
        #get newest 10 plugins
        newest_plugin_list = _dbobjects.order_by('-created')[:10]
        #get recently updated 10 plugins
        #updated_plugin_list = _dbobjects.order_by('-lastmodified')[:10]
        updated_plugin_list = _dbobjects.exclude(created__gte=F('lastmodified')).order_by('-lastmodified')[:10]
                                                       #^^^^^when a new plugin is saved, "created" is slightly newer than "lastmodified"
        popular_plugin_list = _dbobjects.filter(popularity__score__isnull=False).order_by('-popularity__score')[:10]
        form = PluginSearchForm()

        plugin_tags = calculate_cloud(Tag.objects.usage_for_queryset(_dbobjects, counts=True, min_count=2))

        d = {'form': form,
             'newest_plist': newest_plugin_list,
             'updated_plist': updated_plugin_list,
             'popular_plist': popular_plugin_list,
             'anonymous_user': request.user.is_anonymous(),
             'plugin_tags': plugin_tags,
            }
        return render_to_response('plugin/pluginlibrary.html', d)
开发者ID:SuLab,项目名称:biogps_core,代码行数:29,代码来源:plugin.py

示例12: get_tagcloud_intersection

def get_tagcloud_intersection(agree_issues, disagree_issues):
    try :
        agree_tags = Tag.objects.usage_for_model(Issue, 
            counts=True, filters=dict(id__in=agree_issues))
    except EmptyResultSet:
        agree_tags = []
    try:
        disagree_tags = Tag.objects.usage_for_model(Issue, 
            counts=True, filters=dict(id__in=disagree_issues))
    except EmptyResultSet:
        disagree_tags = [] 

    tags_dagree= dict((tag.name, tag) for tag in disagree_tags)
    all_tags = []
    # loop over al for tags, look if tag also exists in disagree tag
    # if so add a status with 'conflict' to the tag.
    # agree_tags have 'agree' status
    # disagree_tags have no status.
    for a_tag in agree_tags:
        a_tag.status = 'agree'
        if tags_dagree.has_key(a_tag.name):
            d_tag = tags_dagree[a_tag.name]
            d_tag.count = d_tag.count + a_tag.count
            d_tag.status = 'conflict'
            all_tags.append(d_tag)
            tags_dagree.pop(a_tag.name)
        else:
            all_tags.append(a_tag)

    all_tags.extend(tags_dagree.values())
    
    return calculate_cloud(all_tags)
开发者ID:spreeker,项目名称:democracygame,代码行数:32,代码来源:votes.py

示例13: tags

def tags(request):
    all_tags = {}
    
    # Want 2.7 for the collections.Counter :(
    def update_tags(tag):
        existing = all_tags.get(tag.name, None)
        if existing:
            existing.count += tag.count
        else:
            all_tags[tag.name] = tag
        
    scraper_tags = Tag.objects.usage_for_model(Scraper, counts=True, filters={'privacy_status':'public', 'privacy_status':'visible'})
    view_tags = Tag.objects.usage_for_model(View, counts=True, filters={'privacy_status':'public', 'privacy_status':'visible'})
    for tag in itertools.chain(scraper_tags, view_tags):
        update_tags(tag)
    
    # Use UserCodeRole objects to get code objects that are private but 
    # accessible to this user and then use update_tags to update the 
    # dictionary
    if request.user.is_authenticated():
        privatescraper_ids = [u.code.id for u in UserCodeRole.objects.filter(code__privacy_status='private', user=request.user)]
        qs = Code.objects.filter(pk__in=privatescraper_ids)
        extra_tags = Tag.objects.usage_for_queryset(qs, counts=True)
        for tag in extra_tags:
            update_tags(tag)
        
    tags = calculate_cloud(all_tags.values(), steps=4, distribution=LOGARITHMIC)

    return render_to_response('frontend/tags.html', {'tags':tags}, context_instance=RequestContext(request))
开发者ID:lkundrak,项目名称:scraperwiki,代码行数:29,代码来源:views.py

示例14: get_tag_cloud

def get_tag_cloud(context, steps=6, template='zinnia/tags/tag_cloud.html'):
    """Return a cloud of published tags"""
    tags = Tag.objects.usage_for_queryset(
        Entry.published.all(), counts=True)
    return {'template': template,
            'tags': calculate_cloud(tags, steps),
            'context_tag': context.get('tag')}
开发者ID:WayneTatum,项目名称:django-blog-zinnia,代码行数:7,代码来源:zinnia_tags.py

示例15: tag_cloud

 def tag_cloud(self):
     "Returns instance tags annotated with tag cloud weights"
     # Just using self.tags doesn't aggregate properly (the only
     # matching item is self)
     tags = (Tag.objects
             .filter(pk__in=[t.pk for t in self.tags])
             .annotate(count=Count('items')))
     return calculate_cloud(tags)
开发者ID:waffle-iron,项目名称:decisions,代码行数:8,代码来源:models.py


注:本文中的tagging.utils.calculate_cloud函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。