def handle(self, *args, **options):
        from tendenci.apps.base.utils import send_email_notification
        from tendenci.apps.site_settings.utils import get_setting
        from tendenci.apps.directories.models import Directory

        # Query all events that are not yet marked for checking
        directories = Directory.objects.filter(renewal_notice_sent=False)

        days = get_setting('module', 'directories', 'renewaldays')
        days = int(days)

        for directory in directories:
            if datetime.now() + timedelta(days) > directory.expiration_dt:
                email_recipient = directory.creator.email
                print 'Sending email to %s for directory %s.' % (email_recipient, directory, )
                send_email_notification(
                    'directory_renewal_eligible',
                    email_recipient,
                    {
                    'directory': directory,
                    }
                )

                directory.renewal_notice_sent = True
                directory.save()
            else:
                print 'Directory %s not eligible for renewal right now.' % (directory, )
示例#2
0
def approve(request, id, template_name="directories/approve.html"):
    can_view_directories = has_perm(request.user, 'directories.view_directory')
    can_change_directories = has_perm(request.user, 'directories.change_directory')

    if not all([can_view_directories, can_change_directories]):
        raise Http403

    directory = get_object_or_404(Directory, pk=id)

    if request.method == "POST":
        directory.activation_dt = datetime.now()
        directory.expiration_dt = directory.activation_dt + timedelta(days=directory.requested_duration)
        directory.allow_anonymous_view = True
        directory.status = True
        directory.status_detail = 'active'

        if not directory.creator:
            directory.creator = request.user
            directory.creator_username = request.user.username

        if not directory.owner:
            directory.owner = request.user
            directory.owner_username = request.user.username

        directory.save()

        # send email notification to user
        recipients = [directory.creator.email]
        if recipients:
            extra_context = {
                'object': directory,
                'request': request,
            }
            try:
                send_email_notification('directory_approved_user_notice', recipients, extra_context)
            except:
                pass

        msg_string = 'Successfully approved %s' % directory
        messages.add_message(request, messages.SUCCESS, _(msg_string))

        return HttpResponseRedirect(reverse('directory', args=[directory.slug]))

    return render_to_response(template_name, {'directory': directory},
            context_instance=RequestContext(request))
示例#3
0
文件: views.py 项目: ediaz1/tendenci
def approve(request, id, template_name="jobs/approve.html"):
    can_view_jobs = has_perm(request.user, 'jobs.view_job')
    can_change_jobs = has_perm(request.user, 'jobs.change_job')

    if not all([can_view_jobs, can_change_jobs]):
        raise Http403

    job = get_object_or_404(Job, pk=id)

    if request.method == "POST":
        job.activation_dt = datetime.now()
        job.allow_anonymous_view = True
        job.status = True
        job.status_detail = 'active'

        if not job.creator:
            job.creator = request.user
            job.creator_username = request.user.username

        if not job.owner:
            job.owner = request.user
            job.owner_username = request.user.username

        job.save()

        # send email notification to user
        recipients = [job.creator.email]
        if recipients:
            extra_context = {
                'object': job,
                'request': request,
            }
            #try:
            send_email_notification(
                'job_approved_user_notice', recipients, extra_context)
            #except:
            #    pass
        msg_string = 'Successfully approved %s' % job
        messages.add_message(request, messages.SUCCESS, _(msg_string))

        return HttpResponseRedirect(reverse('job', args=[job.slug]))

    return render_to_response(template_name, {'job': job},
            context_instance=RequestContext(request))
    def handle(self, *args, **options):
        from tendenci.apps.base.utils import send_email_notification
        from tendenci.apps.site_settings.utils import get_setting
        from tendenci.apps.events.models import Event
        from tendenci.apps.events.utils import registration_has_recently_ended

        site_label = get_setting('site', 'global', 'sitedisplayname')
        site_url = get_setting('site', 'global', 'siteurl')
        admins = get_setting('module', 'events', 'admin_emails').split(',')
        email_list = [admin.strip() for admin in admins]

        # Query all events that are not yet marked for checking
        events = Event.objects.filter(mark_registration_ended=False)
        for event in events:
            if registration_has_recently_ended(event):
                # Calculate fees, number of participants, etc
                money_collected = event.money_collected
                money_outstanding = event.money_outstanding
                all_registrants = event.registrants()
                registrants_with_balance = event.registrants(with_balance=True)
                print 'Sending email to admins for event %s.' % (event, )
                send_email_notification(
                    'event_registration_end_recap',
                    email_list,
                    {
                        'SITE_GLOBAL_SITEDISPLAYNAME': site_label,
                        'SITE_GLOBAL_SITEURL': site_url,
                        'event': event,
                        'money_collected': money_collected,
                        'money_outstanding': money_outstanding,
                        'registrants_count': len(all_registrants),
                        'registrants_with_balance_count': len(registrants_with_balance),
                    }
                )
                print 'Message sent.'

                # Mark event as ended
                event.mark_registration_ended = True
                event.save()