コード例 #1
0
ファイル: models.py プロジェクト: aprildh31/tendenci
    def generate_newsletter_contents(self, request):
        simplified = True if self.format == 0 else False

        opening_txt = render_to_string(template_name='newsletters/opening_text.txt',
                                            request=request)

        footer_txt = render_to_string(template_name='newsletters/footer.txt',
                                            context={'newsletter': self },
                                            request=request)

        unsubscribe_txt = render_to_string(template_name='newsletters/newsletter_unsubscribe.txt',
                                            request=request)

        view_from_browser_txt = render_to_string(template_name='newsletters/view_from_browser.txt',
                                            request=request)

        login_content = ""
        if self.include_login:
            login_content = render_to_string(template_name='newsletters/login.txt',
                                             request=request)

        jumplink_content = ""
        if self.jump_links:
            jumplink_content = render_to_string(template_name='newsletters/jumplinks.txt', context=locals(),
                                                request=request)

        articles_content = ""
        articles_list =[]
        if self.articles:
            articles_list, articles_content = newsletter_articles_list(request, self.articles_days, simplified)

        news_content = ""
        news_list = []
        if self.news:
            news_list, news_content = newsletter_news_list(request, self.news_days, simplified)

        jobs_content = ""
        jobs_list = []
        if self.jobs:
            jobs_list, jobs_content = newsletter_jobs_list(request, self.jobs_days, simplified)

        pages_content = ""
        pages_list = []
        if self.pages:
            pages_list, pages_content = newsletter_pages_list(request, self.pages_days, simplified)

        directories_content = ""
        directories_list = []
        if self.directories:
            directories_list, directories_content = newsletter_directories_list(request, self.directories_days, simplified)

        resumes_content = ""
        resumes_list = []
        if self.resumes:
            resumes_list, resumes_content = newsletter_resumes_list(request, self.resumes_days, simplified)

        try:
            events_type = self.events_type
            events_list, events_content = newsletter_events_list(
                request,
                start_dt=self.event_start_dt,
                end_dt=self.event_end_dt,
                simplified=simplified)

        except ImportError:
            events_list = []
            events_type = None

        data = {
                'opening_text': opening_txt,
                'footer_text' : footer_txt,
                'unsubscribe_text': unsubscribe_txt,
                'browser_text': view_from_browser_txt,
                'login_content': login_content,
                'jumplink_content': jumplink_content,
                'articles_content': articles_content,
                'articles_list': articles_list,
                'news_content': news_content,
                'news_list': news_list,
                'jobs_content': jobs_content,
                'jobs_list': jobs_list,
                'pages_content': pages_content,
                'pages_list': pages_list,
                'directories_content': directories_content,
                'directories_list': directories_list,
                'resumes_content': resumes_content,
                'resumes_list': resumes_list,
                'events_list': events_list,
                'events_content': events_content,
                'events_type': events_type}

        return data
