Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TIC-Desk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Teckids
TIC-Desk
Commits
3ae05161
Verified
Commit
3ae05161
authored
7 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Allow more flexible retrieval of image paths.
parent
3a88c4b0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ticdesk_account/models.py
+23
-11
23 additions, 11 deletions
ticdesk_account/models.py
with
23 additions
and
11 deletions
ticdesk_account/models.py
+
23
−
11
View file @
3ae05161
...
...
@@ -42,25 +42,37 @@ class TeckidsLdapMixin(object):
return
objects
def
get_image_
u
rl
(
self
,
field
=
'
jpeg_photo
'
,
fallback
=
None
):
if
getattr
(
self
,
field
):
entry_dir
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'
ticdesk
'
,
'
ldap
'
,
md5
(
self
.
dn
.
encode
(
"
utf-8
"
)).
hexdigest
())
if
not
os
.
path
.
isdir
(
entry_dir
):
os
.
makedirs
(
entry_dir
)
def
get_image_r
e
l
(
self
,
field
=
'
jpeg_photo
'
,
fallback
=
None
):
entry_dir
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
'
ticdesk
'
,
'
ldap
'
,
md5
(
self
.
dn
.
encode
(
"
utf-8
"
)).
hexdigest
())
if
not
os
.
path
.
isdir
(
entry_dir
):
os
.
makedirs
(
entry_dir
)
filename
=
'
%s.jpg
'
%
os
.
path
.
join
(
entry_dir
,
md5
(
field
.
encode
(
"
utf-8
"
)).
hexdigest
())
with
open
(
filename
,
'
wb
'
)
as
image_file
:
image_file
.
write
(
getattr
(
self
,
field
))
filename
=
'
%s.jpg
'
%
os
.
path
.
join
(
entry_dir
,
md5
(
field
.
encode
(
"
utf-8
"
)).
hexdigest
())
return
'
%s%s/%s/%s/%s.jpg
'
%
(
settings
.
MEDIA_URL
,
'
ticdesk
'
,
'
ldap
'
,
md5
(
self
.
dn
.
encode
(
"
utf-8
"
)).
hexdigest
(),
md5
(
field
.
encode
(
"
utf-8
"
)).
hexdigest
())
if
not
getattr
(
self
,
field
):
else
:
if
fallback
is
None
:
fallback
=
'
%s%s
'
%
(
settings
.
STATIC_URL
,
'
people.jpg
'
)
return
fallback
fallback
=
'
%s%s
'
%
(
settings
.
STATIC_ROOT
,
'
people.jpg
'
)
with
open
(
filename
,
'
wb
'
)
as
image_file
,
open
(
fallback
,
'
rb
'
)
as
fallback_file
:
image_file
.
write
(
fallback_file
.
read
())
return
'
%s/%s/%s/%s.jpg
'
%
(
'
ticdesk
'
,
'
ldap
'
,
md5
(
self
.
dn
.
encode
(
"
utf-8
"
)).
hexdigest
(),
md5
(
field
.
encode
(
"
utf-8
"
)).
hexdigest
())
def
get_image_url
(
self
,
field
=
'
jpeg_photo
'
,
fallback
=
None
):
return
'
%s%s
'
%
(
settings
.
MEDIA_URL
,
self
.
get_image_rel
(
field
,
fallback
))
def
get_image_path
(
self
,
field
=
'
jpeg_photo
'
,
fallback
=
None
):
return
'
%s%s
'
%
(
settings
.
MEDIA_ROOT
,
self
.
get_image_rel
(
field
,
fallback
))
def
__getattr__
(
self
,
attr
):
if
attr
.
endswith
(
'
__url
'
):
return
self
.
get_image_url
(
attr
[:
-
5
])
elif
attr
.
endswith
(
'
__path
'
):
return
self
.
get_image_path
(
attr
[:
-
6
])
elif
attr
.
endswith
(
'
__rel
'
):
return
self
.
get_image_rel
(
attr
[:
-
5
])
class
TeckidsGroup
(
ldapdb
.
models
.
Model
,
TeckidsLdapMixin
):
class
Meta
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment