def entity_comment(request, federation_slug=None, entity_id=None): entity = None federation = None if federation_slug: federation = get_object_or_404(Federation, slug=federation_slug) if entity_id: entity = get_object_or_404(Entity, id=entity_id, federations__id=federation.id) if entity_id and not federation_slug: entity = get_object_or_404(Entity, id=entity_id) if request.method == 'POST': form = EntityCommentForm(request.POST, request.FILES, instance=entity) if form.is_valid(): mail_config = getattr(settings, "MAIL_CONFIG") try: subject = mail_config['comment_subject'] % entity send_mail(form.data['email'], subject, form.data['comment']) messages.success(request, _('Comment posted successfully')) except Exception, errorMessage: messages.error( request, _('Comment could not be posted successfully: %s' % errorMessage)) return HttpResponseRedirect(form.instance.get_absolute_url()) else: messages.error(request, _('Please correct the errors indicated' ' below'))
def entity_proposal(request, federation_slug=None, entity_id=None): entity = None federation = None if federation_slug: federation = get_object_or_404(Federation, slug=federation_slug) if entity_id: entity = get_object_or_404(Entity, id=entity_id, federations__id=federation.id) if entity_id and not federation_slug: entity = get_object_or_404(Entity, id=entity_id) if request.method == 'POST': form = EntityProposalForm(request.POST, request.FILES, instance=entity) if form.is_valid(): mail_config = getattr(settings, "MAIL_CONFIG") try: subject = mail_config['proposal_subject'] %entity my_dict = dict(form.data.iterlists()) body = mail_config['proposal_body'] % (entity, ', '.join(my_dict['federations']), form.data['comment']) send_mail(form.data['email'], subject, body) messages.success(request, _('Proposal posted successfully')) except Exception, errorMessage: messages.error(request, _('Proposal could not be posted successfully: %s' %errorMessage)) return HttpResponseRedirect(form.instance.get_absolute_url()) else: messages.error(request, _('Please correct the errors indicated' ' below'))
def _send_message_via_email(error_msg, federation, logger=None): mail_config_dict = getattr(settings, "MAIL_CONFIG") try: subject = mail_config_dict['refresh_subject'] % federation from_address = mail_config_dict['from_email_address'] send_mail(from_address, subject, '%s' % error_msg) except Exception, errorMessage: log('Message could not be posted successfully: %s' % errorMessage, logger, logging.ERROR)
# MET v2 was developed for TERENA by Tamim Ziai, DAASI International GmbH, http://www.daasi.de # Current version of MET has been revised for performance improvements by Andrea Biancini, # Consortium GARR, http://www.garr.it ######################################################################################### import sys, os import logging.config os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs/' current_directory = os.path.join(os.path.dirname(__file__), '..') activate_this = os.path.join(current_directory, '..', 'met-venv/bin/activate_this.py') execfile(activate_this, dict(__file__=activate_this)) sys.path.append(current_directory) sys.path.append(os.path.join(current_directory, 'met')) os.environ['DJANGO_SETTINGS_MODULE'] = 'met.settings' import django django.setup() from django.conf import settings from met.metadataparser.utils import send_mail mail_config_dict = getattr(settings, "MAIL_CONFIG") m_subj = 'Email test' m_message = 'Body of the test email' send_mail(mail_config_dict['from_email_address'], m_subj, m_message)
# Current version of MET has been revised for performance improvements by Andrea Biancini, # Consortium GARR, http://www.garr.it ######################################################################################### import sys, os import logging.config os.environ['PYTHON_EGG_CACHE'] = '/tmp/.python-eggs/' current_directory = os.path.join(os.path.dirname(__file__), '..') activate_this = os.path.join(current_directory, '..', 'met-venv/bin/activate_this.py') execfile(activate_this, dict(__file__=activate_this)) sys.path.append(current_directory) sys.path.append(os.path.join(current_directory, 'met')) os.environ['DJANGO_SETTINGS_MODULE'] = 'met.settings' import django django.setup() from django.conf import settings from met.metadataparser.utils import send_mail mail_config_dict = getattr(settings, "MAIL_CONFIG") m_subj = 'Email test' m_message = 'Body of the test email' send_mail(mail_config_dict['from_email_address'], m_subj, m_message)