Create or update a Category related to a post.

        :param bulk_mode: If True, minimize db operations by bulk creating post objects
        :param api_category: the API data for the Category
        :return: the Category object
973447
def process_post_category(self, bulk_mode, api_category):
        
        category = None

        # try to get from the ref data map if in bulk mode
        if bulk_mode:
            category = self.ref_data_map["categories"].get(api_category["ID"])

        # double check the db before giving up, we may have sync'd it in a previous run
        if not category:
            category, created = Category.objects.get_or_create(site_id=self.site_id,
                                                               wp_id=api_category["ID"],
                                                               defaults=self.api_object_data("category", api_category))

            if category and not created:
                self.update_existing_category(category, api_category)

            # add to ref data map so later lookups work
            if category:
                self.ref_data_map["categories"][api_category["ID"]] = category

        return category
16522
def enable_category(self, category: str) -> None:
        
        for cmd_name in list(self.disabled_commands):
            func = self.disabled_commands[cmd_name].command_function
            if hasattr(func, HELP_CATEGORY) and getattr(func, HELP_CATEGORY) == category:
                self.enable_command(cmd_name)
810405
def _set_categories(self):
        
        for column, _ in self._categories.items():
            if column in self.columns:
                self[column] = self[column].astype('category')
282568
def __related_categories(self, category_id):
        
        related = []
        for cat in self.categories_tree:
            if category_id in self.categories_tree[cat]:
                related.append(self.categories[cat])
        return related
1273388
def help_center_category_translation_create(self, category_id, data, **kwargs):
        ""
        api_path = "/api/v2/help_center/categories/{category_id}/translations.json"
        api_path = api_path.format(category_id=category_id)
        return self.call(api_path, method="POST", data=data, **kwargs)
956036
def related_by_category(obj, count, collected_so_far, mods=[], only_from_same_site=True):
    
    related = []
    # top objects in given category
    if count > 0:
        from ella.core.models import Listing
        cat = obj.category
        listings = Listing.objects.get_queryset_wrapper(
            category=cat,
            content_types=[ContentType.objects.get_for_model(m) for m in mods]
        )
        for l in listings[0:count + len(related)]:
            t = l.publishable
            if t != obj and t not in collected_so_far and t not in related:
                related.append(t)
                count -= 1

            if count <= 0:
                return related
    return related
1199481
def addCategory(self, categoryUri, weight):
        
        assert isinstance(weight, (float, int)), "weight value has to be a positive or negative integer"
        self.topicPage["categories"].append({"uri": categoryUri, "wgt": weight})
237410
def category(self):
        
        if self.api and self.category_id:
            return self.api._get_category(self.category_id)
319169
def for_category(self, category, live_only=False):
        
        filters = {'tag': category.tag}

        if live_only:
            filters.update({'entry__live': True})

        return self.filter(**filters)
577533
def create_post(self, title, body, board, category, username):
    '''

    '''

    category_url = "%s/categories.json" % board
    response = requests.get(category_url)

    if response.status_code != 200:
        print('Error with retrieving %s' % category_url)
        sys.exit(1)

    # Get a list of all categories
    categories = response.json()['category_list']['categories']
    categories = {c['name']:c['id'] for c in categories}

    # And if not valid, warn the user
    if category not in categories:
        bot.warning('%s is not valid, will use default' % category)

    category_id = categories.get(category, None)

    headers = {"Content-Type": "application/json",
               "User-Api-Client-Id": self.client_id,
               "User-Api-Key": self.token }


    # First get the category ids
    data = {'title': title,
            'raw': body,
            'category': category_id}

    response = requests.post("%s/posts.json" % board,
                             headers=headers,
                             data=json.dumps(data))

    if response.status_code in [200, 201, 202]:
        topic = response.json()
        url = "%s/t/%s/%s" %(board, topic['topic_slug'], topic['topic_id'])
        bot.info(url)
        return url

    elif response.status_code == 404:
        bot.error('Cannot post to board, not found. Do you have permission?')
        sys.exit(1)

    else:
        bot.error('Cannot post to board %s' % board)
        bot.error(response.content)
        sys.exit(1)
474566
public function course_bulk_actions(core_course_category $category) {
        $html  = html_writer::start_div('course-bulk-actions bulk-actions');
        if ($category->can_move_courses_out_of()) {
            $html .= html_writer::div(get_string('coursebulkaction'), 'accesshide', array('tabindex' => '0'));
            $options = core_course_category::make_categories_list('moodle/category:manage');
            $select = html_writer::select(
                $options,
                'movecoursesto',
                '',
                array('' => 'choosedots'),
                array('aria-labelledby' => 'moveselectedcoursesto', 'class' => 'mr-1')
            );
            $submit = array('type' => 'submit', 'name' => 'bulkmovecourses', 'value' => get_string('move'),
                'class' => 'btn btn-secondary');
            $html .= $this->detail_pair(
                html_writer::span(get_string('moveselectedcoursesto'), '', array('id' => 'moveselectedcoursesto')),
                $select . html_writer::empty_tag('input', $submit)
            );
        }
        $html .= html_writer::end_div();
        return $html;
    }
174493
def update_catagory(netid, category_code, status):
    
    url = "{0}/category".format(url_version())
    body = {
        "categoryCode": category_code,
        "status": status,
        "categoryList": [{"netid": netid}]
    }

    response = post_resource(url, json.dumps(body))
    return json.loads(response)
581251
public function update(ArticleCategory $category, Request $request)
	{
		$this->validate($request, ArticleCategory::$rules, ArticleCategory::$messages);

        $this->updateEntry($category, $request->only('name'));

        return redirect_to_resource();
	}
599318
def list_categories(location_id, opts = {})
      data, _status_code, _headers = list_categories_with_http_info(location_id, opts)
      return data
    end
353092
def bulk(self, request, *args, **kwargs):
        
        manager = self.get_manager()
        errors = {}
        preferences = []
        payload = request.data

        # first, we check updated preferences actually exists in the registry
        try:
            for identifier, value in payload.items():
                try:
                    preferences.append(
                        self.queryset.model.registry.get(identifier))
                except exceptions.NotFoundInRegistry:
                    errors[identifier] = 'invalid preference'
        except (TypeError, AttributeError):
            return Response('invalid payload', status=400)

        if errors:
            return Response(errors, status=400)

        # now, we generate an optimized Q objects to retrieve all matching
        # preferences at once from database
        queries = [
            Q(section=p.section.name, name=p.name)
            for p in preferences
        ]

        query = queries[0]
        for q in queries[1:]:
            query |= q
        preferences_qs = self.get_queryset().filter(query)

        # next, we generate a serializer for each database preference
        serializer_objects = []
        for p in preferences_qs:
            s = self.get_serializer_class()(
                p, data={'value': payload[p.preference.identifier()]})
            serializer_objects.append(s)

        validation_errors = {}

        # we check if any serializer is invalid
        for s in serializer_objects:
            if s.is_valid():
                continue
            validation_errors[s.instance.preference.identifier()] = s.errors

        if validation_errors:
            return Response(validation_errors, status=400)

        for s in serializer_objects:
            s.save()

        return Response(
            [s.data for s in serializer_objects],
            status=200,
        )
1337438
protected function addCategory()
    {
        if (!$this->isError()) {
            $id = $this->category->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
1088719
def gifs_categories_get(api_key, opts = {})
      data, _status_code, _headers = gifs_categories_get_with_http_info(api_key, opts)
      return data
    end