Exemple #1
0
Fichier : index.py Projet : melfo/s
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 "",
        }
Exemple #2
0
Fichier : index.py Projet : melfo/s
def all_premiers(request):

    request.session['premier'] = 0
    request.session['now_see'] = 0

    clips = Clips.objects.filter(premier=Clips.PREMIER_YES, is_deleted=False, moderated=True).order_by('date_create').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')
            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 {
        'pager_clips':clip,
        'clips_items':clip.object_list,
        'request_params': "&%s" %
                          request_params.urlencode() if request_params.urlencode() else "",
        }
Exemple #3
0
Fichier : index.py Projet : melfo/s
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 "",
        }
Exemple #4
0
Fichier : index.py Projet : melfo/s
        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('/')

    if request.method == 'GET':
        search = SearchForm(request.GET)
        if search.is_valid():
            value = search.cleaned_data.get('search')
            return HttpResponseRedirect('/?search=%s' % value)

    form = Comment()
    if request.method == 'POST':
        form = Comment(request.POST)
        if form.is_valid():
            comment = Comments.objects.create(
                clip_id = clip.id,
                author_id = request.user.id,
                text = form.cleaned_data.get('text'),
            )
            comment.save()
            clip.count_comments += 1
            clip.save()