Put a list of categories for blog posts into the template context.
550080
def blog_categories(*args):
    
    posts = BlogPost.objects.published()
    categories = BlogCategory.objects.filter(blogposts__in=posts)
    return list(categories.annotate(post_count=Count("blogposts")))
1004442
protected function addCategoryGroup()
    {
        if (!$this->isError()) {
            $id = $this->category_group->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
935288
function setCategories( $value, $params=FALSE ) {
    $category = array();
    $category['value']  = $value;
    $category['params'] = $this->_setParams( $params );
    $this->categories[] = $category;
  }
121586
def update_categories
      @post = LatoBlog::Post.find_by(id: params[:id])
      return unless check_post_presence

      params[:categories].each do |category_id, value|
        category = LatoBlog::Category.find_by(id: category_id)
        next if !category || category.meta_language != @post.meta_language

        category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
        if value == 'true'
          LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
        else
          category_post.destroy if category_post
        end
      end
    end
1156582
protected function attach_nodes_to_categories() {
        foreach ($this->nodes as $node) {
            $parentcat = $node->parentcat;
            if (!isset($this->categories[$parentcat])) {
                throw new \coding_exception("Category $parentcat doesn't exist");
            } else {
                $this->categories[$parentcat]->add_node($node);
            }
        }
    }
1350553
def category_links(categories)
      base_dir = @context.registers[:site].config['category_dir']
      categories = categories.sort!.map do |category|
        category_dir = GenerateCategories.category_dir(base_dir, category)
        # Make sure the category directory begins with a slash.
        category_dir = "/#{category_dir}" unless category_dir =~ /^\//
        "<a class='category' href='#{category_dir}/'>#{category}</a>"
      end

      case categories.length
      when 0
        ""
      when 1
        categories[0].to_s
      else
        categories.join(', ')
      end
    end
235528
def set_categories(self):
        """"""
        self.categories = []
        temp_categories = self.soup.findAll('category')
        for category in temp_categories:
            category_text = category.string
            self.categories.append(category_text)
1048285
private function AddCategoryField()       
    {
        $name = 'Category';
        $value = '';
        if ($this->article->Exists()) {
            $value = $this->article->GetCategory()->GetID();
        }
        $field = new Select($name, $value);
        $field->AddOption('', Trans('Core.PleaseSelect'));
        $catList = new CategoryListProvider($this->archive);
        $categories = $catList->ToArray();
        foreach ($categories as $category) {
            $field->AddOption($category->GetID(), $category->GetName());
        }
        $this->AddField($field);
        $this->SetRequired($name);
    }
116021
def _to_add_with_category(self, catid):
        '''
        
        '''

        catinfo = MCategory.get_by_uid(catid)
        kwd = {
            'uid': self._gen_uid(),
            'userid': self.userinfo.user_name if self.userinfo else '',
            'gcat0': catid,
            'parentname': MCategory.get_by_uid(catinfo.pid).name,
            'catname': MCategory.get_by_uid(catid).name,
        }

        self.render('autogen/add/add_{0}.html'.format(catid),
                    userinfo=self.userinfo,
                    kwd=kwd)
883143
public function addCategory($category)
    {
        if (!($category instanceof Category)) {
            $category = new Category($category);
        }
        $this->categories[] = $category;
    }
110964
def _addTags(self, **k):
        """"""

        for tag, thing in k.items():
            if not isinstance(thing, (tuple, list)):
                thing = (thing,)
            typetag = defaulttagtype[tag]
            self.rawtagdict[tag] = encode(typetag, *thing)
        return self
1351224
def get_categories_tree(context, template='zinnia/tags/categories_tree.html'):
    
    return {'template': template,
            'categories': Category.objects.all().annotate(
                count_entries=Count('entries')),
            'context_category': context.get('category')}
1254062
def output_list(self, category):
        """"""
        print('{} users:'.format(category))
        for user in getattr(self.sub, category):
            print('  {}'.format(user))
861574
def add_category(self, name):
        
        category = BayesCategory(name)
        self.categories[name] = category
        return category
852886
def get_categories(blog_id, username, password):
    
    authenticate(username, password)
    site = Site.objects.get_current()
    return [category_structure(category, site)
            for category in Category.objects.all()]
20234
def render_category(category='', template=None):
    
    # pylint:disable=too-many-return-statements

    # See if this is an aliased path
    redir = get_redirect()
    if redir:
        return redir

    # Forbidden template types
    if template and template.startswith('_'):
        raise http_error.Forbidden("Template is private")
    if template in ['entry', 'error']:
        raise http_error.BadRequest("Invalid view requested")

    if category:
        # See if there's any entries for the view...
        if not orm.select(e for e in model.Entry if e.category == category or
                          e.category.startswith(category + '/')):
            raise http_error.NotFound("No such category")

    if not template:
        template = Category(category).get('Index-Template') or 'index'

    tmpl = map_template(category, template)

    if not tmpl:
        # this might actually be a malformed category URL
        test_path = '/'.join((category, template)) if category else template
        logger.debug("Checking for malformed category %s", test_path)
        record = orm.select(
            e for e in model.Entry if e.category == test_path).exists()
        if record:
            return redirect(url_for('category', category=test_path, **request.args))

        # nope, we just don't know what this is
        raise http_error.NotFound("No such view")

    view_spec = view.parse_view_spec(request.args)
    view_spec['category'] = category
    view_obj = view.View(view_spec)

    rendered, etag = render_publ_template(
        tmpl,
        _url_root=request.url_root,
        category=Category(category),
        view=view_obj)

    if request.if_none_match.contains(etag):
        return 'Not modified', 304

    return rendered, {'Content-Type': mime_type(tmpl),
                      'ETag': etag}
40371
public function addCategory(BlogCategory $category)
    {
        $category->setBlog($this);
        $this->categories->add($category);

        return $this;
    }