예제 #1
0
파일: views.py 프로젝트: svabis/servax
def galery_main(request, pageid=1):
    args = galery_default(request)
    images = args['images']

    pagecount = int(math.ceil( int(images.count()) / float( img_on_page ))) # integer identical to range by count

    if int(pageid) > pagecount and int(pageid) > 1: # pageid exceeds pagecount
        pageid = pagecount

    start_img = int(pageid) * img_on_page - img_on_page	# start from image NR
    end_img = int(pageid) * img_on_page # end with image NR
    if end_img > images.count(): # if end NR exceeds limit set it to end NR
        end_img = images.count()

    args['images'] = images.order_by('-galery_date')[start_img:end_img] # -argument is for negative sort
    args['paginator'] = Paginator( pagecount, pageid, 8 )

    if args['mobile_browser']:
        response = render(request, 'galery_mobile.html', args)
        response.set_cookie( key='page_loc', value='/gallery/' + str(pageid) + '/', path='/' )
        return response

    response = render(request, 'galery.html', args)
    response.set_cookie( key='page_loc', value='/gallery/' + str(pageid) + '/', path='/' )
    return response
예제 #2
0
파일: views.py 프로젝트: svabis/qual
def main(request, pageid=1):
    args = k.cam_header(request)  # Header (Tabs, e.t.c. from app kamera)
    args['heading'] = u'Lietotāju attēlu galerija'

    if int(pageid) < 1:  # negative page number --> 404
        return redirect('/')

    bildes = Galerija.objects.all()

    img_on_page = 20
    pagecount = int(
        math.ceil(int(bildes.count()) /
                  float(img_on_page)))  # integer identical to range by count

    if int(pageid) > pagecount and int(
            pageid) > 1:  # pageid exceeds pagecount --> 404
        return redirect('/')

    start_img = int(pageid) * img_on_page - img_on_page  # start from image NR
    end_img = int(pageid) * img_on_page  # end with image NR
    if end_img > bildes.count():  # if end NR exceeds limit set it to end NR
        end_img = bildes.count()

    args['images'] = bildes.order_by('-bilde_added')[
        start_img:end_img]  # -argument is for negative sort
    args['paginator'] = Paginator(pagecount, pageid)

    args['galery_tab'] = True  # For ACTIVE state "Lietotaju Galerija"

    response = render(request, 'gal_grid.html', args)
    # SET page_location COOKIE
    response.set_cookie(key='page_location',
                        value='/gallery/' + str(pageid) + '/')
    return response
예제 #3
0
def super(request, s_id, pageid=1):
    args = create_args(request)
    if args['username'].get_username() == '': # NO USER
        return redirect('access_denied')
    else:
        idea_access = User_data.objects.get(user_user = args['username']).idea
    if idea_access != True:
      # ACCESS DENIED
        return redirect('access_denied')

    try:
        args['idea_add'] = User_data.objects.get(user_user = args['username']).idea_add
    except:
        pass

    try:
        s = SuperTheme.objects.get(slug=str(s_id))
    except:
        return redirect('/idea/')

    args['super'] = SuperTheme.objects.all().order_by('order')
    args['user'] = auth.get_user(request)

    args['title'] = u'Ideju Lāde | ' + s.title
    args['heading'] = u'Ideju Lāde'
    args['active_tab'] = s.slug

    args['disable_back'] = True

    rez_obj = Theme.objects.filter( relate_to_super = s, parent = None ).order_by('comment', '-last_entry')

    results_per_page = 3

    if int(pageid) < 1: # negative page number --> 404
        return redirect ('/idea/')

    pagecount = int(math.ceil( int(rez_obj.count()) / float( results_per_page ))) # integer identical to range by count

    if int(pageid) > pagecount: # pageid exceeds pagecount --> 404
        return redirect ('/idea/')

    start_obj = int(pageid) * results_per_page - results_per_page # start from image NR
    end_obj = int(pageid) * results_per_page # end with image NR
    if end_obj > rez_obj.count(): # if end NR exceeds limit set it to end NR
        end_obj = rez_obj.count()

    args['paginator'] = Paginator( pagecount, pageid, 10 )
    args['temas'] = rez_obj[start_obj:end_obj]

    args['add_tema'] = True
    args['form'] = ThemeForm

    response = render(request, 'theme.html', args)
    response.set_cookie( key='page_loc', value='/idea/' + str(s_id) + '/' )
    return response
