Exemplo n.º 1
0
def city_edit(request, c_id):
    args = kamera_main.cam_header(request)

   # LIMIT ACCES TO GROUP ADMIN
    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    args['data'] = MapPlotCity.objects.all()

    try:
        args['edit'] = MapPlotCity.objects.get(id=c_id)
    except:
        return redirect('city_add')

    form = MapPlotCityForm( instance=args['edit'] )

    if request.POST:
       # ADD CITY
        form = MapPlotCityForm( request.POST, instance=args['edit'] )
        if form.is_valid():
#            new_city = form.save( commit=False )
            form.save()
            response = redirect('city_add')
            return response

    args['form'] = form

    response = render(request, 'city_add.html', args)
    return response
Exemplo n.º 2
0
def city_export_xls(request, c_id):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP ADMIN
    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

# GET CITY
    city = MapPlotCity.objects.get(id=c_id)
    # GET POINTS SORTED FOR CITY
    points = MapPlot.objects.filter(city=city, deleted=False).order_by('mark')

    filename = unicodedata.normalize('NFKD',
                                     city.name).encode('ascii', 'ignore')
    response = HttpResponse(content_type='application/ms-excel')
    response[
        'Content-Disposition'] = 'attachment; filename="' + filename.lower(
        ) + '.xls"'

    wb = xlwt.Workbook(encoding='utf-8')
    ws = wb.add_sheet(city.name)

    # Sheet header, first row
    row_num = 0

    font_style = xlwt.XFStyle()
    font_style.font.bold = True

    columns = [
        'DATE_ADD', 'DATE_EDIT', 'ID', 'LATITUDE', 'LONGITUDE', 'TYPE', 'OLD',
        'LED', 'CONSOLE'
    ]

    for col_num in range(len(columns)):
        ws.write(row_num, col_num, columns[col_num], font_style)

    # Sheet body, remaining rows
    font_style = xlwt.XFStyle()

    # HISTORY
    rows = points  #.values_list('create_date', 'edit_date', 'mark', 'lat', 'lon', 'radio', 'chk_1', 'chk_2', 'chk_3')
    for row in rows:
        row_num += 1
        ws.write(row_num, 0, row.create_date.strftime("%Y-%m-%d %H:%M"),
                 font_style)
        try:
            ws.write(row_num, 1, row.edit_date.strftime("%Y-%m-%d %H:%M"),
                     font_style)
        except:
            pass
        ws.write(row_num, 2, row.mark, font_style)
        ws.write(row_num, 3, row.lat, font_style)
        ws.write(row_num, 4, row.lon, font_style)
        ws.write(row_num, 5, row.radio.name, font_style)
        ws.write(row_num, 6, row.chk_1, font_style)
        ws.write(row_num, 7, row.chk_2, font_style)
        ws.write(row_num, 8, row.chk_3, font_style)

    wb.save(response)
    return response
Exemplo n.º 3
0
Arquivo: views.py Projeto: 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
Exemplo n.º 4
0
Arquivo: grid.py Projeto: svabis/qual
def cam_all(request):
    try:
        kamera1 = kamera_main.cam_objects(request)[0][0]
        kamera_slug = getattr(
            kamera1, 'kamera_slug'
        )  # get first kamera_slug from available Kamera object list depending on sort type
    except:
        args = kamera_main.cam_header(request)
        args['heading'] = u'Kamera nav atrasta'
        return render_to_response('no_cam.html', args)
    return redirect(
        'cam_id_grid', camid=kamera_slug, pageid=1
    )  # first argument is "name of the view (look in urls.py)", next are parameters
Exemplo n.º 5
0
def plot_search(request):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    if not args['username'].groups.filter(
            name__in=["map_admin", "map_doer"]).exists():
        #    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    try:
        s = request.POST['search']
        edit = MapPlot.objects.filter(mark=s)[0]
        response = redirect('/mapplot/plot/' + str(edit.id) + '/')
        return response

    except:
        response = redirect('/mapplot/plot/')
        return response
