本文整理汇总了Python中helpdesk.models.Ticket类的典型用法代码示例。如果您正苦于以下问题:Python Ticket类的具体用法?Python Ticket怎么用?Python Ticket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ticket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
q = Queue(title='Q1', slug='q1')
q.save()
t = Ticket(title='Test Ticket', submitter_email='[email protected]')
t.queue = q
t.save()
self.ticket = t
示例2: view_ticket
def view_ticket(request):
ticket_req = request.GET.get('ticket', '')
ticket = False
email = request.GET.get('email', '')
error_message = ''
if ticket_req and email:
queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req)
try:
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email)
except:
ticket = False
error_message = _('Invalid ticket ID or e-mail address. Please try again.')
if ticket:
if request.user.is_staff:
redirect_url = reverse('helpdesk_view', args=[ticket_id])
if 'close' in request.GET:
redirect_url += '?close'
return HttpResponseRedirect(redirect_url)
if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
from helpdesk.views.staff import update_ticket
# Trick the update_ticket() view into thinking it's being called with
# a valid POST.
request.POST = {
'new_status': Ticket.CLOSED_STATUS,
'public': 1,
'title': ticket.title,
'comment': _('Submitter accepted resolution and closed ticket'),
}
if ticket.assigned_to:
request.POST['owner'] = ticket.assigned_to.id
request.GET = {}
return update_ticket(request, ticket_id, public=True)
# redirect user back to this ticket if possible.
redirect_url = ''
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
redirect_url = reverse('helpdesk_view', args=[ticket_id])
return render(request, 'helpdesk/public_view_ticket.html',
{
'ticket': ticket,
'helpdesk_settings': helpdesk_settings,
'next': redirect_url,
})
return render(request, template_name='helpdesk/public_view_form.html',
context = {
'ticket': ticket,
'email': email,
'error_message': error_message,
'helpdesk_settings': helpdesk_settings,
})
示例3: save
def save(self, user):
"""
Writes and returns a Ticket() object
"""
q = Queue.objects.get(id=int(self.cleaned_data['queue']))
t = Ticket( title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
created = timezone.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
error_msg = self.cleaned_data['error_msg'],
priority = self.cleaned_data['priority'],
type = self.cleaned_data['type'],
due_date = self.cleaned_data['due_date'],
)
t.assigned_to = None
if self.cleaned_data['assigned_to']:
try:
u = User.objects.get(id=self.cleaned_data['assigned_to'])
t.assigned_to = u
except User.DoesNotExist:
pass
t.save()
for field, value in self.cleaned_data.items():
if field.startswith('custom_'):
field_name = field.replace('custom_', '', 1)
customfield = CustomField.objects.get(name=field_name)
cfv = TicketCustomFieldValue(ticket=t,
field=customfield,
value=value)
cfv.save()
ticket = t
user = None
try:
user = t.assigned_to
except Exception, e:
pass
示例4: handle_messages
def handle_messages(self, imbox, project, email=None, assignee=None):
logger.info("--- Started processing emails ---")
unread_messages = imbox.messages(unread=True, folder='INBOX', sent_to=email or project.email)
for uid, message in unread_messages:
try:
subject = getattr(message, 'subject', 'Email ticket')
logger.info("Got message %s: %s" % (uid, subject))
if SETTINGS['ignore_autoreply'] and self._is_autoreply(message):
logger.info(' Message is auto-submitted, skipping')
if SETTINGS['mark_seen']:
imbox.mark_seen(uid)
continue
if Ticket.objects.filter(message_id=uid).exists() or Comment.objects.filter(message_id=uid).exists():
logger.info(' Message already exists, skipping')
if SETTINGS['mark_seen']:
imbox.mark_seen(uid)
continue
try:
body = message.body['html'][0]
except IndexError:
try:
body = message.body['plain'][0]
except IndexError:
body = ''
initial = self._get_initial_issue(message)
if initial is None:
ticket = Ticket.create(
title=subject[:255],
body=body,
customer=message.sent_from[0]['email'],
message_id=uid,
assignee=assignee or project.default_assignee,
project=project
)
logger.info(' Created new ticket')
self._create_attachments(message.attachments, ticket)
else:
comment = Comment.objects.create(
body=body,
author=None,
message_id=uid,
ticket=initial
)
self._create_attachments(message.attachments, comment)
logger.info(' Added comment to ticket')
if SETTINGS['mark_seen']:
imbox.mark_seen(uid)
except Exception:
logger.exception(' Error while retrieving email %s' % uid)
logger.info("--- Finished processing emails ---")
示例5: form_valid
def form_valid(self, form):
if not self.attachment_formset.is_valid():
return self.render_to_response(self.get_context_data())
data = form.cleaned_data
comment = data.pop('comment')
ticket = Ticket.create(body='This ticket was created by [user:%d]' % self.request.user.pk,
message_id='ticket-%d' % time.mktime(now().timetuple()),
author=self.request.user,
**data)
reply = Comment.objects.create(ticket=ticket, body=comment, author=self.request.user)
self.attachment_formset.instance = reply
self.attachment_formset.save()
new_answer.send(sender=Comment, ticket=ticket, answer=reply)
return HttpResponseRedirect(reverse('helpdesk_home'))
示例6: get_object
def get_object(self):
# For GET method and we have a decode code
if self.kwargs.get('code'):
ticket_id, email = Ticket.decode(self.kwargs['code'].encode("utf-8"))
elif self.request.GET.get('email') and self.request.GET.get('ticket'):
parts = self.request.GET['ticket'].split('-')
queue = '-'.join(parts[0:-1])
ticket_id = parts[-1]
email = self.request.GET.get('email')
# ToDo
# I think its not really right to check queue cause moderator can move ticket to different queue
return Ticket.objects.get(
id=ticket_id,
#queue__slug__iexact=queue,
submitter_email__iexact=email
)
示例7: save
def save(self, user):
"""
Writes and returns a Ticket() object
"""
q = Queue.objects.get(id=int(self.cleaned_data["queue"]))
t = Ticket(
title=self.cleaned_data["title"],
submitter_email=self.cleaned_data["submitter_email"],
created=datetime.now(),
status=Ticket.OPEN_STATUS,
queue=q,
description=self.cleaned_data["body"],
priority=self.cleaned_data["priority"],
due_date=self.cleaned_data["due_date"],
)
if HAS_TAG_SUPPORT:
t.tags = self.cleaned_data["tags"]
if self.cleaned_data["assigned_to"]:
try:
u = User.objects.get(id=self.cleaned_data["assigned_to"])
t.assigned_to = u
except User.DoesNotExist:
t.assigned_to = None
t.save()
for field, value in self.cleaned_data.items():
if field.startswith("custom_"):
field_name = field.replace("custom_", "")
customfield = CustomField.objects.get(name=field_name)
cfv = TicketCustomFieldValue(ticket=t, field=customfield, value=value)
cfv.save()
f = FollowUp(
ticket=t,
title=_("Ticket Opened"),
date=datetime.now(),
public=True,
comment=self.cleaned_data["body"],
user=user,
)
if self.cleaned_data["assigned_to"]:
f.title = _("Ticket Opened & Assigned to %(name)s") % {"name": t.get_assigned_to}
f.save()
files = []
if self.cleaned_data["attachment"]:
import mimetypes
file = self.cleaned_data["attachment"]
filename = file.name.replace(" ", "_")
a = Attachment(
followup=f,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or "application/octet-stream",
size=file.size,
)
a.file.save(file.name, file, save=False)
a.save()
if file.size < getattr(settings, "MAX_EMAIL_ATTACHMENT_SIZE", 512000):
# Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
files.append(a.file.path)
context = safe_template_context(t)
context["comment"] = f.comment
messages_sent_to = []
if t.submitter_email:
send_templated_mail(
"newticket_submitter",
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if (
t.assigned_to
and t.assigned_to != user
and getattr(t.assigned_to.usersettings.settings, "email_on_ticket_assign", False)
and t.assigned_to.email
and t.assigned_to.email not in messages_sent_to
):
send_templated_mail(
"assigned_owner",
context,
recipients=t.assigned_to.email,
sender=q.from_address,
fail_silently=True,
files=files,
)
#.........这里部分代码省略.........
示例8: save
def save(self, user):
"""
Writes and returns a Ticket() object
"""
q = self.cleaned_data['queue']
t = Ticket( title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
account = self.cleaned_data['account'],
created = datetime.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
priority = self.cleaned_data['priority'],
owner = self.cleaned_data['owner']
)
if HAS_TAG_SUPPORT:
t.tags = self.cleaned_data['tags']
if self.cleaned_data['assigned_to']:
try:
t.assigned_to = self.cleaned_data['assigned_to']
except User.DoesNotExist:
t.assigned_to = None
t.save()
f = FollowUp( ticket = t,
title = _('Ticket Opened'),
date = datetime.now(),
public = False,
comment = self.cleaned_data['body'],
systemuser = user.account,
)
if self.cleaned_data['assigned_to']:
f.title = _('Ticket Opened & Assigned to %(name)s') % {
'name': t.get_assigned_to
}
f.save()
files = []
if self.cleaned_data['attachment']:
import mimetypes
file = self.cleaned_data['attachment']
filename = file.name.replace(' ', '_')
a = Attachment(
followup=f,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or 'application/octet-stream',
size=file.size,
)
a.file.save(file.name, file, save=False)
a.save()
if file.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000):
# Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
files.append(a.file.path)
context = {
'ticket': t,
'queue': q,
'comment': f.comment,
}
messages_sent_to = []
if t.submitter_email:
send_templated_mail(
'newticket_owner',
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
#FIX USERSETTINGS
#=======================================================================
# if t.assigned_to and t.assigned_to != user and getattr(t.assigned_to.usersettings.settings, 'email_on_ticket_assign', False) and t.assigned_to.email and t.assigned_to.email not in messages_sent_to:
# send_templated_mail(
# 'assigned_to',
# context,
# recipients=t.assigned_to.email,
# sender=q.from_address,
# fail_silently=True,
# files=files,
# )
# messages_sent_to.append(t.assigned_to.email)
#=======================================================================
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
recipients=q.new_ticket_cc,
sender=q.from_address,
#.........这里部分代码省略.........
示例9: ticket_from_message
def ticket_from_message(message, queue, quiet):
# 'message' must be an RFC822 formatted message.
msg = message
message = email.message_from_string(msg)
subject = message.get('subject', _('Created from e-mail'))
subject = decode_mail_headers(decodeUnknown(message.get_charset(), subject))
subject = subject.replace("Re: ", "").replace("Fw: ", "").replace("RE: ", "").replace("FW: ", "").strip()
sender = message.get('from', _('Unknown Sender'))
sender = decode_mail_headers(decodeUnknown(message.get_charset(), sender))
sender_name = parseaddr(sender)[0]
sender_email = parseaddr(sender)[1]
body_plain, body_html = '', ''
for ignore in IgnoreEmail.objects.filter(Q(queues=queue) | Q(queues__isnull=True)):
if ignore.test(sender_email):
if ignore.keep_in_mailbox:
# By returning 'False' the message will be kept in the mailbox,
# and the 'True' will cause the message to be deleted.
return False
return True
matchobj = re.match(r"^\[(?P<queue>[-A-Za-z0-9]+)-(?P<id>\d+)\]", subject)
if matchobj:
# This is a reply or forward.
ticket = matchobj.group('id')
else:
ticket = None
counter = 0
files = []
for part in message.walk():
if part.get_content_maintype() == 'multipart':
continue
name = part.get_param("name")
if name:
name = collapse_rfc2231_value(name)
if part.get_content_maintype() == 'text' and name == None:
if part.get_content_subtype() == 'plain':
body_plain = decodeUnknown(part.get_content_charset(), part.get_payload(decode=True))
else:
body_html = part.get_payload(decode=True)
else:
if not name:
ext = mimetypes.guess_extension(part.get_content_type())
name = "part-%i%s" % (counter, ext)
files.append({
'filename': name,
'content': part.get_payload(decode=True),
'type': part.get_content_type()},
)
counter += 1
if body_plain:
body = body_plain
else:
body = _('No plain-text email body available. Please see attachment email_html_body.html.')
if body_html:
files.append({
'filename': _("email_html_body.html"),
'content': body_html,
'type': 'text/html',
})
now = datetime.now()
if ticket:
try:
t = Ticket.objects.get(id=ticket)
new = False
except Ticket.DoesNotExist:
ticket = None
priority = 3
smtp_priority = message.get('priority', '')
smtp_importance = message.get('importance', '')
high_priority_types = ('high', 'important', '1', 'urgent')
if smtp_priority in high_priority_types or smtp_importance in high_priority_types:
priority = 2
update = ''
if ticket == None:
t = Ticket(
title=subject,
queue=queue,
submitter_name=sender_name,
submitter_email=sender_email,
created=now,
description=body,
#.........这里部分代码省略.........
示例10: save
def save(self):
"""
Writes and returns a Ticket() object
"""
q = Queue.objects.get(title = 'public')
t = Ticket(
title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
created = timezone.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
priority = 3,
due_date = None,
)
t.save()
for field, value in self.cleaned_data.items():
if field.startswith('custom_'):
field_name = field.replace('custom_', '')
customfield = CustomField.objects.get(name=field_name)
cfv = TicketCustomFieldValue(ticket=t,
field=customfield,
value=value)
cfv.save()
f = FollowUp(
ticket = t,
title = _('Ticket Opened Via Web'),
date = timezone.now(),
public = True,
comment = self.cleaned_data['body'],
)
f.save()
files = []
context = safe_template_context(t)
messages_sent_to = []
send_templated_mail(
'newticket_submitter',
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
recipients=q.new_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(q.new_ticket_cc)
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc and q.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
recipients=q.updated_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
return t
示例11: ticket_from_message
def ticket_from_message(message, queue, logger):
# 'message' must be an RFC822 formatted message.
msg = message
message = email.message_from_string(msg)
subject = message.get('subject', _('Created from e-mail'))
subject = decode_mail_headers(decodeUnknown(message.get_charset(), subject))
for affix in STRIPPED_SUBJECT_STRINGS:
subject = subject.replace(affix, "")
subject = subject.strip()
sender = message.get('from', _('Unknown Sender'))
sender = decode_mail_headers(decodeUnknown(message.get_charset(), sender))
sender_email = parseaddr(sender)[1]
body_plain, body_html = '', ''
for ignore in IgnoreEmail.objects.filter(Q(queues=queue) | Q(queues__isnull=True)):
if ignore.test(sender_email):
if ignore.keep_in_mailbox:
# By returning 'False' the message will be kept in the mailbox,
# and the 'True' will cause the message to be deleted.
return False
return True
matchobj = re.match(r".*\[" + queue.slug + "-(?P<id>\d+)\]", subject)
if matchobj:
# This is a reply or forward.
ticket = matchobj.group('id')
logger.info("Matched tracking ID %s-%s" % (queue.slug, ticket))
else:
logger.info("No tracking ID matched.")
ticket = None
counter = 0
files = []
for part in message.walk():
if part.get_content_maintype() == 'multipart':
continue
name = part.get_param("name")
if name:
name = collapse_rfc2231_value(name)
if part.get_content_maintype() == 'text' and name is None:
if part.get_content_subtype() == 'plain':
body_plain = EmailReplyParser.parse_reply(
decodeUnknown(part.get_content_charset(), part.get_payload(decode=True)))
logger.debug("Discovered plain text MIME part")
else:
body_html = part.get_payload(decode=True)
logger.debug("Discovered HTML MIME part")
else:
if not name:
ext = mimetypes.guess_extension(part.get_content_type())
name = "part-%i%s" % (counter, ext)
files.append({
'filename': name,
'content': part.get_payload(decode=True),
'type': part.get_content_type()},
)
logger.debug("Found MIME attachment %s" % name)
counter += 1
if body_plain:
body = body_plain
else:
body = _('No plain-text email body available. Please see attachment "email_html_body.html".')
if body_html:
files.append({
'filename': _("email_html_body.html"),
'content': body_html,
'type': 'text/html',
})
now = timezone.now()
if ticket:
try:
t = Ticket.objects.get(id=ticket)
new = False
logger.info("Found existing ticket with Tracking ID %s-%s" % (t.queue.slug, t.id))
except Ticket.DoesNotExist:
logger.info("Tracking ID %s-%s not associated with existing ticket. Creating new ticket." % (queue.slug, ticket))
ticket = None
priority = 3
smtp_priority = message.get('priority', '')
smtp_importance = message.get('importance', '')
high_priority_types = ('high', 'important', '1', 'urgent')
if smtp_priority in high_priority_types or smtp_importance in high_priority_types:
priority = 2
#.........这里部分代码省略.........
示例12: ticket_from_message
#.........这里部分代码省略.........
else:
if not name:
ext = mimetypes.guess_extension(part.get_content_type())
name = "part-%i%s" % (counter, ext)
files.append({
'filename': name,
'content': part.get_payload(decode=True),
'type': part.get_content_type()},
)
counter += 1
plain = html = False
if body_plain:
body = body_plain
plain = True
else:
body = _('No plain-text email body available. Please see attachment email_html_body.html.')
if body_html:
html = True
files.append({
'filename': _("email_html_body.html"),
'content': body_html,
'type': 'text/html',
})
now = datetime.now()
if ticket:
try:
t = Ticket.objects.get(id=ticket)
new = False
except Ticket.DoesNotExist:
logger.debug("Didn't find a ticket with ID %s" % ticket)
ticket = None
priority = 3
smtp_priority = message.get('priority', '')
smtp_importance = message.get('importance', '')
high_priority_types = ('high', 'important', '1', 'urgent')
if smtp_priority in high_priority_types or smtp_importance in high_priority_types:
priority = 2
if ticket == None:
logger.debug("Creating new ticket for email")
t = Ticket(
title=subject,
queue=queue,
submitter_email=sender_email,
created=now,
description=body,
priority=priority,
)
t.save()
new = True
update = ''
elif t.status == Ticket.CLOSED_STATUS:
logger.debug("Reopening ticket")
t.status = Ticket.REOPENED_STATUS
示例13: save
def save(self, owner=None):
"""
Writes and returns a Ticket() object
"""
q = Queue.objects.get(id=int(self.cleaned_data["queue"]))
t = Ticket(
title=self.cleaned_data["title"],
owner=owner,
submitter_email=self.cleaned_data["submitter_email"],
created=datetime.now(),
status=Ticket.OPEN_STATUS,
queue=q,
description=self.cleaned_data["body"],
priority=self.cleaned_data["priority"],
account=owner.account,
)
t.save()
f = FollowUp(
ticket=t,
title=_("Ticket Opened Via Web"),
date=datetime.now(),
public=True,
comment=self.cleaned_data["body"],
account=owner.account,
)
f.save()
files = []
if self.cleaned_data["attachment"]:
import mimetypes
file = self.cleaned_data["attachment"]
filename = file.name.replace(" ", "_")
a = Attachment(
followup=f,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or "application/octet-stream",
size=file.size,
)
a.file.save(file.name, file, save=False)
a.save()
if file.size < getattr(settings, "MAX_EMAIL_ATTACHMENT_SIZE", 512000):
# Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
files.append(a.file.path)
context = {"ticket": t, "queue": q}
messages_sent_to = []
send_templated_mail(
"newticket_owner",
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
"newticket_cc",
context,
recipients=q.new_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(q.new_ticket_cc)
if (
q.updated_ticket_cc
and q.updated_ticket_cc != q.new_ticket_cc
and q.updated_ticket_cc not in messages_sent_to
):
send_templated_mail(
"newticket_cc",
context,
recipients=q.updated_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
return t
示例14: save
def save(self, user):
"""
Writes and returns a Ticket() object
"""
q = Queue.objects.get(id=int(self.cleaned_data['queue']))
t = Ticket( title = self.cleaned_data['title'],
submitter_email = self.cleaned_data['submitter_email'],
created = timezone.now(),
status = Ticket.OPEN_STATUS,
queue = q,
description = self.cleaned_data['body'],
priority = self.cleaned_data['priority'],
due_date = self.cleaned_data['due_date'],
)
if HAS_TAG_SUPPORT:
t.tags = self.cleaned_data['tags']
if self.cleaned_data['assigned_to']:
try:
u = User.objects.get(id=self.cleaned_data['assigned_to'])
t.assigned_to = u
except User.DoesNotExist:
t.assigned_to = None
t.save()
for field, value in self.cleaned_data.items():
if field.startswith('custom_'):
field_name = field.replace('custom_', '')
customfield = CustomField.objects.get(name=field_name)
cfv = TicketCustomFieldValue(ticket=t,
field=customfield,
value=value)
cfv.save()
f = FollowUp( ticket = t,
title = _('Ticket Opened'),
date = timezone.now(),
public = True,
comment = self.cleaned_data['body'],
user = user,
)
if self.cleaned_data['assigned_to']:
f.title = _('Ticket Opened & Assigned to %(name)s') % {
'name': t.get_assigned_to
}
f.save()
files = []
if self.cleaned_data['attachment']:
import mimetypes
file = self.cleaned_data['attachment']
filename = file.name.replace(' ', '_')
a = Attachment(
followup=f,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or 'application/octet-stream',
size=file.size,
)
a.file.save(file.name, file, save=False)
a.save()
if file.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000):
# Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
files.append(a.file.path)
context = safe_template_context(t)
context['comment'] = f.comment
messages_sent_to = []
if t.submitter_email:
send_templated_mail(
'newticket_submitter',
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if t.assigned_to and t.assigned_to != user and t.assigned_to.usersettings.settings.get('email_on_ticket_assign', False) and t.assigned_to.email and t.assigned_to.email not in messages_sent_to:
send_templated_mail(
'assigned_owner',
context,
recipients=t.assigned_to.email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.assigned_to.email)
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
#.........这里部分代码省略.........
示例15: save
def save(self):
"""
Writes and returns a Ticket() object
"""
q = self.cleaned_data["queue"]
t = Ticket(
title=self.cleaned_data["title"],
submitter_email=self.cleaned_data["submitter_email"],
created=timezone.now(),
status=Ticket.OPEN_STATUS,
queue=q,
description=self.cleaned_data["body"],
priority=self.cleaned_data["priority"],
due_date=self.cleaned_data["due_date"],
)
t.save()
for field, value in self.cleaned_data.items():
if field.startswith("custom_"):
field_name = field.replace("custom_", "", 1)
customfield = CustomField.objects.get(name=field_name)
cfv = TicketCustomFieldValue(ticket=t, field=customfield, value=value)
cfv.save()
f = FollowUp(
ticket=t,
title=_("Ticket Opened Via Web"),
date=timezone.now(),
public=True,
comment=self.cleaned_data["body"],
)
f.save()
files = []
if self.cleaned_data["attachment"]:
import mimetypes
file = self.cleaned_data["attachment"]
filename = file.name.replace(" ", "_")
a = Attachment(
followup=f,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or "application/octet-stream",
size=file.size,
)
a.file.save(file.name, file, save=False)
a.save()
if file.size < getattr(settings, "MAX_EMAIL_ATTACHMENT_SIZE", 512000):
# Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
files.append([a.filename, a.file])
context = safe_template_context(t)
messages_sent_to = []
send_templated_mail(
"newticket_submitter",
context,
recipients=t.submitter_email,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
"newticket_cc",
context,
recipients=q.new_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
messages_sent_to.append(q.new_ticket_cc)
if (
q.updated_ticket_cc
and q.updated_ticket_cc != q.new_ticket_cc
and q.updated_ticket_cc not in messages_sent_to
):
send_templated_mail(
"newticket_cc",
context,
recipients=q.updated_ticket_cc,
sender=q.from_address,
fail_silently=True,
files=files,
)
return t