forked from mpessas/django-tagging
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,538 additions
and
857 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,15 @@ | ||
VERSION = (0, 4, 0, "dev", 1) | ||
""" | ||
Django-tagging | ||
""" | ||
__version__ = '0.4.6' | ||
__license__ = 'BSD License' | ||
|
||
__author__ = 'Jonathan Buchanan' | ||
__author_email__ = '[email protected]' | ||
|
||
__maintainer__ = 'Fantomas42' | ||
__maintainer_email__ = '[email protected]' | ||
|
||
def get_version(): | ||
if VERSION[3] == "final": | ||
return "%s.%s.%s" % (VERSION[0], VERSION[1], VERSION[2]) | ||
elif VERSION[3] == "dev": | ||
if VERSION[2] == 0: | ||
return "%s.%s.%s%s" % (VERSION[0], VERSION[1], VERSION[3], VERSION[4]) | ||
return "%s.%s.%s.%s%s" % (VERSION[0], VERSION[1], VERSION[2], VERSION[3], VERSION[4]) | ||
else: | ||
return "%s.%s.%s%s" % (VERSION[0], VERSION[1], VERSION[2], VERSION[3]) | ||
__url__ = 'https://github.com/Fantomas42/django-tagging' | ||
|
||
|
||
__version__ = get_version() | ||
|
||
|
||
class AlreadyRegistered(Exception): | ||
""" | ||
An attempt was made to register a model more than once. | ||
""" | ||
pass | ||
|
||
|
||
registry = [] | ||
|
||
|
||
def register(model, tag_descriptor_attr='tags', | ||
tagged_item_manager_attr='tagged'): | ||
""" | ||
Sets the given model class up for working with tags. | ||
""" | ||
|
||
from tagging.managers import ModelTaggedItemManager, TagDescriptor | ||
|
||
if model in registry: | ||
raise AlreadyRegistered("The model '%s' has already been " | ||
"registered." % model._meta.object_name) | ||
if hasattr(model, tag_descriptor_attr): | ||
raise AttributeError("'%s' already has an attribute '%s'. You must " | ||
"provide a custom tag_descriptor_attr to register." % ( | ||
model._meta.object_name, | ||
tag_descriptor_attr, | ||
) | ||
) | ||
if hasattr(model, tagged_item_manager_attr): | ||
raise AttributeError("'%s' already has an attribute '%s'. You must " | ||
"provide a custom tagged_item_manager_attr to register." % ( | ||
model._meta.object_name, | ||
tagged_item_manager_attr, | ||
) | ||
) | ||
|
||
# Add tag descriptor | ||
setattr(model, tag_descriptor_attr, TagDescriptor()) | ||
|
||
# Add custom manager | ||
ModelTaggedItemManager().contribute_to_class(model, tagged_item_manager_attr) | ||
|
||
# Finally register in registry | ||
registry.append(model) | ||
default_app_config = 'tagging.apps.TaggingConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
""" | ||
Admin components for tagging. | ||
""" | ||
from django.contrib import admin | ||
from tagging.models import Tag, TaggedItem | ||
|
||
from tagging.models import Tag | ||
from tagging.models import TaggedItem | ||
from tagging.forms import TagAdminForm | ||
|
||
|
||
class TagAdmin(admin.ModelAdmin): | ||
form = TagAdminForm | ||
|
||
|
||
admin.site.register(TaggedItem) | ||
admin.site.register(Tag, TagAdmin) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Apps for tagging. | ||
""" | ||
from django.apps import AppConfig | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
class TaggingConfig(AppConfig): | ||
""" | ||
Config for Tagging application. | ||
""" | ||
name = 'tagging' | ||
label = 'tagging' | ||
verbose_name = _('Tagging') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.db import models | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.AutoField( | ||
verbose_name='ID', serialize=False, | ||
auto_created=True, primary_key=True)), | ||
('name', models.CharField( | ||
unique=True, max_length=50, | ||
verbose_name='name', db_index=True)), | ||
], | ||
options={ | ||
'ordering': ('name',), | ||
'verbose_name': 'tag', | ||
'verbose_name_plural': 'tags', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='TaggedItem', | ||
fields=[ | ||
('id', models.AutoField( | ||
verbose_name='ID', serialize=False, | ||
auto_created=True, primary_key=True)), | ||
('object_id', models.PositiveIntegerField( | ||
verbose_name='object id', db_index=True)), | ||
('content_type', models.ForeignKey( | ||
verbose_name='content type', | ||
on_delete=models.SET_NULL, | ||
to='contenttypes.ContentType')), | ||
('tag', models.ForeignKey( | ||
related_name='items', verbose_name='tag', | ||
on_delete=models.SET_NULL, | ||
to='tagging.Tag')), | ||
], | ||
options={ | ||
'verbose_name': 'tagged item', | ||
'verbose_name_plural': 'tagged items', | ||
}, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='taggeditem', | ||
unique_together=set([('tag', 'content_type', 'object_id')]), | ||
), | ||
] |
Oops, something went wrong.