def features(request, content, page=1): """ This renders the features list page. """ try: key = [key for key, val in Feature.FEATURES if val == content][0] except IndexError: raise Http404 if request.user.is_authenticated(): feature_list = Feature.qa_objects.filter( content_type=key).order_by('-posting_time') else: feature_list = Feature.objects.filter( content_type=key).order_by('-posting_time') paginator = DiggPaginator(feature_list, ARTICLES_PER_PAGE) try: features = paginator.page(page) except (EmptyPage, InvalidPage): features = paginator.page(paginator.num_pages) ctx = { 'page': features, 'content': content, 'url': '/features/%s/' % content, } template = 'articles/%s_list.html' % content.lower() return render(request, template, ctx)
def index(request, news_type, page=1): """ This renders the article index page. """ topic = None if news_type == 'all': objects = Article.objects.order_by('-posting_time') elif news_type in ('Webscout', 'News', 'FDA Approvals'): objects = Article.objects.filter(news_type=news_type).order_by('-posting_time') else: try: topic = Topic.objects.get(topic_name=news_type) except Topic.DoesNotExist: raise Http404 except Topic.MultipleObjectsReturned: for topic in Topic.objects.filter(topic_name=news_type): if len(topic.article_set.all()) > 0: break objects = Article.objects.filter(topics__topic_name=news_type).order_by('-posting_time') category = None if request.GET.get('category'): try: category = Category.objects.get(pk=request.GET['category']) objects = objects.filter(topics__in=category.topics.all()).distinct() except Category.DoesNotExist: objects = [] fyi = Article.objects.filter(news_type='FYI').order_by('-posting_time')[:5] categories = Category.objects.order_by('category') paginator = DiggPaginator(objects, ARTICLES_PER_PAGE) try: articles = paginator.page(page) except (EmptyPage, InvalidPage): articles = paginator.page(paginator.num_pages) url = None if category: url = '/healthday/all/' if news_type: url = '/healthday/%s/' % news_type ctx = { 'fyi': fyi, 'categories': categories, 'news_type': news_type, 'category': category, 'topic': topic, 'url': url, 'page': articles, } return render_to_response('articles/healthday-index.html', ctx , context_instance=RequestContext(request))
def news_by_category(request, category_pk, template, url, page=1, contentpath=None): category = Category.objects.get(pk=category_pk) news_list = Article.objects.filter(topics__in=category.topics.all()).order_by('-posting_time').distinct() paginator = DiggPaginator(news_list, ARTICLES_PER_PAGE) # get service content try: page_obj = Page.objects.get(urlname=contentpath) content = page_obj.content except Page.DoesNotExist: content = '' try: news = paginator.page(page) except (EmptyPage, InvalidPage): news = paginator.page(paginator.num_pages) return render(request, template, {'page':news, 'url':url, 'content': content})
def mediaresults_list(request, page=1): """ display all active mediaresults """ template = 'articles/newsroom/mediaresults_list.html' if request.user.is_authenticated(): articles = MediaResult.qa_objects.all().order_by('-posting_time') else: articles = MediaResult.objects.all().order_by('-posting_time') paginator = DiggPaginator(articles, ARTICLES_PER_PAGE) try: paged_articles = paginator.page(page) except (EmptyPage, InvalidPage): paged_articles = paginator.page(paginator.num_pages) ctx = { 'page': paged_articles, 'url': '/recentcoverage/', } return render(request, template, ctx)
def recipes(request, page=1): """ This renders the recipe list page. """ if request.user.is_authenticated(): recipe_list = Recipe.qa_objects.all().order_by('-posting_time') else: recipe_list = Recipe.objects.all().order_by('-posting_time') paginator = DiggPaginator(recipe_list, ARTICLES_PER_PAGE) try: recipes = paginator.page(page) except (EmptyPage, InvalidPage): recipes = paginator.page(paginator.num_pages) ctx = { 'page': recipes, } template = 'articles/recipe_list.html' return render(request, template, ctx)
def index(request, page=1): """ This renders the article index page. """ if request.user.is_authenticated(): articles = Article.qa_objects.exclude( leader_promo__gt=0).order_by('-posting_time') else: articles = Article.objects.exclude( leader_promo__gt=0).order_by('-posting_time') paginator = DiggPaginator(articles, ARTICLES_PER_PAGE) try: paged_articles = paginator.page(page) except (EmptyPage, InvalidPage): paged_articles = paginator.page(paginator.num_pages) ctx = { 'page': paged_articles, 'url': '/articles/', } return render(request, 'articles/articles.html', ctx)
def search_full(request, model, page=1): """ Return results for a sidewide search. """ try: query = request.REQUEST['search-input'] except KeyError: query = '' if model == 'smg.smgnews': (count1, results1) = search(0, 'complete', 'articles.Article', 'alpha', query, query) (count2, results2) = search(0, 'complete', 'articles.PressRelease', 'alpha', query, query) count = count1 + count2 results = results1 + results2 elif model == 'smg.feature': (count1, results1) = search(0, 'complete', 'articles.Feature', 'alpha', query, query) (count2, results2) = search(0, 'complete', 'articles.Recipe', 'alpha', query, query) count = count1 + count2 results = results1 + results2 elif model == 'smg.events': (count1, results1) = search(0, 'complete', 'events.Event', 'alpha', query, query) (count2, results2) = search(0, 'complete', 'events.Class', 'alpha', query, query) count = count1 + count2 results = results1 + results2 elif model == 'smg.article': (count, results) = search(0, 'complete', 'articles.Article', 'alpha', query, query) elif model == 'smg.page': (count, results) = search(0, 'complete', 'pages.Page', 'alpha', query, query) else: (count, results) = search(0, 'complete', model, 'alpha', query, query) filtered = {} newresults = [] for result in results: if result.url in filtered: continue filtered[result.url] = True newresults.append(result) results = newresults result_data = dict() # [Limit, Keys, Count, More, Order, Pretty_name] if 'CAREER' in query.upper() or 'JOB' in query.upper(): count = str(int(count) + 1) results.append(Result(['Keyword', '', '/careers/', 'Careers'])) if (query.upper().startswith('LOC') or query.upper().startswith('HOU') or query.upper().startswith('DIR') or query.upper().startswith('OPE')): try: count = str(int(count) + 1) except ValueError: raise Http404 results.append( Result([ 'Keyword', '', '/locations/', 'Locations, Directions, and Hours' ])) if (query.upper().startswith('PORT') or query.upper().startswith('ONLI')): try: count = str(int(count) + 1) except ValueError: raise Http404 for result in results: if result.model == 'articles.PressRelease': result.model = 'smg.smgnews' result.limit = 10 if result.model == 'articles.Article': result.model = 'smg.smgnews' result.limit = 10 if result.model == 'articles.Feature': result.model = 'smg.feature' result.limit = 10 if result.model == 'articles.Recipe': result.model = 'smg.feature' result.limit = 10 if result.model == 'events.Event' or result.model == 'events.Class': result.model = 'smg.events' result.limit = 10 try: limit = result_data[result.model][0] except KeyError: if result.model == 'Keyword': continue omodel = model result_data[result.model] = [ None, [], 0, False, 0, 'Top Matches' ] else: (app_name, model_name) = result.model.split('.') omodel = models.get_model(app_name, model_name) try: limit = omodel.search_limit except AttributeError: limit = None if result.model == 'smg.smgnews': display_name = 'Summit Medical Group Articles and Pages' result_data[result.model] = [ limit, [], 0, False, 8, display_name ] elif result.model == 'smg.events': display_name = 'Events and Classes' result_data[result.model] = [ limit, [], 0, False, 4, display_name ] elif result.model == 'smg.feature': display_name = 'Fitness, Nutrition, and Recipes' result_data[result.model] = [ limit, [], 0, False, 7, display_name ] elif result.model == 'doctors.Doctor': display_name = 'Doctors' result_data[result.model] = [ limit, [], 0, False, 1, display_name ] else: display_name = force_unicode( capfirst(omodel._meta.verbose_name_plural)) result_data[result.model] = [ limit, [], 0, False, omodel.search_order, display_name ] result_data[result.model][1].append(result) result_data[result.model][2] += 1 result_groups = [ ResultGroup(key, result_data[key][3], result_data[key][4], result_data[key][1], result_data[key][5]) for key in result_data.keys() ] if not result_groups: raise Http404 result_groups.sort(lambda x, y: x.order - y.order) if result_groups[0].name == 'Keyword': paged_results = result_groups[1] else: paged_results = result_groups[0] paginator = DiggPaginator(paged_results.results, RESULTS_PER_PAGE) try: pages = paginator.page(page) except (EmptyPage, InvalidPage): pages = paginator.page(paginator.num_pages) ctx = { 'query': query, 'model': model, 'display_name': display_name, 'result_groups': result_groups, 'page': pages, 'url': '/search/%s/' % paged_results.name, } return render(request, 'search/results.html', ctx)