diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bd04192 --- /dev/null +++ b/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 diff --git a/sigi/apps/solicitacoes/forms.py b/sigi/apps/solicitacoes/forms.py index 5db2086..6153e68 100644 --- a/sigi/apps/solicitacoes/forms.py +++ b/sigi/apps/solicitacoes/forms.py @@ -1,8 +1,33 @@ from __future__ import absolute_import +from django.db import transaction from django import forms from django.forms import ModelForm - +from sigi.settings.prod import OSTICKET_API_KEY, OSTICKET_URL 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): @@ -20,6 +45,14 @@ class SolicitacaoForm(ModelForm): widgets = {u'codigo': 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): diff --git a/sigi/apps/solicitacoes/migrations/0004_solicitacao_osticket.py b/sigi/apps/solicitacoes/migrations/0004_solicitacao_osticket.py new file mode 100644 index 0000000..6e4a52e --- /dev/null +++ b/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'), + ), + ] diff --git a/sigi/apps/solicitacoes/models.py b/sigi/apps/solicitacoes/models.py index f6d025f..cacff14 100644 --- a/sigi/apps/solicitacoes/models.py +++ b/sigi/apps/solicitacoes/models.py @@ -45,6 +45,11 @@ class Solicitacao(models.Model): null=True, verbose_name=_(u'Descrição')) + osticket = models.CharField(blank=True, + null=True, + max_length=256, + verbose_name=_(u'Código Ticket')) + class Meta(object): verbose_name = _(u'Solicitação de Novo Serviço') verbose_name_plural = _(u'Solicitações de Novos Serviços') diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 12556c6..fea53bc 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -135,16 +135,6 @@ SERVER_EMAIL = 'sigi@interlegis.leg.br' DEFAULT_FROM_EMAIL = 'spdt@interlegis.leg.br' 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 = ( os.path.join(BASE_DIR, 'templates'), )