Exemplo n.º 6
0
def mapplot_admin(request):
    args = kamera_main.cam_header(request)

   # LIMIT ACCES TO GROUP ADMIN
    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    args["heading"] = u'Mapplot Admin sadaļa'
    args["title"] = u'Mapplot Admin sadaļa'

   # CITY
    args["city_data"] = MapPlotCity.objects.all().order_by('name')

   # USER
    u_data = []
    data = MapPlotUserCity.objects.all().order_by('user', 'city')
    temp_data = []
    try:
        temp = data[0].user
    except:
        temp = ""

    for d in data:
        groups = d.user.groups.all().values_list('name', flat=True)
        adm = True if "map_admin" in groups else False

        if temp == d.user:
            temp_data.append( [d, adm] )
        else:
            u_data.append( temp_data )
            temp_data = [[d, adm]]
        temp = d.user
    if len(u_data) != 0:
        u_data.append( temp_data )

    args["user_data"] = u_data

# !!!!!!!!!!!!!!!!!!!!!!!!!
# !!! PUT STUFF IN HERE !!!
# !!!!!!!!!!!!!!!!!!!!!!!!!

    response = render(request, 'mapplot_admin.html', args)
    return response
Exemplo n.º 7
0
def plot_del(request, d_id):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    if not args['username'].groups.filter(
            name__in=["map_admin", "map_doer"]).exists():
        #    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    plot = MapPlot.objects.get(id=d_id)
    plot.edit_date = timezone.now()
    plot.user = args['username']
    plot.deleted = True
    plot.save()

    # Set return to added Point
    c = plot.lat + ":" + plot.lon + ":" + "18"
    response = redirect('/mapplot/plot/')
    response.set_cookie(key='view', value=c, path='/', max_age=5)
    return response
Exemplo n.º 8
0
def city_export_pdf(request, c_id):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    #    if not args['username'].groups.filter(name__in=["map_admin", "map_doer"]).exists():
    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    args['title'] = 'Kartes plotteris'
    args['heading'] = 'Kartes ploteris'

    # SET CITY
    args['city'] = MapPlotCity.objects.get(id=c_id)

    args['data'] = MapPlot.objects.filter(deleted=False, city=args['city'])

    #    args['form'] = MapPlotForm(initial={'city':args['city']})

    response = render(request, 'pdf.html', args)
    response.set_cookie(key='page_location', value='/plot/', path='/')
    return response
Exemplo n.º 9
0
def login(request):
    # if user is already authenticated --> redirect from here
    if request.user.is_authenticated():
        response = redirect('/gallery/')
        return response

    args = k.cam_header(request)  # Header (Tabs, e.t.c. from app kamera)
    #    args.update(csrf(request))      # encript data
    args['heading'] = "Autorizācija sistēmā"

    if request.POST:  # actions if login Form is submitted
        username = request.POST.get(
            'username', ''
        )  # usermname <= get variable from Form (name="username"), if not leave blank
        password = request.POST.get(
            'password', ''
        )  # password <= get variable from Form (name="password"), if not leave blank
        user = auth.authenticate(
            username=username,
            password=password)  # new variable --> user from auth system

        if user is not None:  # auth return None if this user does not exit, if not then:
            if user.is_active == False:  # User is disabled in Django Admin -->
                args['login_error'] = "Lietotājs uz doto momentu ir bloķēts"
                return render(request, 'login.html', args)
            auth.login(request, user)  # authorizate user from Form

            response = redirect('/gallery/')
            response.set_cookie(key='cam_type', value=3)
            return response

        else:  # if user does not exist:
            args[
                'login_error'] = "Ievadīts lietotāja vārds vai parole nepareizi"
            return render(request, 'login.html', args)

    else:  # actions if not request.POST (link clicked)
        return render(request, 'login.html', args)
