Exemplo n.º 1
0
 def setUp(self):
     self.tags = []
     for line in open(os.path.join(os.path.dirname(__file__), 'test_tags.txt')).readlines():
         name, count = line.rstrip().split()
         tag = Tag(name=name)
         tag.count = int(count)
         self.tags.append(tag)
Exemplo n.º 2
0
    def testTagClouds(self):
        tags = []
        for line in open(os.path.join(os.path.dirname(__file__),
                                      'tags.txt')).readlines():
            name, count = line.rstrip().split()
            tag = Tag(name=name)
            tag.count = int(count)
            tags.append(tag)

        sizes = {}
        for tag in calculate_cloud(tags, steps=5):
            sizes[tag.font_size] = sizes.get(tag.font_size, 0) + 1

        # This isn't a pre-calculated test, just making sure it's consistent
        self.assertEqual({1: 48, 2: 30, 3: 19, 4: 15, 5: 10}, sizes)

        sizes = {}
        for tag in calculate_cloud(tags, steps=5, distribution=LINEAR):
            sizes[tag.font_size] = sizes.get(tag.font_size, 0) + 1

        # This isn't a pre-calculated test, just making sure it's consistent
        self.assertEqual({1: 97, 2: 12, 3: 7, 4: 2, 5: 4}, sizes)

        self.assertRaises(ValueError,
                          calculate_cloud,
                          tags,
                          steps=5,
                          distribution='cheese')
 def _synonym(self,item):
     tag=self._find_tag(item['id'],item['name'])
     properTags=Tag.objects.filter(name=item['proper_name'])
     if len(properTags)>0:
         properTag=properTags[0]
     else:
         properTag=None
     if tag is not None:
         if properTag is None:
             # got the synonym tag but not the proper tag
             # create the proper tag - so we can link it to the synonym
             properTag=Tag(name=item['proper_name'])
             properTag.save()
         if properTag is not None and properTag!=tag:
             # got the synonym tag and the proper tag - just create the synonym
             try:
                 ts=TagSynonym(tag=properTag,synonym_tag=tag)
                 if self._options['nodryrun']:
                     ts.save()
                     self.stdout.write('done')
             except IntegrityError as e:
                 if str(e)=='column synonym_tag_id is not unique':
                     self.stdout.write('-- warning --')
                     self.stdout.write('synonym already exists')
                     self.stdout.write('--------------------')
                 else:
                     raise e
Exemplo n.º 4
0
 def setUp(self):
     self.tags = []
     for line in default_tags:
         name, count = line.rstrip().split()
         tag = Tag(name=name)
         tag.count = int(count)
         self.tags.append(tag)
Exemplo n.º 5
0
def list_tag(request, name, **kwargs):
    try:
        tag = Tag.objects.get(name=name)
    except:
        tag = Tag()
        tag.name = name
    queryset = SoftwareCollection.tagged.with_all(tag).filter(has_content=True)
    dictionary = {'tag': tag}
    return _list(request, 'scls/list_tag.html', queryset, dictionary, **kwargs)
Exemplo n.º 6
0
 def test_tag_entries(self):
     self.create_published_entry()
     feed = TagEntries()
     tag = Tag(name='tests')
     self.assertEquals(feed.get_object('request', 'tests').name, 'tests')
     self.assertEquals(len(feed.items('tests')), 1)
     self.assertEquals(feed.link(tag), '/tags/tests/')
     self.assertEquals(feed.get_title(tag),
                       'Entries for the tag %s' % tag.name)
     self.assertEquals(feed.description(tag),
                       'The latest entries for the tag %s' % tag.name)
Exemplo n.º 7
0
 def test_tag_gbobjects(self):
     self.create_published_gbobject()
     feed = TagGbobjects()
     tag = Tag(name='tests')
     self.assertEquals(feed.get_object('request', 'tests').name, 'tests')
     self.assertEquals(len(feed.items('tests')), 1)
     self.assertEquals(feed.link(tag), '/tags/tests/')
     self.assertEquals(feed.title(tag),
                       _('Gbobjects for the tag %s') % tag.name)
     self.assertEquals(feed.description(tag),
                       _('The latest gbobjects for the tag %s') % tag.name)
Exemplo n.º 8
0
 def test_tag_title_non_ascii(self):
     entry = self.create_published_entry()
     tag_unicode = smart_text('accentué')
     entry.tags = tag_unicode
     entry.save()
     feed = TagEntries()
     tag = Tag(name=tag_unicode)
     self.assertEqual(feed.get_title(tag),
                      'Entries for the tag %s' % tag_unicode)
     self.assertEqual(feed.description(tag),
                      'The last entries tagged with %s' % tag_unicode)
Exemplo n.º 9
0
    def test_search_by_not_tag(self):
        client = self.client
        self.login(client)

        unused_tag = Tag(name="Unused")
        unused_tag.save()
        response = client.post('/contacts/', {
            'search_term': "My",
            "tags": [unused_tag.id]
        })

        self.assertContains(response, 'No Results found.')
