def update_template(template=None): """ Update an email template """ if request.method == 'PUT': body = request.get_json() code, resp = TemplatesController.update(template, body) else: code, resp = TemplatesController.destroy(template) return code, resp
def get_prefetch_preset(user, ticket_id, preset_id, lang=None): """ Prefetch preset with ticket infos """ action = params = None try: ticket = Ticket.objects.get(id=ticket_id) preset = TicketWorkflowPreset.objects.get(id=preset_id, roles=user.operator.role) if preset.config: action = model_to_dict(preset.config.action) if preset.config.params: params = {param.codename: param.value for param in preset.config.params.all()} preset = model_to_dict(preset) except (ObjectDoesNotExist, ValueError): return 404, {'status': 'Not Found', 'code': 404, 'message': 'Ticket or preset not found'} preset['templates'] = [] templates_codename = list(set(MailTemplate.objects.filter(ticketworkflowpreset=preset['id']).values_list('codename', flat=True))) for codename in templates_codename: template = MailTemplate.objects.get(codename=codename) code, resp = TemplatesController.get_prefetch_template(ticket.id, template.id, lang=lang) if code != 200: return code, resp else: preset['templates'].append(resp) preset['action'] = action if action and params: preset['action']['params'] = params return 200, preset
def get_all_templates(): """ Get all Abuse mail templates """ filters = None if 'filters' in request.args: filters = request.args['filters'] code, resp = TemplatesController.index(filters=filters) return code, resp
def get_recipients_type(): """ Get application supported languages """ code, resp = TemplatesController.get_recipients_type() return code, resp
def get_supported_languages(): """ Get application supported languages """ code, resp = TemplatesController.get_supported_languages() return code, resp
def create_templates(): """ Add an email template """ body = request.get_json() code, resp = TemplatesController.create(body) return code, resp
def get_template(template=None): """ Get a given email template """ code, resp = TemplatesController.show(template) return code, resp
def get_ticket_prefetched_template(ticket=None, template=None): """ Get a template prefetched with ticket infos """ code, resp = TemplatesController.get_prefetch_template(ticket, template) return code, resp