def post(self, request, *args, **kwargs): project_obj = get_object_or_404(Project, pk=self.kwargs.get('pk')) project_review_form = ProjectReviewForm(project_obj.pk, request.POST) project_review_status_choice = ProjectReviewStatusChoice.objects.get( name='Pending') if project_review_form.is_valid(): form_data = project_review_form.cleaned_data project_review_obj = ProjectReview.objects.create( project=project_obj, reason_for_not_updating_project=form_data.get('reason'), status=project_review_status_choice) project_obj.force_review = False project_obj.save() domain_url = get_domain_url(self.request) url = '{}{}'.format(domain_url, reverse('project-review-list')) if EMAIL_ENABLED: send_email_template( 'New project review has been submitted', 'email/new_project_review.txt', {'url': url}, EMAIL_SENDER, [EMAIL_DIRECTOR_EMAIL_ADDRESS, ] ) messages.success(request, 'Project reviewed successfully.') return HttpResponseRedirect(reverse('project-detail', kwargs={'pk': project_obj.pk})) else: messages.error( request, 'There was an error in processing your project review.') return HttpResponseRedirect(reverse('project-detail', kwargs={'pk': project_obj.pk}))
def post(self, request): if EMAIL_ENABLED: send_email_template('Upgrade Account Request', 'email/upgrade_account_request.txt', {'user': request.user}, request.user.email, [EMAIL_TICKET_SYSTEM_ADDRESS]) messages.success(request, 'Your request has been sent') return HttpResponseRedirect(reverse('user-profile'))
def send_expiry_emails(): # Subscriptions expiring for days_remaining in sorted(set(EMAIL_SUBSCRIPTION_EXPIRING_NOTIFICATION_DAYS)): expring_in_days = datetime.datetime.today( ) + datetime.timedelta(days=days_remaining) for subscription_obj in Subscription.objects.filter(status__name='Active', end_date=expring_in_days): expire_notification = subscription_obj.subscriptionattribute_set.filter( subscription_attribute_type__name='EXPIRE NOTIFICATION').first() if expire_notification and expire_notification.value == 'No': continue subscripion_renew_url = '{}/{}/{}/{}'.format( CENTER_BASE_URL.strip('/'), 'subscription', subscription_obj.pk, 'renew') resource_name = subscription_obj.get_parent_resource.name template_context = { 'center_name': CENTER_NAME, 'subscription_type': resource_name, 'expring_in_days': days_remaining, 'subscripion_renew_url': subscripion_renew_url, 'project_renewal_help_url': CENTER_PROJECT_RENEWAL_HELP_URL, 'opt_out_instruction_url': EMAIL_OPT_OUT_INSTRUCTION_URL, 'signature': EMAIL_SIGNATURE } email_receiver_list = [] for subscription_user in subscription_obj.project.projectuser_set.all(): if (subscription_user.enable_notifications and subscription_obj.subscriptionuser_set.filter( user=subscription_user.user, status__name='Active') and subscription_user.user.email not in email_receiver_list): email_receiver_list.append(subscription_user.user.email) send_email_template('Subscription to {} expiring in {} days'.format(resource_name, days_remaining), 'email/subscription_expiring.txt', template_context, EMAIL_SENDER, email_receiver_list ) logger.info('Subscription to {} expiring in {} days email sent to PI {}.'.format( resource_name, days_remaining, subscription_obj.project.pi.username)) # Subscriptions expiring today today = datetime.datetime.now().strftime('%Y-%m-%d') for subscription_attribute in SubscriptionAttribute.objects.filter( value=today, subscription_attribute_type__name='send_expiry_email_on_date'): subscription_obj = subscription_attribute.subscription days_remaining = subscription_obj.expires_in subscripion_renew_url = '{}/{}/{}/{}'.format( CENTER_BASE_URL.strip('/'), 'subscription', subscription_obj.pk, 'renew') resource_name = subscription_obj.get_parent_resource.name template_context = { 'center_name': CENTER_NAME, 'subscription_type': resource_name, 'expring_in_days': days_remaining, 'subscripion_renew_url': subscripion_renew_url, 'project_renewal_help_url': CENTER_PROJECT_RENEWAL_HELP_URL, 'opt_out_instruction_url': EMAIL_OPT_OUT_INSTRUCTION_URL, 'signature': EMAIL_SIGNATURE } email_receiver_list = [] for subscription_user in subscription_obj.project.projectuser_set.all(): if (subscription_user.enable_notifications and subscription_obj.subscriptionuser_set.filter( user=subscription_user.user, status__name='Active') and subscription_user.user.email not in email_receiver_list): email_receiver_list.append(subscription_user.user.email) send_email_template('Subscription to {} expiring in {} days'.format(resource_name, days_remaining), 'email/subscription_expiring.txt', template_context, EMAIL_SENDER, email_receiver_list ) logger.info('Subscription to {} expiring in {} days email sent to PI {}.'.format( resource_name, days_remaining, subscription_obj.project.pi.username)) # Expired subscriptions expring_in_days = datetime.datetime.today() + datetime.timedelta(days=-1) for subscription_obj in Subscription.objects.filter(end_date=expring_in_days): expire_notification = subscription_obj.subscriptionattribute_set.filter( subscription_attribute_type__name='EXPIRE NOTIFICATION').first() if expire_notification and expire_notification.value == 'No': continue resource_name = subscription_obj.get_parent_resource.name subscripion_renew_url = '{}/{}/{}/{}'.format( CENTER_BASE_URL.strip('/'), 'subscription', subscription_obj.pk, 'renew') project_url = '{}/{}/{}/'.format(CENTER_BASE_URL.strip('/'), 'project', subscription_obj.project.pk) template_context = { 'center_name': CENTER_NAME, 'subscription_type': resource_name, 'project_renewal_help_url': CENTER_PROJECT_RENEWAL_HELP_URL, 'project_url': project_url, 'opt_out_instruction_url': EMAIL_OPT_OUT_INSTRUCTION_URL, 'signature': EMAIL_SIGNATURE } email_receiver_list = [] for subscription_user in subscription_obj.project.projectuser_set.all(): if (subscription_user.enable_notifications and subscription_obj.subscriptionuser_set.filter( user=subscription_user.user, status__name='Active') and subscription_user.user.email not in email_receiver_list): email_receiver_list.append(subscription_user.user.email) send_email_template('Subscription to {} has expired'.format(resource_name), 'email/subscription_expired.txt', template_context, EMAIL_SENDER, email_receiver_list ) logger.info('Subscription to {} expired email sent to PI {}.'.format( resource_name, subscription_obj.project.pi.username))