lfarrell / django-tagging Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/django-tagging
License: Other
Automatically exported from code.google.com/p/django-tagging
License: Other
I love django-tagging, but I had the need for tags with multiple words. For
example, if I wanted
to tag an item as "stained glass", but didn't want it to break into two tags, I
would have to use
"stained-glass" or "stainedglass", neither of which I liked very much.
With just two tiny changes in utils.py, I was able to add the ability to
designate a multiple word
string as a single tag using quotes, without (as far as I can tell) affecting
the previous
functionality. So now, the user can type 'window "stained glass" blue'
(without single quotes) and
the generated tags will be "window", "stained glass", and "blue".
Here's the changed section of my utils.py:
find_tag_re = re.compile('\"[-\w\s]+\"|[-\w]+', re.U)
def get_tag_name_list(tag_names):
"""
Find tag names in the given string and return them as a list.
"""
if not isinstance(tag_names, unicode) and tag_names is not None:
tag_names = tag_names.decode(settings.DEFAULT_CHARSET)
tag_names = re.sub('\s+', ' ', tag_names)
results = find_tag_re.findall(tag_names or '')
return [item.encode(settings.DEFAULT_CHARSET).replace('"', '') for item in results]
Note that I added the re.sub line to get rid of extra spaces that might crop up
from this.
Hope this is useful to someone else.
Branton
Original issue reported on code.google.com by [email protected]
on 2 Jun 2007 at 9:52
The attached patch (which is really just an added file) adds a TagField
object (in ``tagging.fields``) that allows more natural access to tags on
tagged items. You define it thusly::
from django.db import models
from tagging.fields import TagField
class MyModel(models.Model):
...
tags = TagField()
And then use it pretty naturally::
>>> from myapp.models import MyModel
>>> m = MyModel.objects.get(...)
>>> m.tags = "foo bar"
>>> m.tags
"bar foo"
>>> m.tags = "foo bar baz"
>>> m.tags
"bar baz foo"
Original issue reported on code.google.com by [email protected]
on 11 Mar 2007 at 2:03
Attachments:
It would be useful provide update_tags functionality for additional tag
formats when importing data from other services. Off the top of my head:
Flickr style: tag "tag with a space" othertag
CSV (LibraryThing, among others) style: tag?,tag with a space,othertag!
The Flickr double-quotes style could be added to the existing regex and by
doing a quick transform from spaces to slug-style hypens (-). The regex
would then be something like:
find_tag_re = re.compile('(?P[-\w]+)|\"(?P[-\w ]+)\"', re.U)
(I added capturing groups to keep the "" quotes out of the returned tag.)
and then with the tags just do a quick tag_name.replace(' ','-')
For the CSV style it would be useful to provide some quick flag to switch
to "real CSV style" and run django's slugify() to clean gunk like
non-alphanumeric characters for the final tag name.
I can flesh this out into a full patch in a few days if there is interest.
I'll probably be writing it for my own use in the near future anyway.
It would also be nice to support "verbose names" for tags where spaces
might look cleaner/nicer or be more preferred as the non-URL display name.
Original issue reported on code.google.com by [email protected]
on 19 May 2007 at 9:23
In revision 57, line 166 of models.py reads:
if len(tags) == 0:
tag = tags[0] # Optimisation for single tag
Assuming the comment is correct, it should read:
if len(tags) == 1:
Because len(), like count/length in so many other languages starts with
one. len(tags) == 0 should probably be an error condition. Because this
"optimization" doesn't get called it doesn't look like it works either.
Original issue reported on code.google.com by [email protected]
on 20 May 2007 at 5:09
The last line of the model code currently reads;
tags = property(_get_tags, _set_tags)
which results in an undefined module error.
It should read;
tags = property('_get_tags', '_set_tags')
which now works perfectly.
Original issue reported on code.google.com by [email protected]
on 19 Jun 2007 at 4:26
Form control for editing tags with an autocomplete
P.S.: I found another project of tagging for Django (for if you need more
ideas to tagging)
http://softwaremaniacs.org/soft/tags/en/
Original issue reported on code.google.com by [email protected]
on 18 Jun 2007 at 8:12
What steps will reproduce the problem?
1. Use tagged_objects template tag in a template per README.txt.
eg. {% tagged_objects foo_tag in blog.Entry as entries %}
2. Load template.
3. TemplateSyntaxError: second argument to tagged_objects tag must be 'in'
What is the expected output? What do you see instead?
Expected to see a rendered template, instead raises TemplateSyntaxError.
What version of the product are you using? On what operating system?
Checked out from svn Apr 9, 2007. Cygwin, Windows XP Pro.
Please provide any additional information below.
Line 61 of tagging_tags.py checks bits[2] != 'for'. Probably should be
bits[2] != 'in'. README.txt (and exception output!) defines syntax using 'in'.
Original issue reported on code.google.com by [email protected]
on 8 Apr 2007 at 1:38
I get TypeError:
in django\template\__init__.py in resolve_variable, line 637
expected string or buffer.
I hunted it down, and it seems that there is some offending code in the
TagsForObjectNode class. You are setting the self.object property, and it
somehow (in my case) the resolve_variable is called again, trying to
resolve a model object, and fails. I have modified the render function to
resolve to a temp variable instead...
def render(self, context):
_object = resolve_variable(self.object, context)
context[self.context_var] = Tag.objects.get_for_object(_object)
return ''
Original issue reported on code.google.com by orestis
on 20 Apr 2007 at 9:13
>>> import re
>>> re.findall('\w+',', , foo , bar , ,baz, , ,')
['foo', 'bar', 'baz']
>>>
Original issue reported on code.google.com by ronny.pfannschmidt
on 8 Mar 2007 at 11:20
Few months ago I posted a snippet on djangosnippets.org website:
http://www.djangosnippets.org/snippets/140/
It think that it could be useful to include it in the template tags
Regards,
Massimo
Original issue reported on code.google.com by [email protected]
on 12 Jun 2007 at 6:10
The attachment file is a patch for django-tagging to surpport non-ascii
tag name. I've tested it with chinese.
Original issue reported on code.google.com by [email protected]
on 6 May 2007 at 12:59
Attachments:
Currently, for a multi-user blogging app, the generated tag cloud comes
from the aggregation of everyone's blog entries. Would it be possible to
somehow add the capability to restrict the tag cloud to a subset of blog
entries (in this example)?
Original issue reported on code.google.com by [email protected]
on 21 Mar 2007 at 1:45
1. Implement an equal assignment algorithm in addition to the current
log-based algorithm - allow the user to choose which is used when
calculating a cloud.
2. Move the cloud calculation function out of the TagManager class - it now
operates on a given lists of tags, so it doesn't really fit there any more.
Original issue reported on code.google.com by jonathan.buchanan
on 16 May 2007 at 11:07
i recently switched from sqlite to psql and got the following errors:
in related_for_model the second group by is missing the tag.name
AND t.id NOT IN (%s)
GROUP BY t.id, t.name
ORDER BY 2 ASC""" % (
and the get_intersection_by_model doesnt work:
Exception Value:
ERROR: syntax error at or near ")" at character 354 SELECT
"blog_blogentry"."id","blog_blogentry"."title","blog_blogentry"."summary","blog_
blogentry"."tags","blog_blogentry"."created"
FROM "blog_blogentry" WHERE ("blog_blogentry"."id" IN ()) ORDER BY
"blog_blogentry"."created" DESC
its only throwing this error when there are no blogentries for the tags.
Original issue reported on code.google.com by [email protected]
on 20 May 2007 at 6:23
this issue was posted in django-users:
http://groups.google.com/group/django-users/browse_thread/thread/a28c1ada9c3f813
3/106c18b58e35f5c0#106c18b58e35f5c0
when fixing this i would suggest to add a is_disabled boolean to disable
unwanted tags posted by users and not have to delete them over and over again.
Original issue reported on code.google.com by [email protected]
on 12 May 2007 at 7:02
What steps will reproduce the problem?
1. Install django-tagging as explained in README.txt
2. add line to import Tag in myproj.myapp.models: from
myproj.tagging.models import Tag
3. myapp disappears from Django admin.
What is the expected output? What do you see instead?
As soon as I add the line "from myproj.tagging.models import Tag" to my
model, that model disappears from the Admin. The funny thing is that
everything works fine from the python shell.
What version of the product are you using? On what operating system?
Dreamhost. Python 2.3.5. Current svn of both Django and django-tagging.
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 19 Mar 2007 at 7:31
I'd like to display a tag cloud on a tag page with tags which have been
used with this tag. Hum, ok not really clear and you need an example:
post1.tags = 'foo bar'
post2.tags = 'bar baz'
post3.tags = 'foo ter'
post4.tags = 'bar ter'
Now, the foo tag page will contain a tag cloud with bar and ter tags. The
bar one with foo, baz and ter, and so one...
Let me know if it's easily feasible, maybe I can help.
Original issue reported on code.google.com by [email protected]
on 26 Apr 2007 at 1:27
Ivan Sagalaev's TagsField (http://softwaremaniacs.org/soft/tags/en/) uses a
little bit of JScript to yield Tag auto-complete. Some form of
auto-complete might be handy to include in this tagging library.
Original issue reported on code.google.com by [email protected]
on 19 May 2007 at 8:39
Any model using django-tagging against the current development trunk of
django now fails with this error:
foo.app: 'module' object has no attribute 'GenericForeignKey'
GenericForeignKey has moved to the contenttypes module as of Django
revision 5172:
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Genericrelations
havemoved
Changing the import fixes it. A try/except import block could handle both
the before and after case.
Original issue reported on code.google.com by [email protected]
on 9 May 2007 at 10:11
Methods which accept a tag currently require a Tag object.
Methods which accept lists of tags currently require a list of Tag objects
or a Tag QuerySet.
Make these methods more flexible and user friendly by also accepting tag
names or lists of tag names, loading the appropriate Tag objects as required.
Original issue reported on code.google.com by jonathan.buchanan
on 16 May 2007 at 11:10
Reported on django-users:
http://groups.google.com/group/django-users/browse_thread/thread/79d079db754bfa6
3
Original issue reported on code.google.com by jonathan.buchanan
on 31 May 2007 at 2:20
What steps will reproduce the problem?
1. Try using get_by_model...
What is the expected output? What do you see instead?
If two tagged items (of the same model) both have two shared tags, and you
search for all objects of that model with the two tags, you'd expect the
two items to be returned, but you get only one.
After investigation, it seems that cursor.fetchall() returns:
((2L,), (3L,)) (where 2L and 3L are the pk ids)
And so cursor.fetchall()[0] dutifully returns
(2L,)
which is wrong. The fix for my situation was
- ids = cursor.fetchall()[0]
+ ids = [row[0] for row in cursor.fetchall()]
Perhaps this was changed in the django version? Perhaps I did something wrong?
Original issue reported on code.google.com by [email protected]
on 13 Apr 2007 at 4:25
Right now it looks like it'd be tricky, if possible at all, to say "given this
model, give me instances
tagged with 'foo' AND 'bar'" -- which is a common use case -- because
TaggedItemManager.get_for_model only accepts a single tag. Accepting a list of
tags would make
the DB query a bit more complicated (it would either turn into a pretty nasty
join, or a 'tag_id IN (list
of ids)', but would make this use case a whole lot simpler.
Original issue reported on code.google.com by [email protected]
on 9 Mar 2007 at 2:56
I think it would be good to have the option of having case insensitive
tags. E.g., convert all tags to lowercase before storing, so that
"Something" and "something" would show as the same tag, which they are.
I understand there might be cases where you would want them to be
different, but for my apps I want them to be treated as the same tag, so
users don't get confused.
Original issue reported on code.google.com by [email protected]
on 14 Jun 2007 at 12:03
What steps will reproduce the problem?
e = Entry.objects.get(pk=12)
e.tags = '中文 语言'
What is the expected output? What do you see instead?
e.tags # output nothing
But it should be "中文 语言".
What version of the product are you using? On what operating system?
svn version, ubuntu system, mysql database.
Please provide any additional information below.
I want to integrate tagging framework into my project. Unfortunately I met
a problem saving non-latin(Chinese) characters tags name in database. If
tags name look like "aa bb cc", they can be parsed perfectly and saved into
tag table respectively. But if tags name are non-latin(Chinese) characters,
there is nothing happend in tag table.
There is a TagField named tags in my Entry model.
I think something wrong with the regex when parsing tags name maybe? or
something about unicode?
Original issue reported on code.google.com by [email protected]
on 1 May 2007 at 3:32
Attached is a new templatetag I've made. I find it useful, maybe it's
useful for anyone else. The patch is attached.
Retrieves a list of tags used for a given Model and stores them in
a context variable.
The model is specified in ``[appname].[modelname]`` format.
If specified it adds a count attribute to each tag. Just add an
extra parameter called ``count``
Example usage::
{% tags_for_model blog.comment as tag_list %}
or
{% tags_for_model blog.comment as tag_list count %}
Original issue reported on code.google.com by [email protected]
on 11 May 2007 at 7:21
Attachments:
I am starting to use your tagging module in a series of projects I am working
on (I ditched my
nascent tagging app because yours does most of the stuff that mine did, and
more stuff that
mine had not yet gotten to.)
One of the big barriers that I am overcoming by adding code to my projects is
dealing with cross
model use of tags.
For example, I have forums which have discussions with have posts in one app. I
have wiki topics
in another app. I have user pages elsewhere. I also have blogs.
All of these have tags. As a matter of fact a lot of them will share tags. I
need common views that
let you see _all_ of the objects (or all of the models) that have a given tag.
Luckily with the generic relations and the simple object structure I can add
this code to a
tagging-support app in my project that lets people view lists of objects that
match a tag so they
can find all the relevant discussions, posts, wiki topics, and blog entries
that cover a specific tag.
Do you have any ideas or plans in this direction? (I am not sure this is an
"Issue" but I do not see
any other way to submit comments on google code.)
Original issue reported on code.google.com by [email protected]
on 30 May 2007 at 11:47
When using tags on a model, it's fairly easy to create a simple interface for
retrieving and setting
them by putting a property on the model:
{{{
def _get_tags(self):
return Tag.objects.get_for_object(self):
def _set_tags(self, tag_list):
Tag.objects.update_tags(self, tag_list)
tags = property(_get_tags, _set_tags)
}}}
So suppose you have a blog entry model with tags, and you add the above to it;
now you could
do:
{{{
e = Entry.objects.get(pk=12)
e.tags # prints the tag list
e.tags = 'foo bar' # now the Entry is tagged with 'foo' and 'bar'.
}}}
(thanks for releasing this, btw -- I was just sitting down to write a tagging
implementation for an
app I'm working on when I saw this app scroll by, and it's already got
everything I wanted!)
Original issue reported on code.google.com by [email protected]
on 6 Mar 2007 at 7:37
`TagManager.update_tags` is using a call to `split` to break up the new tag
list by spaces, but this
can cause problems if a user inputs comma-separated tags. Compatibility with
either type of
separator could be achieved by using `re.split` instead:
{{{
import re
updated_tag_names = [t for t in re.split('[\s,]+', tag_list) if t]
}}}
This also has the advantage of automatically returning an empty list of tag
names if tag_list was
empty, removing the need for the 'if tag_list != None' check.
Original issue reported on code.google.com by [email protected]
on 6 Mar 2007 at 6:37
Off the top of my head, it should be a simple wrapper around object_list
which sets up appropriate QuerySet.
Original issue reported on code.google.com by jonathan.buchanan
on 30 May 2007 at 12:43
It would be nice if django-tagging supported machine tags (e.g.
http://www.flickr.com/groups/api/discuss/72157594497877875/) by including a
namespace field.
Original issue reported on code.google.com by [email protected]
on 2 Apr 2007 at 9:19
So I have not started using this project, but I was curious does
django-tagging was able to keep track of the owners of the tags much like
del.icio.us?
Original issue reported on code.google.com by [email protected]
on 30 Mar 2007 at 4:42
What steps will reproduce the problem?
enter 'tétéphone othertag' in a tag list.
return ['t','t','phone','othertag'] list of tags.
What is the expected output? What do you see instead?
return ['téléphone','othertag'] list of tags.
What version of the product are you using? On what operating system?
a svn version, but didn't update since a few week.
Please provide any additional information below.
my proposition for solve this problem :
change in utils.py :
#find_tag_re = re.compile('[-\w]+')
char_accepted_in_tag = u'œ@àéèùçâäîïôöêëûüÄÂÛÜÎÏÔÖÊË'
find_tag_re = re.compile(u'[-%s\w]+' % char_accepted_in_tag)
change in validators.py :
#tag_list_re = re.compile(r'^[-\w]+(?:(?:,\s|[,\s])[-\w]+)*$' )
char_accepted_in_tag = u'œ@àéèùçâäîïôöêëûüÄÂÛÜÎÏÔÖÊË'
tag_list_re = re.compile(r'^[-%s\w]+(?:(?:,\s|[,\s])[-\w]+)*$' %
char_accepted_in_tag)
change in model.py :
add before TagManager
def decodeall(txt):
try:
return txt.decode('utf-8')
except:
return txt
in TagManager:
#if tag_name not in current_tag_names:
ucurrent_tag_names=map(decodeall,current_tag_names)
if tag_name not in ucurrent_tag_names:
It's work...
but for searching...
I will need to téléphone with entry téléphone or telephone.
(because url didn't accept accent)
then I will peharps need to change the structure.
Original issue reported on code.google.com by [email protected]
on 23 Apr 2007 at 6:32
It would be nice if TagManager.usage_for_model returned a queryset instead
of a list so that code such as
Tag.objects.usage_for_model(Item, counts=True).order_by('-count')
would still work. This used to work in previous revisions.
Original issue reported on code.google.com by [email protected]
on 7 Jun 2007 at 12:07
I tried to be far to clever when I first wrote the tag field.
The end result is that it's currently *very* chatty with the database: doing
something like
Model.objects.all() (on an object with a TagField) causes O(N) database hits
instead of the supposed
O(1).
Attached is a patch that's a lot less clever, but also much more economical
with database hits. It
works just as well, but the minor difference is that now tag changes are only
saved back to the
database when object.save() gets called. I think this is more correct (it makes
TagField behave much
more like a CharField), but it is a difference from the previous behavior.
Original issue reported on code.google.com by [email protected]
on 2 Apr 2007 at 4:25
Currently, `TagManager.update_tags` uses a set for the new tags, but doesn't
check for the
presence of built-in sets (which were only added in Python 2.4).
Compatibility to 2.3 could be achieved by testing for the presence of the
built-in `set` type, and
falling back to importing the `Set` class out of the `sets` module if it's not
found, e.g., by
adding this at the top of `models.py`:
{{{
try:
set
except NameError:
from sets import Set as set
}}}
Original issue reported on code.google.com by [email protected]
on 6 Mar 2007 at 6:33
Would be nice
Original issue reported on code.google.com by [email protected]
on 24 Jun 2007 at 9:19
As of Django changeset 5172, the fields for generic relations now live in
django.contrib.contenttypes.generic instead of django.db.models.
Original issue reported on code.google.com by [email protected]
on 14 May 2007 at 7:11
So I have not started using this project, but I was curious does
django-tagging was able to keep track of the owners of the tags much like
del.icio.us?
Original issue reported on code.google.com by [email protected]
on 30 Mar 2007 at 4:43
in the file tagging.models,
in the function get_intersection_by_model :
ids = cursor.fetchall()[0]
return only the first value for postgres database.
I use this code for patch postgres usage :
resultall = cursor.fetchall()
ids=[]
for i in resultall:
ids.append(i[0])
have a good day.
Xavier Manach. [email protected]
PS : thx for your application.
It's help me a lot (i am noob in django).
Original issue reported on code.google.com by [email protected]
on 22 Mar 2007 at 11:48
I needed to access in a template to the "cloud_for_model" function, so i
added a new template tag in the tagging_tags file.
Isn't this a good thing to add in the next version of the django-tagging app?
Future work is give the list of options in the template, and the template
tag return the correspondent value.
In the attach file is the code i used.
Thanks
Original issue reported on code.google.com by [email protected]
on 22 May 2007 at 4:42
Attachments:
Hi Jonathan,
Congrats on the birth of your child. Thanks for the django-tagging app, it
really is the greatest thing since sliced bread.
One thing that I would like to do with it is the following (and if it's
just something that I should put in my own templatetag, that's fine with
me, I'm only putting this out there in case it can be generalised and be of
use to others): I'd like to be able to get a list of two different kinds
of tagged objects that relate to each other. This is best illustrated by
an example.
If I have a weblog entry with the tag-list: "django tagging buchanan" I'd
like to display related links with one or more of those tags. Ideally, I'd
like a list of links arranged by relevance (so that links that match more
tags are listed first).
I hope I'm being clear :(
Thanks!
Seemant
Original issue reported on code.google.com by [email protected]
on 13 May 2007 at 3:02
What steps will reproduce the problem?
our Entry model uses the TagField like so:
tags = TagField()
Using the python interpreter:
1. from tagging.models import TaggedItem, Tag
2. from myapp.blog.models import Entry
3. post = Entry.objects.get(pk=3)
4. post.tags = 'last monkey marketing'
5. post.tags
'last marketing monkey'
then, when you use the templatetag tags_for_object , the tags seem to
disappear from the TaggedItem table.
What version of the product are you using? On what operating system?
latest SVN export on Centos 4, apache mod_python, mysql
Please provide any additional information below.
if you go to the django admin and view the TaggedItem list, that will also
delete all TaggedItems from the system. The tags remain, but the associations.
Original issue reported on code.google.com by [email protected]
on 3 May 2007 at 10:00
hiho
say i have 1000 tags and limit the result to
tag_cloud = Tag.objects.cloud_for_model(MyModel, steps=4)[:100]
the tagcloud shows tags from letter a to m for example, but it should show
up the 100 most used tags and sort them by name.
i don´t see how i can do this.
Original issue reported on code.google.com by [email protected]
on 16 May 2007 at 11:55
I just noticed that `models.py` imports `urllib`, but doesn't use it; it's
probably safe to remove the
import.
Original issue reported on code.google.com by [email protected]
on 6 Mar 2007 at 6:39
I got the exception when i use the tagged_objects tag.then i found the error:
def do_tagged_objects(parser, token):
if bits[2] != 'for':
is not 'for',is 'in'
Original issue reported on code.google.com by [email protected]
on 30 Apr 2007 at 3:03
And release something for once!
Original issue reported on code.google.com by jonathan.buchanan
on 29 May 2007 at 8:27
What steps will reproduce the problem?
1. Have a model with a slug as a primary key, do not have an id...
2. Add tags = TagField() to the model
3. Witness breakage
What is the expected output? What do you see instead?
Expected to render the template.
Actual:
'MyModel' object has no attribute 'id'
/home/user/Projects/mc/../mc/tagging/models.py in update_tags, line 21
What version of the product are you using? On what operating system?
SVN trunk - 4/4/07
Please provide any additional information below.
If you need anymore information. I'm more than willing to help.
Original issue reported on code.google.com by [email protected]
on 4 Apr 2007 at 7:08
If you attempt to use get_by_model and the tag doesn't exists, it creates
an exception in the cursor. I fixed it w/:
226 tags = get_tag_list(tags)
227 if len(tags) == 1:
228 tag = tags[0] # Optimisation for single tag
229 elif len(tags) == 0:
230 return None
231 else:
232 return self.get_intersection_by_model(Model, tags)
Original issue reported on code.google.com by [email protected]
on 30 Jun 2007 at 9:46
What would have to happen for django-tagging to support Unicode tags?
Original issue reported on code.google.com by [email protected]
on 23 Apr 2007 at 4:18
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.