コード例 #2
0
ファイル: models.py プロジェクト: dco5/tendenci
    def generate_newsletter_contents(self, request):
        simplified = True if self.format == 0 else False

        opening_txt = render_to_string('newsletters/opening_text.txt',
                                            context_instance=RequestContext(request))

        footer_txt = render_to_string('newsletters/footer.txt',
                                            {'newsletter': self },
                                            context_instance=RequestContext(request))

        unsubscribe_txt = render_to_string('newsletters/newsletter_unsubscribe.txt',
                                            context_instance=RequestContext(request))

        view_from_browser_txt = render_to_string('newsletters/view_from_browser.txt',
                                            context_instance=RequestContext(request))

        login_content = ""
        if self.include_login:
            login_content = render_to_string('newsletters/login.txt',
                                             context_instance=RequestContext(request))

        jumplink_content = ""
        if self.jump_links:
            jumplink_content = render_to_string('newsletters/jumplinks.txt', locals(),
                                                context_instance=RequestContext(request))

        articles_content = ""
        articles_list =[]
        if self.articles:
            articles_list, articles_content = newsletter_articles_list(request, self.articles_days, simplified)

        news_content = ""
        news_list = []
        if self.news:
            news_list, news_content = newsletter_news_list(request, self.news_days, simplified)

        jobs_content = ""
        jobs_list = []
        if self.jobs:
            jobs_list, jobs_content = newsletter_jobs_list(request, self.jobs_days, simplified)

        pages_content = ""
        pages_list = []
        if self.pages:
            pages_list, pages_content = newsletter_pages_list(request, self.pages_days, simplified)

        directories_content = ""
        directories_list = []
        if self.directories:
            directories_list, directories_content = newsletter_directories_list(request, self.directories_days, simplified)

        resumes_content = ""
        resumes_list = []
        if self.resumes:
            resumes_list, resumes_content = newsletter_resumes_list(request, self.resumes_days, simplified)

        try:
            events_type = self.events_type
            events_list, events_content = newsletter_events_list(
                request,
                start_dt=self.event_start_dt,
                end_dt=self.event_end_dt,
                simplified=simplified)

        except ImportError:
            events_list = []
            events_type = None

        data = {
                'opening_text': opening_txt,
                'footer_text' : footer_txt,
                'unsubscribe_text': unsubscribe_txt,
                'browser_text': view_from_browser_txt,
                'login_content': login_content,
                'jumplink_content': jumplink_content,
                'articles_content': articles_content,
                'articles_list': articles_list,
                'news_content': news_content,
                'news_list': news_list,
                'jobs_content': jobs_content,
                'jobs_list': jobs_list,
                'pages_content': pages_content,
                'pages_list': pages_list,
                'directories_content': directories_content,
                'directories_list': directories_list,
                'resumes_content': resumes_content,
                'resumes_list': resumes_list,
                'events_list': events_list,
                'events_content': events_content,
                'events_type': events_type}

        return data
コード例 #3
0
ファイル: views.py プロジェクト: ZHW123/tendenci
def template_view(request, template_id, render=True):
    """
    Generate newsletter preview
    Combine template with context passed via GET
    """
    template = get_object_or_404(NewsletterTemplate, template_id=template_id)
    if not template.html_file:
        raise Http404

    if not has_perm(request.user, "newsletters.view_newslettertemplate"):
        raise Http403

    simplified = True
    login_content = ""
    include_login = int(request.GET.get("include_login", 0))
    if include_login:
        login_content = render_to_string("newsletters/login.txt", context_instance=RequestContext(request))

    jumplink_content = ""
    jump_links = int(request.GET.get("jump_links", 1))
    if jump_links:
        jumplink_content = render_to_string(
            "newsletters/jumplinks.txt", locals(), context_instance=RequestContext(request)
        )

    art_content = ""
    articles = int(request.GET.get("articles", 1))
    articles_days = request.GET.get("articles_days", 60)
    if articles:
        articles_list, articles_content = newsletter_articles_list(request, articles_days, simplified)
    else:
        articles_list = []
        articles_content = []

    news_content = ""
    news = int(request.GET.get("news", 1))
    news_days = request.GET.get("news_days", 30)
    if news:
        news_list, news_content = newsletter_news_list(request, news_days, simplified)
    else:
        news_list = []
        news_content = []

    jobs_content = ""
    jobs = int(request.GET.get("jobs", 1))
    jobs_days = request.GET.get("jobs_days", 30)
    if jobs:
        jobs_list, jobs_content = newsletter_jobs_list(request, jobs_days, simplified)
    else:
        jobs_list = []
        jobs_content = []

    pages_content = ""
    pages = int(request.GET.get("pages", 0))
    pages_days = request.GET.get("pages_days", 7)
    if pages:
        pages_list, pages_content = newsletter_pages_list(request, pages_days, simplified)
    else:
        pages_list = []
        pages_content = []

    directories_content = ""
    directories = int(request.GET.get("directories", 0))
    directories_days = request.GET.get("directories_days", 7)
    if directories:
        directories_list, directories_content = newsletter_directories_list(request, directories_days, simplified)
    else:
        directories_list = []
        directories_content = []

    resumes_content = ""
    resumes = int(request.GET.get("resumes", 0))
    resumes_days = request.GET.get("resumes_days", 7)
    if resumes:
        resumes_list, resumes_content = newsletter_resumes_list(request, resumes_days, simplified)
    else:
        resumes_list = []
        resumes_content = []

    try:
        events = int(request.GET.get("events", 1))
        events_type = request.GET.get("events_type")
        start_y, start_m, start_d = request.GET.get("event_start_dt", str(datetime.date.today())).split("-")
        event_start_dt = datetime.date(int(start_y), int(start_m), int(start_d))

        end_y, end_m, end_d = request.GET.get(
            "event_end_dt", str(datetime.date.today() + datetime.timedelta(days=90))
        ).split("-")
        event_end_dt = datetime.date(int(end_y), int(end_m), int(end_d))

        events_list, events_content = newsletter_events_list(
            request, start_dt=event_start_dt, end_dt=event_end_dt, simplified=simplified
        )

    except ImportError:
        events_list = []
        events_type = None

    text = DTemplate(apply_template_media(template))
    context = RequestContext(
        request,
        {
            "jumplink_content": jumplink_content,
            "login_content": login_content,
            "art_content": articles_content,  # legacy usage in templates
            "articles_content": articles_content,
            "articles_list": articles_list,
            "jobs_content": jobs_content,
            "jobs_list": jobs_list,
            "news_content": news_content,
            "news_list": news_list,
            "pages_content": pages_content,
            "pages_list": pages_content,
            "directories_content": directories_content,
            "directories_list": directories_list,
            "resumes_content": resumes_content,
            "resumes_list": resumes_list,
            "events": events_list,  # legacy usage in templates
            "events_content": events_content,
            "events_list": events_list,
            "events_type": events_type,
        },
    )
    content = text.render(context)

    if render:
        response = HttpResponse(content)
        return response
    else:
        template_name = "newsletters/content.html"
        return render_to_response(
            template_name, {"content": content, "template": template}, context_instance=RequestContext(request)
        )
