Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7568a6ae
authored
Jun 08, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark some strings as translatable, and a bunch of unrelated style changes.
parent
1baa050f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
14 deletions
+34
-14
taggit/contrib/suggest/models.py
+19
-7
taggit/contrib/suggest/utils.py
+9
-3
taggit/forms.py
+2
-1
taggit/managers.py
+4
-3
No files found.
taggit/contrib/suggest/models.py
View file @
7568a6ae
...
...
@@ -2,6 +2,7 @@ import re
from
django.core.exceptions
import
ValidationError
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
taggit.models
import
Tag
...
...
@@ -12,7 +13,9 @@ except ImportError:
class
TagKeyword
(
models
.
Model
):
""" Model to associate simple keywords to a Tag """
"""
Model to associate simple keywords to a Tag
"""
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'keywords'
)
keyword
=
models
.
CharField
(
max_length
=
30
)
stem
=
models
.
CharField
(
max_length
=
30
)
...
...
@@ -21,7 +24,9 @@ class TagKeyword(models.Model):
return
"Keyword '
%
s' for Tag '
%
s'"
%
(
self
.
keyword
,
self
.
tag
.
name
)
def
save
(
self
,
*
args
,
**
kwargs
):
""" Stem the keyword on save if they have PyStemmer """
"""
Stem the keyword on save if they have PyStemmer
"""
language
=
kwargs
.
pop
(
'stemmer-language'
,
'english'
)
if
not
self
.
pk
and
not
self
.
stem
and
Stemmer
:
stemmer
=
Stemmer
.
Stemmer
(
language
)
...
...
@@ -30,21 +35,26 @@ class TagKeyword(models.Model):
def
validate_regex
(
value
):
""" Make sure we have a valid regular expression """
"""
Make sure we have a valid regular expression
"""
try
:
re
.
compile
(
value
)
except
Exception
:
# TODO: more restrictive in the exceptions
raise
ValidationError
(
'Please enter a valid regular expression'
)
class
TagRegex
(
models
.
Model
):
""" Model to associate regular expressions with a Tag """
"""
Model to associate regular expressions with a Tag
"""
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'regexes'
)
name
=
models
.
CharField
(
max_length
=
30
)
regex
=
models
.
CharField
(
max_length
=
250
,
validators
=
[
validate_regex
],
help_text
=
(
'Enter a valid Regular Expression. To make it '
help_text
=
_
(
'Enter a valid Regular Expression. To make it '
'case-insensitive include "(?i)" in your expression.'
)
)
...
...
@@ -52,6 +62,8 @@ class TagRegex(models.Model):
return
self
.
name
def
save
(
self
,
*
args
,
**
kwargs
):
""" Make sure to validate """
"""
Make sure to validate
"""
self
.
full_clean
()
super
(
TagRegex
,
self
)
.
save
(
*
args
,
**
kwargs
)
super
(
TagRegex
,
self
)
.
save
(
*
args
,
**
kwargs
)
taggit/contrib/suggest/utils.py
View file @
7568a6ae
...
...
@@ -7,7 +7,9 @@ from taggit.models import Tag
def
_suggest_keywords
(
content
):
""" Suggest by keywords """
"""
Suggest by keywords
"""
suggested_keywords
=
set
()
keywords
=
TagKeyword
.
objects
.
all
()
...
...
@@ -22,7 +24,9 @@ def _suggest_keywords(content):
return
suggested_keywords
def
_suggest_regexes
(
content
):
""" Suggest by regular expressions """
"""
Suggest by regular expressions
"""
# Grab all regular expressions and compile them
suggested_regexes
=
set
()
regex_keywords
=
TagRegex
.
objects
.
all
()
...
...
@@ -35,7 +39,9 @@ def _suggest_regexes(content):
return
suggested_regexes
def
suggest_tags
(
content
):
""" Suggest tags based on text content """
"""
Suggest tags based on text content
"""
suggested_keywords
=
_suggest_keywords
(
content
)
suggested_regexes
=
_suggest_regexes
(
content
)
suggested_tag_ids
=
suggested_keywords
|
suggested_regexes
...
...
taggit/forms.py
View file @
7568a6ae
from
django
import
forms
from
django.utils.translation
import
ugettext
as
_
from
taggit.utils
import
parse_tags
,
edit_string_for_tags
...
...
@@ -16,4 +17,4 @@ class TagField(forms.CharField):
try
:
return
parse_tags
(
value
)
except
ValueError
:
raise
forms
.
ValidationError
(
"Please provide a comma-separated list of tags."
)
raise
forms
.
ValidationError
(
_
(
"Please provide a comma-separated list of tags."
)
)
taggit/managers.py
View file @
7568a6ae
...
...
@@ -5,6 +5,7 @@ from django.db import models
from
django.db.models.fields.related
import
ManyToManyRel
from
django.db.models.related
import
RelatedObject
from
django.db.models.query_utils
import
QueryWrapper
from
django.utils.translation
import
ugettext_lazy
as
_
from
taggit.forms
import
TagField
from
taggit.models
import
Tag
,
TaggedItem
...
...
@@ -37,7 +38,7 @@ class TaggableRel(ManyToManyRel):
class
TaggableManager
(
object
):
def
__init__
(
self
,
verbose_name
=
"Tags"
,
through
=
None
):
def
__init__
(
self
,
verbose_name
=
_
(
"Tags"
)
,
through
=
None
):
self
.
use_gfk
=
through
is
None
self
.
through
=
through
or
TaggedItem
self
.
rel
=
TaggableRel
(
to
=
self
.
through
)
...
...
@@ -97,8 +98,8 @@ class TaggableManager(object):
def
formfield
(
self
,
form_class
=
TagField
,
**
kwargs
):
defaults
=
{
"label"
:
"Tags"
,
"help_text"
:
"A comma-separated list of tags."
"label"
:
_
(
"Tags"
)
,
"help_text"
:
_
(
"A comma-separated list of tags."
)
}
defaults
.
update
(
kwargs
)
return
form_class
(
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment