Exemplo n.º 1
0
def createTag(request):
  print request.POST
  tag = Tag()
  tag_dict = doc.to_dict(request.POST, request.user.id)
  if tag_dict.parent == ObjectId("0"):
    tag_obj = doc.collection.insert_one(tag_dict)
  else:
    doc.collection.update_one({"_id":tag_dict.parent}, {$addToSet: {"sub_tag": {"name":tag_dict.name}}}, upsert=False)
  return redirect('/documents/indexTag')
Exemplo n.º 2
0
    def handle(self, *args, **options):

        self.verbosity = options["verbosity"]

        for document in Document.objects.all():

            tags = Tag.objects.exclude(
                pk__in=document.tags.values_list("pk", flat=True))

            for tag in Tag.match_all(document.content, tags):
                print('Tagging {} with "{}"'.format(document, tag))
                document.tags.add(tag)
Exemplo n.º 3
0
    def handle(self, *args, **options):

        self.verbosity = options["verbosity"]

        correspondents = list(Correspondent.objects.all())

        for document in Document.objects.iterator():

            tags = Tag.objects.exclude(
                pk__in=document.tags.values_list("pk", flat=True))

            for tag in Tag.match_all(document.content, tags):
                print('Tagging {} with "{}"'.format(document, tag))
                document.tags.add(tag)

            if not document.correspondent:
                for c in correspondents:
                    if c.matches(document.content):
                        print('Correspondent of {} is "{}"'.format(
                            document, c))
                        document.correspondent = c
                        document.save()
Exemplo n.º 4
0
def get_tag_keys(tag_list):
    """
    Accepts a list of humanized tag names and returns a list of the db.Key's
    for the corresponding Tag model entries.
    """
    if not tag_list:
        return []
    key_list = []
    for tag_name in tag_list:
        obj = Tag.get_by_key_name(slugify(tag_name))
        if obj:
            key_list.append(obj.key())
        else:
            slug = slugify(tag_name)
            obj = Tag(title=tag_name, slug=slug, key_name=slug)
            obj.put()
            key_list.append(obj.key())
    return key_list
Exemplo n.º 5
0
def new(request):
  tags = Tag().collection.find({})
  return render(request, 'documents/new.html', {"tags":tags})