Exemplo n.º 10
0
def pin(request):
    # if user is already authenticated --> redirect from here
    if request.user.is_authenticated():
        response = redirect('/gallery/')
        return response

    args = k.cam_header(request)  # Header (Tabs, e.t.c. from app kamera)
    #    args.update(csrf(request))      # encript data
    args['heading'] = "Autorizācija sistēmā izmantojot PIN kodu"

    if request.POST:
        pin = request.POST.get(
            'pin', ''
        )  # usermname <= get variable from Form (name="username"), if not leave blank
        try:
            user = User_pin.objects.get(user_pin=pin).user_user
        except:
            user = None

        if user is not None:  # auth return None if this user does not exit, if not then:
            if user.is_active == False:  # User is disabled in Django Admin -->
                args['login_error'] = "Lietotājs uz doto momentu ir bloķēts"
                return render(request, 'pin.html', args)

            user.backend = 'django.contrib.auth.backends.ModelBackend'
            auth.login(request, user)

            response = redirect('/gallery/')
            response.set_cookie(key='cam_type', value=2)
            return response

        else:  # if user does not exist:
            response = redirect('/gallery/')
            return response

    else:  # actions if not request.POST (link clicked)
        return render(request, 'pin.html', args)
Exemplo n.º 11
0
def city_select(request):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    if not args['username'].groups.filter(
            name__in=["map_admin", "map_doer"]).exists():
        #    if not args['username'].groups.filter(name="map_admin").exists():
        return redirect("/")

    args["data"] = MapPlotUserCity.objects.filter(
        user=args['username']).order_by('city__name')

    # SELECT CITY IF ONLY ONE IS SET
    if len(args["data"]) == 1:
        city = args["data"][0].city.id
        response = redirect('/mapplot/plot/')
        try:
            response.delete_cookie('view')
        except:
            pass
        response.set_cookie(key='city', value=city, path='/')  #, max_age=5 )
        return response

# SELECT CITY FROM LIST
    if request.POST:
        city = request.POST['city']
        response = redirect('/mapplot/plot/')
        try:
            response.delete_cookie('view')
        except:
            pass
        response.set_cookie(key='city', value=city, path='/')  #, max_age=5 )
        return response

    response = render(request, 'city_select.html', args)
    #    response.set_cookie( key='view', value=c, path='/') #, max_age=5 )
    return response
Exemplo n.º 12
0
Arquivo: image.py Projeto: svabis/qual
def bilde_id(request, pageid, imgid, show='', date=''):
    try:
        if date:
            imgname = date + '/' + imgid + '.jpg'
        else:
            imgname = imgid + '.jpg'
        bilde = Bilde.objects.get(bilde_bilde=imgname)  # get image to display
    except ObjectDoesNotExist:  # not existing bilde --> 404
        return redirect('kameras_main')
    if int(pageid) < 1:  # negative page number --> 404
        return redirect('kameras_main')

    return_cam = getattr(bilde,
                         'bilde_kamera_id')  # get bilde_kamera_id to return to
    bildes = Bilde.objects.filter(bilde_kamera_id=return_cam).order_by(
        '-bilde_datums')  # filtered list of Bilde objects
    #    bildes = Bilde.objects.filter( bilde_kamera_id = return_cam )        # 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:  # pageid exceeds pagecount --> 404
        return redirect('kameras_main')

    args = kamera_main.cam_header(request)
    args['image'] = bilde
    args['time'] = bilde.bilde_datums
    args['title'] = getattr(
        return_cam, 'kamera_nos') + ' | ' + kamera_main.get_domain_full(
            request)  # return page title + kamera_nos + DOMAIN
    args['heading'] = u'Kamera:  ' + getattr(
        return_cam, 'kamera_nos') + kamera_main.cam_header_type(return_cam)
    args['active_tab'] = getattr(return_cam, 'kamera_slug')  # get kamera_slug

    # Getting Next and Previous Bilde objects from filtered list
    counter = 0  # set iteration counter
    for img in bildes:
        if img == bilde:  # if image from this iteration == curent image do:
            try:  # try is for if previous does not exist
                args['back_img'] = getattr(
                    bildes[counter - 1], 'bilde_bilde'
                ).name  # get next object 'bilde_bilde' filename
            except:
                pass
            try:  # try is for if next does not exist
                args['next_img'] = getattr(
                    bildes[counter + 1], 'bilde_bilde'
                ).name  # get next object 'bilde_bilde' filename
            except:
                pass
            return_page = (counter /
                           20) + 1  # locates page number you ar at the moment
        counter += 1  # increase iteration counter
    args['back_page'] = return_page

    if show != '':
        args['slideshow'] = True

