def get(self, request): print 'testsetestestsetestsstest' util = Util() send_messages = SendMessageRecord.objects.order_by('-add_time') writings = WritingsRecord.objects.filter(type='from_others') new_articles = ArticlesRecord.objects.order_by('-add_time')[:5] head_images = PhotoShowRecord.objects.filter(image_type='headImg') try: writings = util.selectData( datas = writings, data_len = writings.count(), select_len = 1 )[0] except: writings = None try: head_images = util.selectData( datas = head_images, data_len = head_images.count(), select_len = 5 ) except: head_images = None try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 ignore_page_operation = IgnorePageOperation(int(page), int(math.ceil(send_messages.count() / 4.0))) pre_ignore_page, next_ignore_page = ignore_page_operation.getIgnorePage() p = Paginator(send_messages, 4, request=request) send_messages = p.page(page) try: head_image = head_images[0] except: head_image = None return render(request, 'message.html', { 'active': 'message', 'send_messages': send_messages, 'writings': writings, 'new_articles': new_articles, 'head_images': head_images, 'top_headImage': head_image, 'pre_ignore_page': pre_ignore_page, 'next_ignore_page': next_ignore_page })
def get(self, request): util = Util() photo_shows = PhotoShowRecord.objects.filter(image_type='photos') try: photo_shows = util.selectData(datas=photo_shows, data_len=photo_shows.count(), select_len=12) colors = [ 'shadow-blue', 'shadow-yellow', 'shadow-orangered', 'shadow-red', 'shadow-green' ] tmp_photo_shows = [] for photo_show in photo_shows: index = random.randint(0, 4) photo_show = {'photo_show': photo_show, 'color': colors[index]} tmp_photo_shows.append(photo_show) except: tmp_photo_shows = None return render(request, 'photos.html', { 'tmp_photo_shows': tmp_photo_shows, 'active': 'photos', })
def get(self, request): util = Util() try: sort = ArticleSortRecord.objects.filter(name='Feelings')[0] except: sort = None articles = ArticlesRecord.objects.order_by('-add_time') new_articles = articles[:5] articles = articles.filter(sort=sort) scenery_images = PhotoShowRecord.objects.filter(image_type='scenery') try: scenery_images = util.selectData(datas=scenery_images, data_len=scenery_images.count(), select_len=2) except: scenery_images = None try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 p = Paginator(articles, 6, request=request) articles = p.page(page) return render( request, 'feelings.html', { 'active': 'feelings', 'articles': articles, 'article_sort': sort, 'scenery_images': scenery_images, 'new_articles': new_articles })
def get(self, request): util = Util() photo_shows = PhotoShowRecord.objects.filter(image_type='banner') photo_shows = util.selectData( datas = photo_shows, data_len = photo_shows.count(), select_len = 5 ) writing_image = PhotoShowRecord.objects.filter(image_type='scenery') try: writing_image = util.selectData( datas = writing_image, data_len = writing_image.count(), select_len = 1 )[0] except: writing_image = None articles = ArticlesRecord.objects.order_by('-add_time')[:5] try: about_me = AboutMeRecord.objects.get(id=1) except: about_me = None try: writing = WritingsRecord.objects.filter(type='from_me') writing = writing.order_by('-add_time')[0] except: writing = None links = LinksRecord.objects.all() return render(request, 'index.html', { 'active': 'home', 'photo_shows': photo_shows, 'articles': articles, 'about_me': about_me, 'writing': writing, 'links': links, 'writing_image': writing_image })
def get_total_html(self, request): util = Util() article_sorts = ArticleSortRecord.objects.all() articles = ArticlesRecord.objects.order_by('-add_time') try: about_me = AboutMeRecord.objects.get(id=1) except: about_me = None new_articles = articles[:5] try: feelings_sort = article_sorts.get(name='Feelings') except: feelings_sort = None article_sorts = article_sorts.filter(~Q(name='Feelings')) articles = articles.filter(~Q(sort=feelings_sort)) colors = [ 'article-class-btn-color-1', 'article-class-btn-color-2', 'article-class-btn-color-3', 'article-class-btn-color-4' ] article_sorts = util.selectData(datas=article_sorts, data_len=article_sorts.count(), select_len=article_sorts.count()) tmp_article_sorts = [] try: for article_sort in article_sorts: index = random.randint(0, 3) tmp_article_sort = { 'article_sort': article_sort, 'color': colors[index] } tmp_article_sorts.append(tmp_article_sort) except: tmp_article_sorts = [] try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 p = Paginator(articles, 5, request=request) articles = p.page(page) return render( request, 'study.html', { 'active': 'study', 'tmp_article_sorts': tmp_article_sorts, 'articles': articles, 'about_me': about_me, 'new_articles': new_articles })
def get(self, request): util = Util() try: article_id = request.GET.get('id', 1) except: article_id = 1 try: send_sort = request.GET.get('sort', 0) except: send_sort = 0 articles = ArticlesRecord.objects.order_by('-add_time') new_articles = articles[:5] article = articles.get(id=int(article_id)) comments = SendCommentRecord.objects.filter(from_article=article) comments = comments.order_by('-add_time') writing = WritingsRecord.objects.filter(type='from_others') try: writing = util.selectData(datas=writing, data_len=writing.count(), select_len=1)[0] except: writing = None article_sorts = ArticleSortRecord.objects.all() feelings_sort = article_sorts.get(name='Feelings') article_sort = ArticleSortRecord.objects.get(name=article.sort) article_sorts = util.selectData(datas=article_sorts, data_len=article_sorts.count(), select_len=4) tmp_article_sorts = [] colors = [ 'btn article-class-btn-color-1', 'btn article-class-btn-color-2', 'btn article-class-btn-color-3', 'btn article-class-btn-color-4' ] for _sort in article_sorts: index = random.randint(0, 3) tmp_article_sort = {'article_sort': _sort, 'color': colors[index]} tmp_article_sorts.append(tmp_article_sort) if send_sort == 0 and article_sort.name != 'Feelings': articles = articles.filter(~Q(sort=feelings_sort)) pre_article, next_article = self.get_pre_next( articles, article.add_time) else: pre_article, next_article = self.get_pre_next( articles.filter(sort=article_sort), article.add_time) try: page = request.GET.get('page', 1) except PageNotAnInteger: page = 1 ignore_page_operation = IgnorePageOperation( int(page), int(math.ceil(comments.count() / 3.0))) pre_ignore_page, next_ignore_page = ignore_page_operation.getIgnorePage( ) p = Paginator(comments, 3, request=request) comments = p.page(page) head_images = PhotoShowRecord.objects.filter(image_type='headImg') head_images = util.selectData(datas=head_images, data_len=head_images.count(), select_len=5) try: head_image = head_images[0] except: head_image = None return render( request, 'article.html', { 'active': 'study', 'article': article, 'comments': comments, 'pre_article': pre_article, 'next_article': next_article, 'writing': writing, 'tmp_article_sorts': tmp_article_sorts, 'new_articles': new_articles, 'send_sort': send_sort, 'article_sort': article_sort, 'not_feelings': article_sort.name != 'Feelings', 'head_images': head_images, 'first_image': head_image, 'pre_ignore_page': pre_ignore_page, 'next_ignore_page': next_ignore_page })