<commit_before>"""Tag handler

A (multilingual) tag handler
"""
import tornado
import logging
from bson.objectid import ObjectId
from bson.json_util import dumps, loads
from slugify import slugify
from server.handlers.base_handler import BaseHandler


class TagHandler(BaseHandler):

    def initialize(self, db):
        """
        Initializes the instance with a mongodb database instance
        :param db: an instance to pymongo database object
        """
        self._db = db

    def get(self):
        """
        loads a single tag entry
        """
        language = self.get_argument('language', None)
        query = self.get_argument('query', '')

        tags = self._db['tag'].find()
        self.write(dumps(tags))
        return
        if query:
            if language:
                tags = self._db['tag'].find({'language':language,'name':{"$regex": '*{}*'.format(query)}})
                self.write(dumps(tags))
            else:
                tags = self._db['tag'].find({'name':{"$regex": '*{}*'.format(query)}})
                self.write(dumps(tags))
    
    def post(self):
        """
        add a new tag
        
        """
        tag = loads(self.request.body.decode("utf-8"))
        try:
            ret = self._db['tag'].insert(tag)
            self.write(dumps(ret))
        except Exception as e:
            self.write(dumps({'status':'error','error':str(e)}))
<commit_msg>basic tag is working<commit_after>"""Tag handler

A (multilingual) tag handler
"""
import tornado
import logging
from bson.objectid import ObjectId
from bson.json_util import dumps, loads
from slugify import slugify
from server.handlers.base_handler import BaseHandler


class TagHandler(BaseHandler):

    def initialize(self, db):
        """
        Initializes the instance with a mongodb database instance
        :param db: an instance to pymongo database object
        """
        self._db = db

    def get(self):
        """
        loads a single tag entry
        """
        language = self.get_argument('language', None)
        query = self.get_argument('query', '')

        tags = self._db['tag'].find({},{'name':1})
        ret = []
        for t in tags:
            ret.append(t['name'])
        self.write(dumps(ret))
        return
        if query:
            if language:
                tags = self._db['tag'].find({'language':language,'name':{"$regex": '*{}*'.format(query)}})
                self.write(dumps(tags))
            else:
                tags = self._db['tag'].find({'name':{"$regex": '*{}*'.format(query)}})
                self.write(dumps(tags))
    
    def post(self):
        """
        add a new tag
        
        """
        tag = loads(self.request.body.decode("utf-8"))
        try:
            ret = self._db['tag'].insert(tag)
            self.write(dumps(ret))
        except Exception as e:
            self.write(dumps({'status':'error','error':str(e)}))

{'fraction_non_alphanumeric': 0.1434412265758092, 'fraction_numerical': 0.0010221465076660989, 'mean_word_length': 2.0937829293993677, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3849442', 'n_tokens_mistral': 856, 'n_tokens_neox': 825, 'n_words': 201}