コード例 #4
0
def template_view(request, template_id, render=True):
    """
    Generate newsletter preview
    Combine template with context passed via GET
    """
    template = get_object_or_404(NewsletterTemplate, template_id=template_id)
    if not template.html_file:
        raise Http404

    if not has_perm(request.user, 'newsletters.view_newslettertemplate'):
        raise Http403

    simplified = True
    login_content = ""
    include_login = int(request.GET.get('include_login', 0))
    if include_login:
        login_content = render_to_string(template_name='newsletters/login.txt',
                                         request=request)

    jumplink_content = ""
    jump_links = int(request.GET.get('jump_links', 1))
    if jump_links:
        jumplink_content = render_to_string(
            template_name='newsletters/jumplinks.txt',
            context=locals(),
            request=request)

    art_content = ""
    articles = int(request.GET.get('articles', 1))
    articles_days = request.GET.get('articles_days', 60)
    if articles:
        articles_list, articles_content = newsletter_articles_list(
            request, articles_days, simplified)
    else:
        articles_list = []
        articles_content = []

    news_content = ""
    news = int(request.GET.get('news', 1))
    news_days = request.GET.get('news_days', 30)
    if news:
        news_list, news_content = newsletter_news_list(request, news_days,
                                                       simplified)
    else:
        news_list = []
        news_content = []

    jobs_content = ""
    jobs = int(request.GET.get('jobs', 1))
    jobs_days = request.GET.get('jobs_days', 30)
    if jobs:
        jobs_list, jobs_content = newsletter_jobs_list(request, jobs_days,
                                                       simplified)
    else:
        jobs_list = []
        jobs_content = []

    pages_content = ""
    pages = int(request.GET.get('pages', 0))
    pages_days = request.GET.get('pages_days', 7)
    if pages:
        pages_list, pages_content = newsletter_pages_list(
            request, pages_days, simplified)
    else:
        pages_list = []
        pages_content = []

    directories_content = ""
    directories = int(request.GET.get('directories', 0))
    directories_days = request.GET.get('directories_days', 7)
    if directories:
        directories_list, directories_content = newsletter_directories_list(
            request, directories_days, simplified)
    else:
        directories_list = []
        directories_content = []

    resumes_content = ""
    resumes = int(request.GET.get('resumes', 0))
    resumes_days = request.GET.get('resumes_days', 7)
    if resumes:
        resumes_list, resumes_content = newsletter_resumes_list(
            request, resumes_days, simplified)
    else:
        resumes_list = []
        resumes_content = []

    try:
        events = int(request.GET.get('events', 1))
        events_type = request.GET.get('events_type')
        start_y, start_m, start_d = request.GET.get(
            'event_start_dt', str(datetime.date.today())).split('-')
        event_start_dt = datetime.date(int(start_y), int(start_m),
                                       int(start_d))

        end_y, end_m, end_d = request.GET.get(
            'event_end_dt',
            str(datetime.date.today() +
                datetime.timedelta(days=90))).split('-')
        event_end_dt = datetime.date(int(end_y), int(end_m), int(end_d))

        events_list, events_content = newsletter_events_list(
            request,
            start_dt=event_start_dt,
            end_dt=event_end_dt,
            simplified=simplified)

    except ImportError:
        events_list = []
        events_type = None

    text = engines['django'].from_string(apply_template_media(template))
    context = {
        'jumplink_content': jumplink_content,
        'login_content': login_content,
        "art_content": articles_content,  # legacy usage in templates
        "articles_content": articles_content,
        "articles_list": articles_list,
        "jobs_content": jobs_content,
        "jobs_list": jobs_list,
        "news_content": news_content,
        "news_list": news_list,
        "pages_content": pages_content,
        "pages_list": pages_content,
        "directories_content": directories_content,
        "directories_list": directories_list,
        "resumes_content": resumes_content,
        "resumes_list": resumes_list,
        "events": events_list,  # legacy usage in templates
        "events_content": events_content,
        "events_list": events_list,
        "events_type": events_type
    }
    content = text.render(context=context, request=request)

    if render:
        response = HttpResponse(content)
        return response
    else:
        template_name = "newsletters/content.html"
        return render_to_resp(request=request,
                              template_name=template_name,
                              context={
                                  'content': content,
                                  'template': template
                              })