# 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=return_cam)
        args['img_owner'] = True
    except:
        pass
#        args['img_owner'] = return_cam

    response = render(request, 'image.html', args)
    # SET page_location COOKIE
    response.set_cookie(key='page_location',
                        value='/cam/img/' + str(pageid) + '/' + str(imgid) +
                        '/')
    return response
Exemplo n.º 13
0
def plot_edit(request, e_id):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    if not args['username'].groups.filter(
            name__in=["map_admin", "map_doer"]).exists():
        #    if not args['username'].groups.filter(name="map_doer").exists():
        return redirect("/")

    args['title'] = 'Kartes plotteris'
    args['heading'] = 'Kartes ploteris'

    # SET CITY
    if str("city") in request.COOKIES:
        city = int(request.COOKIES.get(str("city")))
    args['city'] = MapPlotCity.objects.get(id=city)

    args['data'] = MapPlot.objects.filter(id=e_id)

    #    args['test'] = t

    edit = MapPlot.objects.get(id=e_id)
    args['edit'] = edit

    args['form'] = MapPlotForm(instance=edit)

    if request.POST:
        # POST, FILES, instance
        #        form = MapPlotForm( request.POST, request.FILES , instance=edit )
        form = MapPlotForm(request.POST, instance=edit)
        c = request.POST['zoom']

        if form.is_valid():
            edit_point = form.save(commit=False)

            try:
                temp = MapPlot.objects.filter(deleted=False,
                                              city=new_point.city,
                                              mark=new_point.mark)
                c = temp.count()
                if new_point in temp:
                    c = c - 1

                if c != 0:
                    args['form'] = form
                    args['error'] = " ID EXIST"
                    response = render(request, 'plot.html', args)
                    response.set_cookie(key='view', value=c,
                                        path='/')  #, max_age=5 )
                    response.set_cookie(key='page_location',
                                        value='/plot/',
                                        path='/')
                    return response
            except:
                pass

        # save images
            for img in request.FILES.getlist('camera'):
                MapPlotImage.objects.create(point=edit_point, image=img)

        # POINT VALIDATED
            edit_point.user = args['username']
            edit_point.edit_date = timezone.now()
            form.save()

            # Set return to added Point
            response = redirect('/mapplot/plot/')
            response.set_cookie(key='view', value=c, path='/')  #, max_age=5 )
            return response

        else:
            args['test'] = "viss slikti"
            args['form'] = form
            response = render(request, 'plot.html', args)
            response.set_cookie(key='view', value=c, path='/')  #, max_age=5 )
            response.set_cookie(key='page_location', value='/plot/', path='/')
            return response

    response = render(request, 'plot.html', args)
    response.set_cookie(key='page_location', value='/plot/', path='/')
    return response