Exemplo n.º 10
0
def TagsView(request, template_name="news/tags_list.html"):

    if request.method == 'POST':

        for field in request.POST:

            region_field = field.split('_')
            tag_name = request.POST[field]

            if region_field[0] == 'tag' and tag_name != 'None':

                # What region are we dealing with?
                if region_field[1] == '0':
                    region = None  # 0 = All
                else:
                    region = Region.objects.get(id=region_field[1])

                # Get region tag if available
                if region is not None:
                    tag = list(Tag.objects.get_for_object(region))
                else:
                    tag = [
                        get_redmap_tag(),
                    ]

                if not tag:

                    # create tag if not exists
                    tag = Tag()
                    tag.name = tag_name
                    tag.save()

                elif tag[0].name != tag_name:

                    # update tag if different
                    tag[0].name = tag_name
                    tag[0].save()

                    # TODO: If we update a tag, we will need to update zinnia
                    #       entries with updated tags because the app stores
                    #       tags in a plain-text string rather than by model
                    #       association

                if region is not None:
                    # attach tag to region
                    Tag.objects.update_tags(region, tag_name + ',')

        return HttpResponseRedirect(reverse('news_tags_list'))

    return render(request, template_name)
Exemplo n.º 11
0
def import_tags():
    fields = ['id', 'name', 'alias']
    sql = "SELECT %s FROM jos_tegs" % (', '.join(fields))

    cursor = db.cursor()
    cursor.execute(sql)
    all_tags = cursor.fetchall()

    count = 0
    bar = progressbar.ProgressBar(maxval=len(all_tags),
                                  widgets=[
                                      'import tags: ',
                                      progressbar.SimpleProgress(),
                                  ]).start()

    for row in all_tags:
        Tag(pk=int(row[0]), name=str(row[1]), slug=str(row[2])).save()
        count += 1
        bar.update(count)
    bar.finish()
Exemplo n.º 12
0
  def prepare (self, ids):  # change to 'compile'!
    if trace: print 'PREPARE SOUP', ids
    if not self.head:
      self.html.insert (0, Tag (self, 'head'))

    if 'base' in ids: # set up base tag - get from request, at render/call-time
      ids.remove ('base')
      if self.base:
        self.base ['href'] = '%(base)s'
      else:
        self.head.insert (0, '<base href="%(base)s" />')

    if 'title' in ids:
      ids.remove ('title')
      if self.title:
        self.title.contents = '%(title)s'
      else:
        self.head.insert (1, '<title>%(title)s</title>')

    # if 'meta' in ids:  # need to enh to deal with meta kw, meta desc, etc

    if 'header_extras' in ids:
      ids.remove ('header_extras')
      self.head.append ('%(header_extras)s')
      # bsoup 3.04 requires this:
      # self.head.insert (99,'%(header_extras)s')
      #print self.head

    if 'footer_extras' in ids:
      ids.remove ('footer_extras')
      self.body.append ('%(footer_extras)s')

    kw = dict ([(id, '%(' + id + ')s') for id in ids])
    # WARNING: Don't we want to double-up the %s => %%?

    # could do it this way:
    #for k in 'doctype base title meta header_extras footer_extras'.split():
    #  if k in kw:
    #    v = kw.pop (k)

    self.replaceIds (**kw)
Exemplo n.º 13
0
    def form_valid(self, form: TagForm) -> HttpResponseRedirect:
        social_token: SocialToken = SocialToken.objects.get(
            account__user=self.request.user.id)

        api = Twitter(
            social_token.app.client_id,
            social_token.app.secret,
            social_token.token,
            social_token.token_secret,
        )
        tag = api.create_list(
            form.cleaned_data["name"],
            form.cleaned_data["description"],
            form.cleaned_data["is_private"],
        )

        Tag(list_id=tag.id,
            account=social_token.account,
            name=form.cleaned_data["name"]).save()

        return super().form_valid(form)
Exemplo n.º 14
0
def create_tag(request, user_id):
    if request.method != 'POST':
        error_dict = {"message": "Method not allowed"}
        error_data = json.dumps(error_dict)
        return HttpResponseNotAllowed(error_data,
                                      content_type="application/json")

    received_json_data = json.loads(request.body)
    form = TagForm(received_json_data)
    if form.is_valid():
        new_tag = Tag(tag_name=form.cleaned_data['tag_name'])
        new_tag.user = request.user
        new_tag.save()
        data = json.dumps(new_tag.to_dict())
        logger.info("New Tag created name: %s id: %s", new_tag.tag_name,
                    new_tag.id)
        return HttpResponse(data)
    else:
        logger.error("Invalid Tag Form. %s", form.errors)
        error_data = json.dumps(form.errors)
        return HttpResponseBadRequest(error_data)
Exemplo n.º 15
0
 def test_location(self):
     tag = Tag(name="meeker")
     self.assertEqual('/tag/meeker/', self.sitemap.location(tag))
Exemplo n.º 16
0
 def test_tag_entries(self):
     self.create_published_entry()
     feed = TagEntries()
     self.assertEquals(feed.get_object('request', 'tests').name, 'tests')
     self.assertEquals(len(feed.items('tests')), 1)
     self.assertEquals(feed.link(Tag(name='tests')), '/tags/tests/')