Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-sshkey
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
70d4e6d2
authored
Jun 21, 2013
by
Scott Duckworth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
define UserKey.validate_unique()
parent
73e7b814
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
sshkey/models.py
+19
-0
No files found.
sshkey/models.py
View file @
70d4e6d2
...
...
@@ -22,3 +22,22 @@ class UserKey(models.Model):
self
.
fingerprint
=
sshkey_fingerprint
(
self
.
key
)
except
Exception
,
e
:
raise
ValidationError
(
'Not a valid SSH key: '
+
str
(
e
))
def
validate_unique
(
self
,
exclude
=
None
):
if
self
.
pk
is
None
:
objects
=
type
(
self
)
.
objects
else
:
objects
=
type
(
self
)
.
objects
.
exclude
(
pk
=
self
.
pk
)
if
exclude
is
None
or
'name'
not
in
exclude
:
if
objects
.
filter
(
user
=
self
.
user
,
name
=
self
.
name
)
.
count
():
raise
ValidationError
({
'name'
:
[
'A key with this name already exists'
]})
if
exclude
is
None
or
'key'
not
in
exclude
:
try
:
other
=
objects
.
get
(
fingerprint
=
self
.
fingerprint
,
key
=
self
.
key
)
if
self
.
user
==
other
.
user
:
message
=
'You already have that key on file (
%
s)'
%
other
.
name
else
:
message
=
'Somebody else already has that key on file'
raise
ValidationError
({
'key'
:
[
message
]})
except
type
(
self
)
.
DoesNotExist
:
pass
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