diff --git a/hr/views.py b/hr/views.py index e6f0a93..1573a0c 100644 --- a/hr/views.py +++ b/hr/views.py @@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse from django.contrib.auth.models import User, Group from django.contrib.auth.decorators import login_required from django.template import RequestContext +from django.template.loader import render_to_string import settings @@ -145,14 +146,28 @@ def update_application(request, applicationid): if not hrstaff and int(form.cleaned_data['new_status']) > 1: return HttpResponseRedirect(reverse('hr.views.index')) - app.status = form.cleaned_data['new_status'] - app.save() + if not app.status == form.cleaned_data['new_status']: + + app.status = form.cleaned_data['new_status'] + app.save() - if app.status == APPLICATION_STATUS_AWAITINGREVIEW: - app.user.message_set.create(message="Your application for %s to %s has been submitted." % (app.character, app.corporation)) - if app.status == APPLICATION_STATUS_ACCEPTED: - app.user.message_set.create(message="Your application for %s to %s has been accepted." % (app.character, app.corporation)) - elif app.status == APPLICATION_STATUS_REJECTED: - app.user.message_set.create(message="Your application for %s to %s has been rejected." % (app.character, app.corporation)) + def send_message(application, message_type): + from django.core.mail import send_mail + subject = render_to_string('hr/emails/%s_subject.txt' % message_type, { 'app': app }) + subject = ''.join(subject.splitlines()) + message = render_to_string('hr/emails/%s.txt' % message_type, { 'app': app }) + #send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [application.user.email]) + + if len(application.user.redditaccount_set.all()) > 0: + from reddit.api import Inbox + ib = Inbox(settings.REDDIT_USER, settings.REDDIT_PASSWD) + ib.send(application.user.redditaccount_set.all()[0].username, subject, message) + + print app.status, APPLICATION_STATUS_ACCEPTED + if int(app.status) == APPLICATION_STATUS_ACCEPTED: + print "Yup!" + send_message(app, 'accepted') + elif app.status == APPLICATION_STATUS_REJECTED: + send_message(app, 'rejected') return HttpResponseRedirect(reverse('hr.views.view_application', args=[applicationid])) diff --git a/reddit/api.py b/reddit/api.py index d35037b..9051260 100644 --- a/reddit/api.py +++ b/reddit/api.py @@ -83,14 +83,11 @@ class Inbox(): if not self.login_cookie: raise NotLoggedIn - print self.login_cookie - data = { 'to': to, 'subject': subject, - 'text': 'text', + 'text': text, 'uh': self.modhash, 'thing_id': '' } url = "%s" % (self.REDDIT_API_COMPOSE) jsondoc = json.load(self._url_request(url, data)) - print jsondoc diff --git a/templates/hr/emails/accepted.txt b/templates/hr/emails/accepted.txt new file mode 100644 index 0000000..e5a3581 --- /dev/null +++ b/templates/hr/emails/accepted.txt @@ -0,0 +1,9 @@ +Hi {{ app.character }}, + +Congratulations, Your application to {{ app.corporation }} has been accepted. You will be accepted into the {{ app.corporation }} within the next 24 hours. + +If you have any further questions regarding your application, please contact {{ app.corporation }} via the normal channels. + +Regards, + +{{ app.corporation }} HR Bot diff --git a/templates/hr/emails/accepted_subject.txt b/templates/hr/emails/accepted_subject.txt new file mode 100644 index 0000000..d65268a --- /dev/null +++ b/templates/hr/emails/accepted_subject.txt @@ -0,0 +1 @@ +Application to {{ app.corporation }} accepted. diff --git a/templates/hr/emails/rejected.txt b/templates/hr/emails/rejected.txt new file mode 100644 index 0000000..eab12f4 --- /dev/null +++ b/templates/hr/emails/rejected.txt @@ -0,0 +1,11 @@ +Hi {{ app.character }}, + +Your application to {{ app.corporation }} has been rejected. + +One of our Personnel people will contact you in a seperate method to explain why you have been rejected. + +If you have any further questions regarding your application, please contact {{ app.corporation }} via the normal channels. + +Regards, + +{{ app.corporation }} HR Bot diff --git a/templates/hr/emails/rejected_subject.txt b/templates/hr/emails/rejected_subject.txt new file mode 100644 index 0000000..11f9af0 --- /dev/null +++ b/templates/hr/emails/rejected_subject.txt @@ -0,0 +1 @@ +Application to {{ app.corporation }} rejected.