コード例 #5
0
ファイル: views.py プロジェクト: BIGGANI/tendenci
def template_html(request, template_id):
    template = get_object_or_404(Template, template_id=template_id)

    if not template.html_file:
        raise Http404

    simplified = True

    login_content = ""
    include_login = request.GET.get('include_login', False)
    if include_login:
        login_content = render_to_string('newsletters/login.txt',
                                        context_instance=RequestContext(request))

    jumplink_content = ""
    jump_links = request.GET.get('jump_links', 1)
    if jump_links:
        jumplink_content = render_to_string('newsletters/jumplinks.txt', locals(),
                                        context_instance=RequestContext(request))

    art_content = ""
    articles = request.GET.get('articles', 1)
    articles_days = request.GET.get('articles_days', 60)
    if articles:
        articles_list, articles_content = newsletter_articles_list(request, articles_days, simplified)

    news_content = ""
    news = request.GET.get('news', 1)
    news_days = request.GET.get('news_days',30)
    if news:
        news_list, news_content = newsletter_news_list(request, news_days, simplified)

    jobs_content = ""
    jobs = request.GET.get('jobs', 1)
    jobs_days = request.GET.get('jobs_days', 30)
    if jobs:
        jobs_list, jobs_content = newsletter_jobs_list(request, jobs_days, simplified)

    pages_content = ""
    pages = request.GET.get('pages', 0)
    pages_days = request.GET.get('pages_days', 7)
    if pages:
        pages_list, pages_content = newsletter_pages_list(request, pages_days, simplified)
    try:
        from tendenci.apps.events.models import Event, Type
        events = request.GET.get('events', 1)
        events_type = request.GET.get('events_type')
        start_y, start_m, start_d = request.GET.get('event_start_dt', str(datetime.date.today())).split('-')
        event_start_dt = datetime.date(int(start_y), int(start_m), int(start_d))
        end_y, end_m, end_d = request.GET.get('event_end_dt', str(datetime.date.today() + datetime.timedelta(days=90))).split('-')
        event_end_dt = datetime.date(int(end_y), int(end_m), int(end_d))
        if events:
            #events_list = Event.objects.filter(start_dt__lt=event_end_dt, end_dt__gt=event_start_dt, status_detail='active', status=True, allow_anonymous_view=True)
            events_list = Event.objects.filter(start_dt__gte=event_start_dt,
                                               start_dt__lt=event_end_dt,
                                               status_detail='active',
                                               status=True,
                                               allow_anonymous_view=True)
            if events_type:
                events_list = events_list.filter(type__pk=events_type)
                events_type = Type.objects.filter(pk=events_type)[0]
            events_list = events_list.order_by('start_dt')
    except ImportError:
        events_list = []
        events_type = None

    text = DTemplate(apply_template_media(template))
    context = RequestContext(request,
            {
                'jumplink_content':jumplink_content,
                'login_content':login_content,
                "art_content":articles_content, # legacy usage in templates
                "articles_content":articles_content,
                "articles_list":articles_list,
                "jobs_content":jobs_content,
                "jobs_list":jobs_list,
                "news_content":news_content,
                "news_list":news_list,
                "pages_content":pages_content,
                "pages_list":pages_content,
                "events":events_list, # legacy usage in templates
                "events_list":events_list,
                "events_type":events_type
            })

    response = HttpResponse(text.render(context))
    response['Content-Disposition'] = 'attachment; file=page.html'

    return response
