예제 #1
0
파일: views.py 프로젝트: faalin/financesys
 def get(self, request, *args, **kwargs):
     key = u'最新新闻展示'
     news = Data.objects().order_by("-release_time")
     try:
         article_list = pages(request, news)
     except Exception as e:
         print e
         raise Http404("news error")
     return render(request, 'index.html', {"article_list": article_list, "key": key})
예제 #2
0
파일: views.py 프로젝트: faalin/financesys
 def get(self, request, *args, **kwargs):
     key = u'最新重要新闻展示'
     important_news = Data.objects.all().order_by('-release_time')
     impt_news = []
     for important_new in important_news:
         if important_new.relationship == 2:
             impt_news.append(important_new)
     try:
         article_list = pages(request, impt_news)
     except Exception as e:
         print e
         return render(request, 'failure.html', {"reason": u"没有相关新闻"})
     return render(request, 'index.html', {"article_list": article_list, "key": key})
예제 #3
0
파일: views.py 프로젝트: faalin/financesys
 def get(self, request, *args, **kwargs):
     this_month = datetime.datetime(int(year), int(month) + 1, 1)
     last_month = datetime.datetime(int(year), int(month), 1)
     archive_last_months = Data.objects(release_time__gte=last_month, release_time__lt=this_month)
     impt_news = []
     for important_new in archive_last_months:
         if important_new.relationship == 2:
             impt_news.append(important_new)
     try:
         article_list = pages(request, impt_news)
     except Exception as e:
         print e
         raise Http404("news error")
     return render(request, 'archive.html', {"article_list": article_list})
예제 #4
0
파일: views.py 프로젝트: faalin/financesys
    def get(self, request, *args, **kwargs):
        key = u'关键词搜索展示'
        content_get = request.GET.get('keywords').split()
        content = ''.join(content_get)
        article_list = []
        if content:
            keywords = jieba.cut_for_search(content)
            for keyword in keywords:
                match = {'$or': [{"title": {"$regex": keyword}}, {"content": {"$regex": keyword}}]}
                article_list.append(match)
        article_list_sort = Data.objects(__raw__={'$and': article_list}).order_by('-release_time')
        try:
            article_list = pages(request, article_list_sort)
        except Exception as e:
            print e
            return redirect('/home/')

        return render(request, 'index.html', {"article_list": article_list, "key": key})
예제 #5
0
파일: views.py 프로젝트: faalin/financesys
    def get(self, request, *args, **kwargs):
        key = u'24小时内新闻浏览量排行展示'
        show_news = Data.objects.order_by("-release_time")
        # 浏览量排行
        data = []
        for page_view in show_news:
            release_times = page_view.release_time
            TimeArray = time.strptime(str(release_times), "%Y-%m-%d %H:%M:%S")
            timestamp = int(1000 * (time.mktime(TimeArray)))
            if timestamp > now - 43200000 and timestamp < now:
                data.append(page_view)

        page_view_sort = sorted(data, key=lambda n: n['page_view'])
        page_view_todays = page_view_sort[::-1]
        try:
            article_list = pages(request, page_view_todays)
        except Exception as e:
            print e
            return render(request, 'failure.html', {"reason": u"没有相关新闻"})
        return render(request, 'index.html', {"article_list": article_list, "key": key})