Browse Source

Implementa criação de ticket no osticket

Precisa configurar o prod.py
pull/6/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Luciano Almeida
parent
commit
02e661906a
  1. 14
      docker-compose.yml
  2. 35
      sigi/apps/solicitacoes/forms.py
  3. 20
      sigi/apps/solicitacoes/migrations/0004_solicitacao_osticket.py
  4. 5
      sigi/apps/solicitacoes/models.py
  5. 10
      sigi/settings/base.py

14
docker-compose.yml

@ -0,0 +1,14 @@
osticket:
image: campbellsoftwaresolutions/osticket
ports:
- "80:80"
links:
- mysql
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=osticket
- MYSQL_USER=osticket
- MYSQL_PASSWORD=secret

35
sigi/apps/solicitacoes/forms.py

@ -1,8 +1,33 @@
from __future__ import absolute_import from __future__ import absolute_import
from django.db import transaction
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
from sigi.settings.prod import OSTICKET_API_KEY, OSTICKET_URL
from .models import Sistema, Solicitacao from .models import Sistema, Solicitacao
import json
import requests
def open_osticket(solicitacao):
headers = {'X-API-KEY': OSTICKET_API_KEY,
'Content-Type': 'application/json'}
usuario = solicitacao.usuario
data = {"alert": True,
"autorespond": True,
"source": "API",
"name": usuario.username,
"email": usuario.email,
"phone": '-'.join((usuario.primeiro_telefone.ddd,
usuario.primeiro_telefone.numero)),
"subject": solicitacao.titulo,
"ip": "",
"message": solicitacao.resumo}
response = requests.post(OSTICKET_URL, headers=headers, json=data)
if response.status_code == requests.codes.ok:
return response.text
else:
response.raise_for_status()
class SolicitacaoForm(ModelForm): class SolicitacaoForm(ModelForm):
@ -20,6 +45,14 @@ class SolicitacaoForm(ModelForm):
widgets = {u'codigo': forms.HiddenInput(), widgets = {u'codigo': forms.HiddenInput(),
u'usuario': forms.HiddenInput()} u'usuario': forms.HiddenInput()}
@transaction.atomic
def save(self, commit=False):
solicitacao = super(SolicitacaoForm, self).save(commit)
os_ticket = open_osticket(solicitacao)
solicitacao.osticket = os_ticket
solicitacao.save()
return solicitacao
class SolicitacaoEditForm(ModelForm): class SolicitacaoEditForm(ModelForm):

20
sigi/apps/solicitacoes/migrations/0004_solicitacao_osticket.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-23 13:22
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('solicitacoes', '0003_auto_20160623_0829'),
]
operations = [
migrations.AddField(
model_name='solicitacao',
name='osticket',
field=models.CharField(blank=True, max_length=256, null=True, verbose_name='C\xf3digo Ticket'),
),
]

5
sigi/apps/solicitacoes/models.py

@ -45,6 +45,11 @@ class Solicitacao(models.Model):
null=True, null=True,
verbose_name=_(u'Descrição')) verbose_name=_(u'Descrição'))
osticket = models.CharField(blank=True,
null=True,
max_length=256,
verbose_name=_(u'Código Ticket'))
class Meta(object): class Meta(object):
verbose_name = _(u'Solicitação de Novo Serviço') verbose_name = _(u'Solicitação de Novo Serviço')
verbose_name_plural = _(u'Solicitações de Novos Serviços') verbose_name_plural = _(u'Solicitações de Novos Serviços')

10
sigi/settings/base.py

@ -135,16 +135,6 @@ SERVER_EMAIL = 'sigi@interlegis.leg.br'
DEFAULT_FROM_EMAIL = 'spdt@interlegis.leg.br' DEFAULT_FROM_EMAIL = 'spdt@interlegis.leg.br'
EMAIL_SUBJECT_PREFIX = u'[SIGI]' EMAIL_SUBJECT_PREFIX = u'[SIGI]'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.interlegis.leg.br'
EMAIL_HOST_USER = 'sapl-test'
EMAIL_HOST_PASSWORD = '2BhCwbGHcZ'
EMAIL_SEND_USER = 'atendimento@interlegis.leg.br'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
TEMPLATE_DIRS = ( TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'templates'),
) )

Loading…
Cancel
Save