Revision 3abf6c78 snf-astakos-app/astakos/im/views.py

b/snf-astakos-app/astakos/im/views.py
62 62
from astakos.im.util import get_context, prepare_response, set_cookie, get_query
63 63
from astakos.im.forms import *
64 64
from astakos.im.functions import send_greeting, send_feedback, SendMailError, \
65
    invite as invite_func, logout as auth_logout, activate as activate_func, switch_account_to_shibboleth
65
    invite as invite_func, logout as auth_logout, activate as activate_func, \
66
    switch_account_to_shibboleth, send_admin_notification, SendNotificationError
66 67
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, COOKIE_NAME, COOKIE_DOMAIN, IM_MODULES, SITENAME, LOGOUT_NEXT, LOGGING_LEVEL
67 68

  
68 69
logger = logging.getLogger(__name__)
......
455 456
        return index(request)
456 457
        
457 458
    try:
458
        local_user = AstakosUser.objects.get(~Q(id = user.id), email=user.email, is_active=True)
459
        local_user = AstakosUser.objects.get(
460
            ~Q(id = user.id),
461
            email=user.email,
462
            is_active=True
463
        )
459 464
    except AstakosUser.DoesNotExist:
460 465
        try:
461
            activate_func(user, greeting_email_template_name, helpdesk_email_template_name, verify_email=True)
466
            activate_func(
467
                user,
468
                greeting_email_template_name,
469
                helpdesk_email_template_name,
470
                verify_email=True
471
            )
462 472
            response = prepare_response(request, user, next, renew=True)
463 473
            transaction.commit()
464 474
            return response
......
475 485
            return index(request)
476 486
    else:
477 487
        try:
478
            user = switch_account_to_shibboleth(user, local_user, greeting_email_template_name)
488
            user = switch_account_to_shibboleth(
489
                user,
490
                local_user,
491
                greeting_email_template_name
492
            )
479 493
            response = prepare_response(request, user, next, renew=True)
480 494
            transaction.commit()
481 495
            return response
......
595 609
    except:
596 610
        return HttpResponseBadRequest(_('No such group kind'))
597 611
    
598
    template_name=None,
599 612
    template_loader=loader
600
    extra_context=None
601 613
    post_save_redirect='/im/group/%(id)s/'
602
    login_required=False
603 614
    context_processors=None
604 615
    model, form_class = get_model_and_form_class(
605 616
        model=None,
606 617
        form_class=AstakosGroupCreationForm
607 618
    )
608
    # TODO better approach???
609 619
    resources = dict( (str(r.id), r) for r in Resource.objects.select_related().all() )
620
    policies = []
610 621
    if request.method == 'POST':
611 622
        form = form_class(request.POST, request.FILES, resources=resources)
612 623
        if form.is_valid():
613 624
            new_object = form.save()
625
            
626
            # save owner
614 627
            new_object.owners = [request.user]
628
            
629
            # save quota policies
615 630
            for (rid, limit) in form.resources():
616 631
                try:
617 632
                    r = resources[rid]
618 633
                except KeyError, e:
619 634
                    logger.exception(e)
620
                    # Should I stay or should I go???
635
                    # TODO Should I stay or should I go???
621 636
                    continue
622 637
                else:
623 638
                    new_object.astakosgroupquota_set.create(
624 639
                        resource = r,
625 640
                        limit = limit
626 641
                    )
642
                policies.append('%s %d' % (r, limit))
627 643
            msg = _("The %(verbose_name)s was created successfully.") %\
628 644
                                    {"verbose_name": model._meta.verbose_name}
629 645
            messages.success(request, msg, fail_silently=True)
646
            
647
            # send notification
648
            try:
649
                send_admin_notification(
650
                    template_name='im/group_creation_notification.txt',
651
                    dictionary={
652
                        'group':new_object,
653
                        'owner':request.user,
654
                        'policies':policies,
655
                    },
656
                    subject='%s alpha2 testing group creation notification' % SITENAME
657
                )
658
            except SendNotificationError, e:
659
                messages.error(request, e, fail_silently=True)
630 660
            return redirect(post_save_redirect, new_object)
631 661
    else:
632 662
        now = datetime.now()

Also available in: Unified diff