本文整理汇总了Python中helpdesk.models.Attachment类的典型用法代码示例。如果您正苦于以下问题:Python Attachment类的具体用法?Python Attachment怎么用?Python Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self, user):
task = Task.objects.get(id=int(self.cleaned_data['task']))
if self.cleaned_data['attachment']:
import mimetypes
file = self.cleaned_data['attachment']
filename = file.name.replace(' ', '_')
a = Attachment(
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()
task.attachments.add(a)
task.save()
return None
示例2: _attach_files_to_follow_up
def _attach_files_to_follow_up(self, followup):
attachments = []
if self.cleaned_data["attachment"]:
import mimetypes
attachment = self.cleaned_data["attachment"]
filename = attachment.name.replace(" ", "_")
att = Attachment(
followup=followup,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or "application/octet-stream",
size=attachment.size,
)
att.file.save(attachment.name, attachment, save=False)
att.save()
if attachment.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.
try:
attachments.append([att.filename, att.file])
except NotImplementedError:
pass
return attachments
示例3: 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,
#.........这里部分代码省略.........
示例4: ticket_from_message
#.........这里部分代码省略.........
submitter_email=sender_email,
created=now,
description=body,
priority=priority,
)
t.save()
new = True
elif t.status == Ticket.CLOSED_STATUS:
t.status = Ticket.REOPENED_STATUS
t.save()
f = FollowUp(
ticket = t,
title = _('E-Mail Received from %(sender_email)s' % {'sender_email': sender_email}),
date = datetime.now(),
public = True,
comment = body,
)
if t.status == Ticket.REOPENED_STATUS:
f.new_status = Ticket.REOPENED_STATUS
f.title = _('Ticket Re-Opened by E-Mail Received from %(sender_email)s' % {'sender_email': sender_email})
f.save()
if not quiet:
print (" [%s-%s] %s%s" % (t.queue.slug, t.id, t.title, update)).encode('ascii', 'replace')
for file in files:
if file['content']:
filename = file['filename'].encode('ascii', 'replace').replace(' ', '_')
filename = re.sub('[^a-zA-Z0-9._-]+', '', filename)
a = Attachment(
followup=f,
filename=filename,
mime_type=file['type'],
size=len(file['content']),
)
a.file.save(filename, ContentFile(file['content']), save=False)
a.save()
if not quiet:
print " - %s" % filename
context = safe_template_context(t)
if new:
"""
if sender_email:
send_templated_mail(
'newticket_submitter',
context,
recipients=sender_email,
sender=queue.from_address,
fail_silently=True,
)
"""
if queue.new_ticket_cc:
send_templated_mail(
'newticket_cc',
context,
recipients=queue.new_ticket_cc,
sender=queue.from_address,
示例5: update_ticket
def update_ticket(request, ticket_id, public=False):
if not (
public
or (
request.user.is_authenticated()
and request.user.is_active
and (request.user.is_staff or helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE)
)
):
return HttpResponseForbidden(_("Sorry, you need to login to do that."))
ticket = get_object_or_404(Ticket, id=ticket_id)
comment = request.POST.get("comment", "")
new_status = int(request.POST.get("new_status", ticket.status))
title = request.POST.get("title", "")
public = request.POST.get("public", False)
owner = int(request.POST.get("owner", None))
priority = int(request.POST.get("priority", ticket.priority))
due_year = int(request.POST.get("due_date_year"))
due_month = int(request.POST.get("due_date_month"))
due_day = int(request.POST.get("due_date_day"))
due_date = datetime(due_year, due_month, due_day) if due_year and due_month and due_day else ticket.due_date
tags = request.POST.get("tags", "")
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
# comment.
from django.template import loader, Context
context = safe_template_context(ticket)
# this line sometimes creates problems if code is sent as a comment.
# if comment contains some django code, like "why does {% if bla %} crash",
# then the following line will give us a crash, since django expects {% if %}
# to be closed with an {% endif %} tag.
comment = loader.get_template_from_string(comment).render(Context(context))
if owner is None and ticket.assigned_to:
owner = ticket.assigned_to.id
f = FollowUp(ticket=ticket, date=datetime.now(), comment=comment)
if request.user.is_staff or helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
f.user = request.user
f.public = public
reassigned = False
if owner is not None:
if owner != 0 and ((ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to):
new_user = User.objects.get(id=owner)
f.title = _("Assigned to %(username)s") % {"username": new_user.username}
ticket.assigned_to = new_user
reassigned = True
# user changed owner to 'unassign'
elif owner == 0 and ticket.assigned_to is not None:
f.title = _("Unassigned")
ticket.assigned_to = None
if new_status != ticket.status:
ticket.status = new_status
ticket.save()
f.new_status = new_status
if f.title:
f.title += " and %s" % ticket.get_status_display()
else:
f.title = "%s" % ticket.get_status_display()
if not f.title:
if f.comment:
f.title = _("Comment")
else:
f.title = _("Updated")
f.save()
files = []
if request.FILES:
import mimetypes, os
for file in request.FILES.getlist("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)
if title != ticket.title:
c = TicketChange(followup=f, field=_("Title"), old_value=ticket.title, new_value=title)
c.save()
ticket.title = title
#.........这里部分代码省略.........
示例6: followup_edit
def followup_edit(request):
id = request.POST.get("id")
item = None
if request.method == 'POST':
if id:
model = FollowUp.objects.get(id=id)
form = FollowUpForm(request.POST, instance=model)
if not (request.user.account.has_perm('helpdesk.change_followup')):
messages.error(request, _(u'У вас нет прав на редактирование комментариев к заявке'), extra_tags='alert-danger')
return HttpResponseRedirect(request.path)
else:
form = FollowUpForm(request.POST, request.FILES)
if not (request.user.account.has_perm('helpdesk.add_followup')):
messages.error(request, _(u'У вас нет прав на добавление комментариев к заявке'), extra_tags='alert-danger')
return HttpResponseRedirect(request.path)
if form.is_valid():
model = form.save(commit=False)
model.save()
followup_type = form.cleaned_data.get('followup_type')
if followup_type=='comment':
if not id:
model.title = _(u'Добавлен комментарий от %(USER)s ') % {'USER': request.user.account}
elif followup_type=='files':
if not id:
model.title = _(u'Добавлен файл от %(USER)s ') % {'USER': request.user.account}
files = []
if request.FILES:
import mimetypes, os
for file in request.FILES.getlist('file'):
filename = file.name.replace(' ', '_')
a = Attachment(
followup=model,
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)
elif followup_type=='new_status':
model.title = _(u'Статус заявки изменён %(USER)s ') % {'USER': request.user.account}
if model.new_status!=model.ticket:
model.ticket.status = model.new_status
if model.new_status in [3,4]:
model.ticket.resolution = model.comment
model.ticket.save()
log('EDIT', request.user, model.ticket)
model.systemuser = request.user.account
model.save()
from django.template import loader, Context
log('EDIT', request.user, model) if id else log('CREATE', request.user, model)
messages.success(request, _(u'Комментарий успешно сохранён.'), extra_tags='alert-success')
return {'form':form, 'status': True}
else:
messages.error(request, _(u'При сохранении комментария возникли ошибки.'), extra_tags='alert-danger')
if form._errors:
for k, v in form._errors.items():
messages.error(request, '%s=>%s' % (k, ','.join(v)), extra_tags='alert-danger')
return {'form':form, 'status': False}
else:
id = request.GET.get("id")
ticket_id = request.GET.get("ticket_id")
followup_type = request.GET.get("followup_type") or 'comment'
new_status = request.GET.get("new_status")
if not (request.user.account.has_perm('helpdesk.add_followup')):
messages.error(request, _(u'У вас нет прав на создание комментариев.'), extra_tags='alert-danger')
return {}
if id:
item = FollowUp.objects.get(id=id)
form = FollowUpForm(instance=item)
else:
if new_status:
form = FollowUpForm(initial={'ticket': Ticket.objects.get(id=ticket_id), 'followup_type': followup_type, 'new_status':2})
else:
form = FollowUpForm(initial={'ticket': Ticket.objects.get(id=ticket_id), 'followup_type': followup_type})
#.........这里部分代码省略.........
示例7: form_valid
def form_valid(self, form):
old_ticket = form.instance
ticket = form.save(commit=False)
no_changes = all([
not self.request.FILES,
not self.request.POST['comment'],
ticket.status == old_ticket.status,
ticket.title == old_ticket.title,
ticket.priority == int(old_ticket.priority),
ticket.due_date == old_ticket.due_date,
ticket.owner_id != old_ticket.owner_id
])
if no_changes:
self.object = old_ticket
return HttpResponseRedirect(self.get_success_url())
ticket.save()
self.object = ticket
followup = FollowUp(
ticket_id=ticket.pk,
date = timezone.now(),
comment = self.request.POST['comment'],
user_id = self.request.user.pk,
public = self.request.POST['public'],
title = ''
)
reassigned = False
if ticket.owner_id != old_ticket.owner_id:
followup.title = _('Asigned to %s' % User.objects.get(id=ticket.owner_id))
reassigned = True
if ticket.status != old_ticket.status:
if followup.title != '':
followup.title += ' and '
followup.title += ticket.get_status_display()
followup.save()
files = []
if self.request.FILES:
import mimetypes, os
for file in self.request.FILES.getlist('attachment'):
filename = file.name.encode('ascii', 'ignore')
a = Attachment(
followup_id=followup.pk,
filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or 'application/octet-stream',
size=file.size,
)
a.file.save(filename, 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])
if old_ticket.title != ticket.title:
change = TicketChange(
followup_id=followup.id,
field=_('Title'),
old_value = old_ticket.title,
new_value = ticket.title
)
if old_ticket.priority != ticket.priority:
change = TicketChange(
followup_id=followup.id,
field=_('Priority'),
old_value = old_ticket.priority,
new_value = ticket.priority
)
if old_ticket.due_date != ticket.due_date:
change = TicketChange(
followup_id=followup.id,
field=_('Due on'),
old_value = old_ticket.due_date,
new_value = ticket.due_date
)
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
# comment.
from django.template import loader, Context
context = safe_template_context(ticket)
# this line sometimes creates problems if code is sent as a comment.
# if comment contains some django code, like "why does {% if bla %} crash",
# then the following line will give us a crash, since django expects {% if %}
# to be closed with an {% endif %} tag.
# get_template_from_string was removed in Django 1.8 http://django.readthedocs.org/en/1.8.x/ref/templates/upgrading.html
try:
from django.template import engines
template_func = engines['django'].from_string
except ImportError: # occurs in django < 1.8
#.........这里部分代码省略.........
示例8: update_ticket
def update_ticket(request, ticket_id, public=False):
if not (public or (request.user.is_authenticated() and request.user.is_active and request.user.is_staff)):
return HttpResponseForbidden(_('Sorry, you need to login to do that.'))
ticket = get_object_or_404(Ticket, id=ticket_id)
comment = request.POST.get('comment', '')
new_status = int(request.POST.get('new_status', ticket.status))
title = request.POST.get('title', '')
public = request.POST.get('public', False)
owner = int(request.POST.get('owner', None))
priority = int(request.POST.get('priority', ticket.priority))
tags = request.POST.get('tags', '')
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
# comment.
from django.template import loader, Context
context = safe_template_context(ticket)
comment = loader.get_template_from_string(comment).render(Context(context))
if owner is None and ticket.assigned_to:
owner = ticket.assigned_to.id
f = FollowUp(ticket=ticket, date=datetime.now(), comment=comment)
if request.user.is_staff:
f.user = request.user
f.public = public
reassigned = False
if owner is not None:
if owner != 0 and ((ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to):
new_user = User.objects.get(id=owner)
f.title = _('Assigned to %(username)s') % {
'username': new_user.username,
}
ticket.assigned_to = new_user
reassigned = True
elif owner == 0 and ticket.assigned_to is not None:
f.title = _('Unassigned')
ticket.assigned_to = None
if new_status != ticket.status:
ticket.status = new_status
ticket.save()
f.new_status = new_status
if f.title:
f.title += ' and %s' % ticket.get_status_display()
else:
f.title = '%s' % ticket.get_status_display()
if not f.title:
if f.comment:
f.title = _('Comment')
else:
f.title = _('Updated')
f.save()
files = []
if request.FILES:
import mimetypes, os
for file in request.FILES.getlist('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)
if title != ticket.title:
c = TicketChange(
followup=f,
field=_('Title'),
old_value=ticket.title,
new_value=title,
)
c.save()
ticket.title = title
if priority != ticket.priority:
c = TicketChange(
followup=f,
field=_('Priority'),
old_value=ticket.priority,
new_value=priority,
)
c.save()
ticket.priority = priority
#.........这里部分代码省略.........
示例9: 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
示例10: update_ticket
def update_ticket(request, ticket_id, public=False):
ticket = get_object_or_404(Ticket, id=ticket_id,owner=request.user)
comment = request.POST.get('comment', '')
new_status = int(request.POST.get('new_status', ticket.status))
title = request.POST.get('title', ticket.title)
#public = request.POST.get('public', public)
public=True
owner = ticket.owner
#priority = int(request.POST.get('priority', ticket.priority))
tags = request.POST.get('tags', '')
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
# comment.
from django.template import loader, Context
context = safe_template_context(ticket)
comment = loader.get_template_from_string(comment).render(Context(context))
#if owner is None and ticket.assigned_to:
# owner = ticket.assigned_to.id
f = FollowUp(ticket=ticket, date=datetime.now(), comment=comment)
#if request.user.is_authenticated():
f.account = request.user.account
f.public = True
reassigned = False
if new_status != ticket.status:
ticket.status = new_status
ticket.save()
f.new_status = new_status
if f.title:
f.title += _(u'%(STATUS)s %(USER)s ') % {'USER': request.user.account, 'STATUS': ticket.get_status_display()}
else:
f.title = _(u'%(STATUS)s %(USER)s ') % {'USER': request.user.account, 'STATUS': ticket.get_status_display()}
if not f.title:
if f.comment:
f.title = _(u'Добавлен комментарий от %(USER)s ') % {'USER': request.user.account}
else:
f.title = _(u'Обновлено %(USER)s ') % {'USER': request.user.account}
f.save()
files = []
if request.FILES:
import mimetypes, os
for file in request.FILES.getlist('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)
if title != ticket.title:
c = TicketChange(
followup=f,
field=_('Title'),
old_value=ticket.title,
new_value=title,
)
c.save()
ticket.title = title
if HAS_TAG_SUPPORT:
if tags != ticket.tags:
c = TicketChange(
followup=f,
field=_('Tags'),
old_value=ticket.tags,
new_value=tags,
)
c.save()
ticket.tags = tags
if f.new_status == Ticket.RESOLVED_STATUS:
ticket.resolution = comment
messages_sent_to = []
context.update(
resolution=ticket.resolution,
comment=f.comment,
)
#.........这里部分代码省略.........
示例11: create_object_from_email_message
def create_object_from_email_message(message, ticket_id, payload, files, quiet):
ticket, previous_followup, new = None, None, False
now = timezone.now()
queue = payload['queue']
sender_email = payload['sender_email']
to_list = getaddresses(message.get_all('To', []))
cc_list = getaddresses(message.get_all('Cc', []))
message_id = message.get('Message-Id')
in_reply_to = message.get('In-Reply-To')
if in_reply_to is not None:
try:
queryset = FollowUp.objects.filter(message_id=in_reply_to).order_by('-date')
if queryset.count() > 0:
previous_followup = queryset.first()
ticket = previous_followup.ticket
except FollowUp.DoesNotExist:
pass #play along. The header may be wrong
if previous_followup is None and ticket_id is not None:
try:
ticket = Ticket.objects.get(id=ticket_id)
new = False
except Ticket.DoesNotExist:
ticket = None
# New issue, create a new <Ticket> instance
if ticket is None:
ticket = Ticket.objects.create(
title = payload['subject'],
queue = queue,
submitter_email = sender_email,
created = now,
description = payload['body'],
priority = payload['priority'],
)
ticket.save()
new = True
update = ''
# Old issue being re-openned
elif ticket.status == Ticket.CLOSED_STATUS:
ticket.status = Ticket.REOPENED_STATUS
ticket.save()
f = FollowUp(
ticket = ticket,
title = _('E-Mail Received from %(sender_email)s' % {'sender_email': sender_email}),
date = now,
public = True,
comment = payload['body'],
message_id = message_id,
)
if ticket.status == Ticket.REOPENED_STATUS:
f.new_status = Ticket.REOPENED_STATUS
f.title = _('Ticket Re-Opened by E-Mail Received from %(sender_email)s' % {'sender_email': sender_email})
f.save()
if not quiet:
print((" [%s-%s] %s" % (ticket.queue.slug, ticket.id, ticket.title,)).encode('ascii', 'replace'))
for file in files:
if file['content']:
filename = file['filename'].encode('ascii', 'replace').replace(' ', '_')
filename = re.sub('[^a-zA-Z0-9._-]+', '', filename)
a = Attachment(
followup=f,
filename=filename,
mime_type=file['type'],
size=len(file['content']),
)
a.file.save(filename, ContentFile(file['content']), save=False)
a.save()
if not quiet:
print(" - %s" % filename)
context = safe_template_context(ticket)
new_ticket_ccs = []
new_ticket_ccs.append(create_ticket_cc(ticket, to_list))
new_ticket_ccs.append(create_ticket_cc(ticket, cc_list))
notification_template = None
notifications_to_be_sent = [sender_email,]
if queue.enable_notifications_on_email_events and len(notifications_to_be_sent):
ticket_cc_list = TicketCC.objects.filter(ticket=ticket).all().values_list('email', flat=True)
for email in ticket_cc_list :
notifications_to_be_sent.append(email)
#.........这里部分代码省略.........
示例12: ticket_from_message
#.........这里部分代码省略.........
description=body,
priority=priority,
)
t.save()
new = True
update = ''
elif t.status == Ticket.CLOSED_STATUS:
logger.debug("Reopening ticket")
t.status = Ticket.REOPENED_STATUS
t.save()
f = FollowUp(
ticket = t,
title = _('E-Mail Received from %(sender_email)s' % {'sender_email': sender_email}),
date = datetime.now(),
public = True,
comment = body,
)
if t.status == Ticket.REOPENED_STATUS:
f.new_status = Ticket.REOPENED_STATUS
f.title = _('Ticket Re-Opened by E-Mail Received from %(sender_email)s' % {'sender_email': sender_email})
f.save()
if not quiet:
logger.info(" [%s-%s] %s%s" % (t.queue.slug, t.id, t.title, update)).encode('ascii', 'replace')
for file in files:
if file['content']:
filename = file['filename'].encode('ascii', 'replace').replace(' ', '_')
filename = re.sub('[^a-zA-Z0-9._-]+', '', filename)
a = Attachment(
followup=f,
filename=filename,
mime_type=file['type'],
size=len(file['content']),
)
a.file.save(filename, ContentFile(file['content']), save=False)
a.save()
if not quiet:
logger.info(" - %s" % filename)
context = safe_template_context(t)
if new:
if helpdesk_settings.HELPDESK_SEND_SUBMITTER_EMAIL and sender_email and not is_cc:
send_templated_mail(
'newticket_submitter',
context,
recipients=sender_email,
sender=queue.from_address,
fail_silently=True,
)
if queue.new_ticket_cc and not is_cc:
send_templated_mail(
'newticket_cc',
context,
recipients=queue.new_ticket_cc,
sender=queue.from_address,
fail_silently=True,
)
示例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=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,
)
#.........这里部分代码省略.........
示例15: 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',
#.........这里部分代码省略.........