예제 #4
0
파일: views.py 프로젝트: svabis/servax
def galery_tags(request, tag, pageid=1):
    args = galery_default(request)
    temp = args['images']

    tag = str(tag)
   # EMPTY QUERYSET
    images = []

    for b in temp:
        t_array = b.galery_tags.split(",")
        for t in t_array:
            if tag == slugify( t ):
                images.append( b )

    pagecount = int(math.ceil( int( len(images) ) / float( img_on_page ))) # integer identical to range by count

    if int(pageid) > pagecount and int(pageid) > 1: # pageid exceeds pagecount
        pageid = pagecount

    start_img = int(pageid) * img_on_page - img_on_page	# start from image NR
    end_img = int(pageid) * img_on_page # end with image NR
    if end_img > len(images): # if end NR exceeds limit set it to end NR
        end_img = len(images)

    args['images'] = images[start_img:end_img]
    args['paginator'] = Paginator( pagecount, pageid, 8 )

    args['tag'] = tag

    if args['mobile_browser']:
        response = render(request, 'galery_mobile.html', args)
        response.set_cookie( key='page_loc', value='/gallery/' + str(pageid) + '/', path='/' )
        return response

    response = render(request, 'galery.html', args)
    response.set_cookie( key='page_loc', value='/gallery/tag=' + tag + '/' + str(pageid) + '/', path='/' )
    return response
예제 #5
0
def temas(request, s_id, t_id, pageid=1):
    try:
        t = Theme.objects.get(slug=str(t_id))
    except:
        return redirect('/idea/')

    args = create_args(request)
    if args['username'].get_username() == '':  # NO USER
        return redirect('access_denied')
    else:
        idea_access = User_data.objects.get(user_user=args['username']).idea
    if idea_access != True:
        # ACCESS DENIED
        return redirect('access_denied')

    try:
        args['idea_add'] = User_data.objects.get(
            user_user=args['username']).idea_add
    except:
        pass

    args['super'] = SuperTheme.objects.all().order_by('order')
    args['user'] = auth.get_user(request)

    args[
        'title'] = u'Ideju Lāde | ' + t.relate_to_super.title + " | " + t.title
    args['heading'] = u'Ideju Lāde'
    args['active_tab'] = t.relate_to_super.slug

    args['parent'] = t.parent
    args['s_id'] = str(s_id)

    # IF TEMA COMMENT IS DISABLED
    if t.comment == False:
        temas = Theme.objects.filter(parent=t).order_by(
            'comment', '-last_entry')

        args['temas'] = temas
        args['add_tema'] = True

        args['form'] = ThemeForm

        response = render(request, 'theme.html', args)
        response.set_cookie(key='page_loc',
                            value='/idea/' + str(s_id) + '/' + str(t_id) +
                            '/' + str(pageid) + '/')
        return response

    args['tema_nr'] = t.id
    args['tema_slug'] = t.slug
    args['tema_title'] = t.title

    results_per_page = 50

    rez_obj = Post.objects.filter(relate_to=t).order_by('date')

    if int(pageid) < 1:  # negative page number --> 404
        return redirect('/')

    pagecount = int(math.ceil(
        int(rez_obj.count()) /
        float(results_per_page)))  # integer identical to range by count

    if int(pageid) > pagecount and int(
            pageid) > 1:  # pageid exceeds pagecount --> 404
        return redirect('/')

    start_obj = int(
        pageid) * results_per_page - results_per_page  # start from image NR
    end_obj = int(pageid) * results_per_page  # end with image NR
    if end_obj > rez_obj.count():  # if end NR exceeds limit set it to end NR
        end_obj = rez_obj.count()

    args['paginator'] = Paginator(pagecount, pageid, 10)
    args['diskusija'] = rez_obj[start_obj:end_obj]

    args['form'] = PostForm

    if request.POST:
        form = PostForm(request.POST, request.FILES)

        # save Post object
        if form.is_valid():
            new_coment = form.save(commit=False)
            new_coment.relate_to = t
            new_coment.user = args['user']
            new_coment.save()

            # Save images
            #            for img in request.FILES.getlist('file'):
            for img in request.FILES.getlist('image'):
                PostImage.objects.create(post=new_coment, image=img)

            while t.parent != None:
                try:
                    t.parent.last_entry = new_coment.date
                    t.parent.save()
                except:
                    pass
                t.last_entry = new_coment.date
                t.entry_count += 1
                t.save()
                t = t.parent

            if t.parent == None:
                t.last_entry = new_coment.date
                t.entry_count += 1
                t.save()

            response = redirect('/idea/' + str(s_id) + '/' + str(t_id) +
                                '/#new_comment')
            response.set_cookie(key='page_loc',
                                value='/idea/' + str(s_id) + '/' + str(t_id) +
                                '/#new_comment')
            return response
    else:
        args['form'] = PostForm

    response = render(request, 'discussions.html', args)
    response.set_cookie(key='page_loc',
                        value='/idea/' + str(s_id) + '/' + str(t_id) + '/' +
                        str(pageid) + '/')
    return response
