Revision d028ab18 invitations/invitations.py

b/invitations/invitations.py
42 42
from django.template.loader import render_to_string
43 43
from django.core.validators import validate_email
44 44
from django.views.decorators.csrf import csrf_protect
45
from synnefo.logic.email_send import send_async
45
from django.utils.translation import gettext_lazy as _
46 46

  
47
from synnefo.logic.email_send import send_async
47 48
from synnefo.api.common import method_not_allowed
48 49
from synnefo.db.models import Invitations, SynnefoUser
49
from synnefo.logic import users
50
from synnefo.logic import users, log
50 51

  
51 52
from Crypto.Cipher import AES
52 53

  
54
_logger = log.get_logger("synnefo.invitations")
53 55

  
54 56
def process_form(request):
55 57
    errors = []
......
69 71

  
70 72
            inv = add_invitation(request.user, name, email)
71 73
            send_invitation(inv)
72

  
74
        # FIXME: Delete invitation and user on error
75
        except (InvitationException, ValidationError) as e:
76
            errors += ["Invitation to %s <%s> not sent. Reason: %s" %
77
                       (name, email, e.messages[0])]
73 78
        except Exception as e:
74
            try :
75
                errors += ["Invitation to %s <%s> not sent. Reason: %s" %
76
                           (name, email, e.messages[0])]
77
            except:
78
                errors += ["Invitation to %s <%s> not sent. Reason: %s" %
79
                           (name, email, e.message)]
79
            _logger.exception(e)
80
            errors += ["Invitation to %s <%s> not sent. Reason: %s" %
81
                       (name, email, e.message)]
80 82

  
81 83
    respose = None
82 84
    if errors:
......
228 230

  
229 231
    data = render_to_string('invitation.txt', {'email': email})
230 232

  
231
    print data
232

  
233 233
    send_async(
234 234
        frm = "%s <%s>"%(invitation.source.realname,invitation.source.uniq),
235 235
        to = "%s <%s>"%(invitation.target.realname,invitation.target.uniq),
236
        subject = u'Πρόσκληση για την υπηρεσία Ωκεανός',
236
        subject = u'Πρόσκληση στην υπηρεσία Ωκεανός',
237
        #subject = _('Invitation to IaaS service Okeanos'),
237 238
        body = data
238 239
    )
239 240

  
......
298 299
    invitation.accepted = True
299 300
    invitation.save()
300 301

  
301

  
302
class TooManyInvitations(Exception):
302
class InvitationException(Exception):
303 303
    messages = []
304 304

  
305
class TooManyInvitations(InvitationException):
306

  
305 307
    def __init__(self, msg):
306 308
        self.messages.append(msg)
307 309

  
308 310

  
309
class AlreadyInvited(Exception):
310
    messages = []
311
class AlreadyInvited(InvitationException):
311 312

  
312 313
    def __init__(self, msg):
313 314
        self.messages.append(msg)

Also available in: Unified diff