コード例 #6
0
ファイル: views.py プロジェクト: cwint3/rundownthedemons
def template_html(request, template_id):
    template = get_object_or_404(Template, template_id=template_id)

    if not template.html_file:
        raise Http404

    simplified = True

    login_content = ""
    include_login = request.GET.get('include_login', False)
    if include_login:
        login_content = render_to_string(
            'newsletters/login.txt', context_instance=RequestContext(request))

    jumplink_content = ""
    jump_links = request.GET.get('jump_links', 1)
    if jump_links:
        jumplink_content = render_to_string(
            'newsletters/jumplinks.txt',
            locals(),
            context_instance=RequestContext(request))

    art_content = ""
    articles = request.GET.get('articles', 1)
    articles_days = request.GET.get('articles_days', 60)
    if articles:
        articles_list, articles_content = newsletter_articles_list(
            request, articles_days, simplified)

    news_content = ""
    news = request.GET.get('news', 1)
    news_days = request.GET.get('news_days', 30)
    if news:
        news_list, news_content = newsletter_news_list(request, news_days,
                                                       simplified)

    jobs_content = ""
    jobs = request.GET.get('jobs', 1)
    jobs_days = request.GET.get('jobs_days', 30)
    if jobs:
        jobs_list, jobs_content = newsletter_jobs_list(request, jobs_days,
                                                       simplified)

    pages_content = ""
    pages = request.GET.get('pages', 0)
    pages_days = request.GET.get('pages_days', 7)
    if pages:
        pages_list, pages_content = newsletter_pages_list(
            request, pages_days, simplified)
    try:
        from tendenci.apps.events.models import Event, Type
        events = request.GET.get('events', 1)
        events_type = request.GET.get('events_type')
        start_y, start_m, start_d = request.GET.get(
            'event_start_dt', str(datetime.date.today())).split('-')
        event_start_dt = datetime.date(int(start_y), int(start_m),
                                       int(start_d))
        end_y, end_m, end_d = request.GET.get(
            'event_end_dt',
            str(datetime.date.today() +
                datetime.timedelta(days=90))).split('-')
        event_end_dt = datetime.date(int(end_y), int(end_m), int(end_d))
        if events:
            #events_list = Event.objects.filter(start_dt__lt=event_end_dt, end_dt__gt=event_start_dt, status_detail='active', status=True, allow_anonymous_view=True)
            events_list = Event.objects.filter(start_dt__gte=event_start_dt,
                                               start_dt__lt=event_end_dt,
                                               status_detail='active',
                                               status=True,
                                               allow_anonymous_view=True)
            if events_type:
                events_list = events_list.filter(type__pk=events_type)
                events_type = Type.objects.filter(pk=events_type)[0]
            events_list = events_list.order_by('start_dt')
    except ImportError:
        events_list = []
        events_type = None

    text = DTemplate(apply_template_media(template))
    context = RequestContext(
        request,
        {
            'jumplink_content': jumplink_content,
            'login_content': login_content,
            "art_content": articles_content,  # legacy usage in templates
            "articles_content": articles_content,
            "articles_list": articles_list,
            "jobs_content": jobs_content,
            "jobs_list": jobs_list,
            "news_content": news_content,
            "news_list": news_list,
            "pages_content": pages_content,
            "pages_list": pages_content,
            "events": events_list,  # legacy usage in templates
            "events_list": events_list,
            "events_type": events_type
        })

    response = HttpResponse(text.render(context))
    response['Content-Disposition'] = 'attachment; file=page.html'

    return response