def index(request): request.session['premier'] = 1 request.session['now_see'] = 0 logger = logging.getLogger('log_to_file') statistic = {} for item in settings.META_INFO: statistic[item] = request.META.get(item, None) if request.user.is_anonymous(): static(statistic) else: static(statistic, request.user) logger.info(statistic) clips = Clips.objects.filter(is_deleted=False, moderated=True).order_by('date_create', 'views', 'count_comments', 'year').reverse() if request.method == 'GET': search = SearchForm(request.GET) if search.is_valid(): value = search.cleaned_data.get('search') if clips.filter(title__icontains=value).order_by('-title').count() > 0: clips = clips.filter(title__icontains=value).order_by('-title') paginator_clips = Paginator(clips, settings.PAGINATOR_PER_PAGE) if request.GET.get('page', None): current_page_clips = request.GET.get('page', 1) request.session['page'] = request.GET.get('page', 1) else: request.session['page'] = 1 current_page_clips = request.session.get('page', 1) try: clip = paginator_clips.page(current_page_clips) except PageNotAnInteger: clip = paginator_clips.page(1) except EmptyPage: clip = paginator_clips.page(paginator_clips.num_pages) request_params = copy(request.GET) if request_params.get('page'): del request_params['page'] return { 'pager_clips':clip, 'clips_items':clip.object_list, 'request_params': "&%s" % request_params.urlencode() if request_params.urlencode() else "", }
def favourites(request): logger = logging.getLogger('log_to_file') statistic = {} for item in settings.META_INFO: statistic[item] = request.META.get(item, None) if request.user.is_anonymous(): static(statistic) else: static(statistic, request.user) logger.info(statistic) request.session['premier'] = 0 request.session['now_see'] = 0 favourite_clips = FavouritesClips.objects.filter(user=request.user.id).order_by('-id', 'date_create') clips = [] for i in favourite_clips: clip = Clips.objects.get(id=i.clip) if clip.is_deleted == False: clips.append(clip) paginator_clips = Paginator(clips, settings.PAGINATOR_PER_PAGE) current_page_clips = request.GET.get('page', 1) try: clip = paginator_clips.page(current_page_clips) except PageNotAnInteger: clip = paginator_clips.page(1) except EmptyPage: clip = paginator_clips.page(paginator_clips.num_pages) request_params = copy(request.GET) if request_params.get('page'): del request_params['page'] return { 'pager_clips':clip, 'clips_items':clip.object_list, }
def clip(request, clip): request.session['premier'] = 0 request.session['now_see'] = 1 logger = logging.getLogger('log_to_file') statistic = {} for item in settings.META_INFO: statistic[item] = request.META.get(item, None) if request.user.is_anonymous(): static(statistic) else: static(statistic, request.user) logger.info(statistic) try: clip = Clips.objects.get(id=clip, is_deleted=False, moderated=True) clip.views += 1 clip.save() except Exception, e: logger.info(e) return HttpResponseRedirect('/')
def sort_clips(request, sort): request.session['premier'] = 0 request.session['now_see'] = 1 logger = logging.getLogger('log_to_file') statistic = {} for item in settings.META_INFO: statistic[item] = request.META.get(item, None) if request.user.is_anonymous(): static(statistic) else: static(statistic, request.user) logger.info(statistic) SORT = {'new':0, 'comments':1, 'views':2, 'recommended':3} if SORT.get(sort, '') == '': return HttpResponseRedirect('/') if sort == 'new': clips = Clips.objects.filter(is_deleted=False, moderated=True).order_by('-date_create')[:50] if sort == 'comments': clips = Clips.objects.filter(is_deleted=False, moderated=True).order_by('-count_comments')[:50] if sort == 'views': clips = Clips.objects.filter(is_deleted=False, moderated=True).order_by('-views')[:50] if sort == 'recommended': clips = Clips.objects.filter(is_deleted=False, moderated=True).order_by('?')[:10] if request.method == 'GET': search = SearchForm(request.GET) if search.is_valid(): value = search.cleaned_data.get('search') if clips.filter(title__icontains=value).order_by('-title').count() > 0: clips = clips.filter(title__icontains=value).order_by('-title') else: pass paginator_clips = Paginator(clips, settings.PAGINATOR_PER_PAGE) current_page_clips = request.GET.get('page', 1) try: clip = paginator_clips.page(current_page_clips) except PageNotAnInteger: clip = paginator_clips.page(1) except EmptyPage: clip = paginator_clips.page(paginator_clips.num_pages) request_params = copy(request.GET) if request_params.get('page'): del request_params['page'] return { 'sort':sort, 'pager_clips':clip, 'clips_items':clip.object_list, 'request_params': "&%s" % request_params.urlencode() if request_params.urlencode() else "", }