Exemplo n.º 14
0
def plot(request):
    args = kamera_main.cam_header(request)

    # LIMIT ACCES TO GROUP MEMBERS
    if not args['username'].groups.filter(
            name__in=["map_admin", "map_doer"]).exists():
        #    if not args['username'].groups.filter(name="map_doer").exists():
        return redirect("/")

    args['title'] = 'Kartes plotteris'
    args['heading'] = 'Kartes ploteris'

    # SET CITY
    if str("city") in request.COOKIES:
        city = int(request.COOKIES.get(str("city")))
    args['city'] = MapPlotCity.objects.get(id=city)

    args['data'] = MapPlot.objects.filter(deleted=False, city=args['city'])

    args['form'] = MapPlotForm(initial={'city': args['city']})

    if request.POST:
        form = MapPlotForm(request.POST)
        c = request.POST['zoom']

        if form.is_valid():
            new_point = form.save(commit=False)

            try:
                temp = MapPlot.objects.filter(deleted=False,
                                              city=new_point.city,
                                              mark=new_point.mark)
                if temp.count() != 0:
                    args['form'] = form
                    args['error'] = " ID EXIST"
                    response = render(request, 'plot.html', args)
                    response.set_cookie(key='view', value=c,
                                        path='/')  #, max_age=5 )
                    response.set_cookie(key='page_location',
                                        value='/plot/',
                                        path='/')
                    return response
            except:
                pass

        # POINT VALIDATED
            new_point.user = args['username']
            form.save()
            # Set return to added Point

            #            response = redirect( '/mapplot/plot/')
            response = render(request, 'plot.html', args)

            response.set_cookie(key='view', value=c, path='/')  #, max_age=5 )
            return response

        else:
            #            args['test'] = "viss slikti"
            args['form'] = form
            response = render(request, 'plot.html', args)
            response.set_cookie(key='view', value=c, path='/')  #, max_age=5 )
            response.set_cookie(key='page_location', value='/plot/', path='/')
            return response

    response = render(request, 'plot.html', args)
    response.set_cookie(key='page_location', value='/plot/', path='/')
    return response
Exemplo n.º 15
0
Arquivo: views.py Projeto: svabis/qual
def img_big(request, pageid, imgid):
    try:
        bilde = Galerija.objects.get(id=imgid)  # get image to display
    except ObjectDoesNotExist:  # not existing bilde --> 404
        return redirect('galerija_main')
    if int(pageid) < 1:  # negative page number --> 404
        return redirect('galerija_main')

    bildes = Galerija.objects.all().order_by('-bilde_added')
    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:  # pageid exceeds pagecount --> 404
        return redirect('galerija_main')

    args = k.cam_header(request)  # Header (Tabs, e.t.c. from app kamera)

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

    if request.POST and ("pause" + str(imgid)
                         not in request.session):  # IF COMMENT ADDED -->
        comment = request.POST.get('comment', '')
        if comment != '':  # COMMENT NOT EMPTY -->
            new_comment = GalerijaKoment(koment_bilde=bilde,
                                         koment_text=comment)  # create coment
            new_comment.save()  # save comment

            request.session.set_expiry(60)
            request.session['pause' + str(imgid)] = True

            return redirect(
                'galerija_img', pageid=pageid, imgid=imgid
            )  # reload this view (prevents resend POST on refresh page)

    args['heading'] = u'Lietotāju attēlu galerija'
    args['image'] = bilde
    args['time'] = bilde.bilde_datums
    args['title'] = 'Lietotāju galerija | ' + k.get_domain_full(
        request)  # title + DOMAIN

    args['komenti'] = GalerijaKoment.objects.filter(
        koment_bilde=bilde).order_by('-koment_datums')
    args['komenti_counter'] = args['komenti'].count()
    try:
        img_likes = GalerijaLike.objects.get(bilde=bilde)
        args['bilde_plus'] = img_likes.bilde_plus
        args['bilde_minus'] = img_likes.bilde_minus
    except:
        args['bilde_plus'] = 0
        args['bilde_minus'] = 0
#        pass

# Getting Next and Previous Bilde objects from filtered list
    counter = 0  # set iteration counter
    for img in bildes:
        if img == bilde:  # if image from this iteration == curent image do:
            try:  # try is for if previous does not exist
                args['back_img'] = bildes[counter - 1]  # get next object
            except:
                pass
            try:  # try is for if next does not exist
                args['next_img'] = bildes[counter + 1]  # get next object
            except:
                pass
            return_page = (counter /
                           20) + 1  # locates page number you ar at the moment
        counter += 1  # increase iteration counter
    args['back_page'] = return_page

    response = render(request, 'gal_image.html', args)
    # SET page_location COOKIE
    #    response.set_cookie( key='page_location', value='/cam/img/'+ str(pageid) +'/'+ str(imgid) +'/' )
    return response
Exemplo n.º 16
0
Arquivo: grid.py Projeto: 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