예제 #6
0
파일: grid.py 프로젝트: svabis/qual
def cam_id_grid(request, camid, pageid):
    if int(pageid) < 1:  # negative page number --> 404
        return redirect('kameras_main')
    access = kamera_main.slug_access(request,
                                     camid)  # test slug for access denied
    if access == False:
        return redirect('kameras_main')

    kamera = Kamera.objects.get(kamera_slug=camid)

    bildes = Bilde.objects.filter(
        bilde_kamera_id=kamera
    )  # list of Bilde objects for current Kamera object

    img_on_page = 20
    pagecount = int(
        math.ceil(int(bildes.count()) /
                  float(img_on_page)))  # integer identical to range by count

    if int(pageid) > pagecount and int(
            pageid) > 1:  # pageid exceeds pagecount --> last page
        if pagecount == 0:
            pageid = "1"
        else:
            pageid = str(pagecount)

    start_img = int(pageid) * img_on_page - img_on_page  # start from image NR
    end_img = int(pageid) * img_on_page  # end with image NR
    if end_img > bildes.count():  # if end NR exceeds limit set it to end NR
        end_img = bildes.count()

    args = kamera_main.cam_header(request)

    # ADD CSRF TOKEN
    #    args.update(csrf(request))

    args['images'] = bildes.order_by('-bilde_datums')[
        start_img:end_img]  # -argument is for negative sort
    args['title'] = getattr(
        kamera, 'kamera_nos') + ' | ' + kamera_main.get_domain_full(
            request)  # return page title + kamera_nos + DOMAIN
    args['heading'] = u'Kamera:  ' + getattr(
        kamera, 'kamera_nos') + kamera_main.cam_header_type(kamera)
    args['active_tab'] = camid
    args['paginator'] = Paginator(pagecount, pageid)

    # IMAGE DELETE/SHARE OPTION
    try:
        usr = auth.get_user(request).username
        usr_del = User.objects.get(username=usr).k.filter(
            user=User.objects.get(username=usr)).get(kamera=kamera)
        args['owner'] = True
    except:
        pass

    response = render(request, 'grid.html', args)
    # SET page_location COOKIE
    response.set_cookie(key='page_location',
                        value='/cam/grid/' + str(camid) + '/' + str(pageid) +
                        '/')
    return response