Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyOTRS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Som Connexió
OTRS
PyOTRS
Commits
40ddff9f
Commit
40ddff9f
authored
8 years ago
by
Robert Habermann
Browse files
Options
Downloads
Patches
Plain Diff
add parsing and repr for Attachments
parent
0341e3dc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+2
-1
2 additions, 1 deletion
README.md
pyotrs/lib.py
+80
-34
80 additions, 34 deletions
pyotrs/lib.py
with
82 additions
and
35 deletions
README.md
+
2
−
1
View file @
40ddff9f
...
...
@@ -29,11 +29,12 @@ True
u'2010080210123456'
>>> my_ticket.Title
u'Welcome to OTRS!'
>>> my_ticket.to_dct() # Show complete ticket
>>> my_article = Article({"Subject": "Subj", "Body": "New Body"})
>>> client.ticket_update(1, article=my_article)
True
>> client.ticket_get_by_id(1,
all_
articles=1
)
>> client.ticket_get_by_id(1, articles=1
, attachments=1) # include Articles and Attachments
```
## Full Docs
...
...
This diff is collapsed.
Click to expand it.
pyotrs/lib.py
+
80
−
34
View file @
40ddff9f
...
...
@@ -100,12 +100,40 @@ class Article(object):
for
key
,
value
in
dct
.
items
():
self
.
__dict__
=
dct
self
.
list_attachments
=
self
.
_parse_attachments
()
self
.
list_dynamic_fields
=
self
.
_parse_dynamic_fields
()
def
__repr__
(
self
):
if
hasattr
(
self
,
'
ArticleID
'
):
return
"
<{0}: {1}>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
ArticleID
)
_len
=
len
(
self
.
list_attachments
)
if
_len
==
0
:
return
"
<ArticleID: {1}>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
ArticleID
)
elif
_len
==
1
:
return
"
<ArticleID: {1} (1 Attachment)>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
ArticleID
)
else
:
return
"
<ArticleID}: {1} ({2} Attachments)>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
ArticleID
,
_len
)
else
:
return
"
<{0}>
"
.
format
(
self
.
__class__
.
__name__
)
def
_parse_attachments
(
self
):
if
hasattr
(
self
,
'
Attachment
'
):
lst
=
[
Attachment
(
item
)
for
item
in
self
.
Attachment
]
delattr
(
self
,
'
Attachment
'
)
return
lst
else
:
return
[]
def
_parse_dynamic_fields
(
self
):
"""
Articles have DynamicFields too
"""
if
hasattr
(
self
,
'
DynamicField
'
):
lst
=
[
DynamicField
.
from_dct
(
item
)
for
item
in
self
.
DynamicField
]
delattr
(
self
,
'
DynamicField
'
)
return
lst
else
:
return
[]
@classmethod
def
_dummy
(
cls
):
"""
dummy data (for testing)
...
...
@@ -163,13 +191,14 @@ class Article(object):
class
Attachment
(
object
):
"""
PyOTRS Attachment class
"""
def
__init__
(
self
,
Content
=
None
,
ContentType
=
None
,
Filename
=
None
):
self
.
Content
=
Content
# base64 encoded
self
.
ContentType
=
ContentType
self
.
Filename
=
Filename
def
__init__
(
self
,
dct
):
self
.
__dict__
=
dct
def
__repr__
(
self
):
return
"
<{0}: {1}>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
Filename
)
if
hasattr
(
self
,
'
Filename
'
):
return
"
<{0}: {1}>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
Filename
)
else
:
return
"
<{0}>
"
.
format
(
self
.
__class__
.
__name__
)
def
to_dct
(
self
):
"""
represent AttachmentList and related Attachment objects as dict
...
...
@@ -179,6 +208,16 @@ class Attachment(object):
"""
return
self
.
__dict__
@classmethod
def
create_basic
(
cls
,
Content
=
None
,
ContentType
=
None
,
Filename
=
None
):
cls
.
Content
=
Content
# base64 encoded
cls
.
ContentType
=
ContentType
cls
.
Filename
=
Filename
return
Attachment
({
'
Content
'
:
Content
,
'
ContentType
'
:
ContentType
,
'
Filename
'
:
Filename
})
@classmethod
def
_dummy
(
cls
):
"""
dummy data (for testing)
...
...
@@ -186,7 +225,7 @@ class Attachment(object):
Returns:
"""
return
Attachment
(
"
YmFyCg==
"
,
"
text/plain
"
,
"
dümmy.txt
"
)
return
Attachment
.
create_basic
(
"
YmFyCg==
"
,
"
text/plain
"
,
"
dümmy.txt
"
)
class
DynamicField
(
object
):
...
...
@@ -255,7 +294,6 @@ class Ticket(object):
self
.
__dict__
=
dct
self
.
list_articles
=
self
.
_parse_articles
()
self
.
list_attachments
=
self
.
_parse_attachments
()
self
.
list_dynamic_field
=
self
.
_parse_dynamic_fields
()
def
__repr__
(
self
):
...
...
@@ -266,19 +304,17 @@ class Ticket(object):
def
_parse_articles
(
self
):
if
hasattr
(
self
,
'
Article
'
):
return
[
Article
(
item
)
for
item
in
self
.
Article
]
else
:
return
[]
def
_parse_attachments
(
self
):
if
hasattr
(
self
,
'
Attachment
'
):
return
[
Attachment
(
item
)
for
item
in
self
.
Attachment
]
lst
=
[
Article
(
item
)
for
item
in
self
.
Article
]
delattr
(
self
,
'
Article
'
)
return
lst
else
:
return
[]
def
_parse_dynamic_fields
(
self
):
if
hasattr
(
self
,
'
DynamicField
'
):
return
[
DynamicField
.
from_dct
(
item
)
for
item
in
self
.
DynamicField
]
lst
=
[
DynamicField
.
from_dct
(
item
)
for
item
in
self
.
DynamicField
]
delattr
(
self
,
'
DynamicField
'
)
return
lst
else
:
return
[]
...
...
@@ -795,16 +831,18 @@ class Client(object):
def
ticket_get_by_id
(
self
,
ticket_id
,
dynamic_fields
=
True
,
articles
=
False
):
articles
=
False
,
attachments
=
False
,
dynamic_fields
=
True
):
"""
ticket_get_by_id
Args:
ticket_id (int): Integer value of a Ticket ID
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
attachments (bool): will request OTRS to include attachments (*default: False*)
articles (bool): will request OTRS to include all
Articles (+default: False*)
Articles (*default: False*)
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
Returns:
bool: **True** if successful, otherwise **False**
...
...
@@ -817,6 +855,7 @@ class Client(object):
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
TicketID
"
:
"
{}
"
.
format
(
ticket_id
),
"
AllArticles
"
:
int
(
articles
),
"
Attachments
"
:
int
(
attachments
),
"
DynamicFields
"
:
int
(
dynamic_fields
)
}
...
...
@@ -824,16 +863,18 @@ class Client(object):
def
ticket_get_by_ids
(
self
,
ticket_id_list
,
dynamic_fields
=
True
,
articles
=
False
):
articles
=
False
,
attachments
=
False
,
dynamic_fields
=
True
):
"""
ticket_get_by_ids
Args:
ticket_id_list (list): List of Integer value
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
attachments (bool): will request OTRS to include attachments (*default: False*)
articles (bool): will request OTRS to include all
Articles (*default: False*)
Articles (*default: False*)
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
Returns:
bool: **True** if successful, otherwise **False**
...
...
@@ -846,6 +887,7 @@ class Client(object):
"
SessionID
"
:
self
.
session_id_store
.
value
,
"
TicketID
"
:
'
,
'
.
join
([
str
(
item
)
for
item
in
ticket_id_list
]),
"
AllArticles
"
:
int
(
articles
),
"
Attachments
"
:
int
(
attachments
),
"
DynamicFields
"
:
int
(
dynamic_fields
)
}
...
...
@@ -853,16 +895,20 @@ class Client(object):
def
ticket_get_by_number
(
self
,
ticket_number
,
dynamic_fields
=
True
,
articles
=
False
):
articles
=
False
,
attachments
=
False
,
dynamic_fields
=
True
):
"""
ticket_get_by_number
Args:
attachments:
ticket_number (unicode): Integer value of a Ticket ID
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
attachments (bool): will request OTRS to include attachments (*default: False*)
articles (bool): will request OTRS to include all
Articles (*default: False*)
dynamic_fields (bool): will request OTRS to include all
Dynamic Fields (*default: True*)
Returns:
bool: **True** if successful, otherwise **False**
...
...
@@ -877,8 +923,9 @@ class Client(object):
elif
len
(
result_list
)
==
1
:
tid
=
result_list
[
0
]
return
self
.
ticket_get_by_id
(
tid
,
dynamic_fields
=
dynamic_fields
,
articles
=
articles
)
articles
=
articles
,
attachments
=
attachments
,
dynamic_fields
=
dynamic_fields
)
else
:
raise
TicketSearchNumberMultipleResults
(
"
Found more that one result for
"
"
Ticket Number: {0}
"
.
format
(
ticket_number
))
...
...
@@ -1232,8 +1279,7 @@ class Client(object):
# for operation TicketGet: parse result list into Ticket object list
if
self
.
operation
==
"
TicketGet
"
:
for
item
in
self
.
response_json
[
'
Ticket
'
]:
self
.
list_ticket_get_results
.
append
(
Ticket
(
item
))
self
.
list_ticket_get_results
=
[
Ticket
(
item
)
for
item
in
self
.
response_json
[
'
Ticket
'
]]
return
True
...
...
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