Ejemplo n.º 1
0
def home(request):
    posts = Blog.objects.all()[:10]
    for post in posts:
        html = django_markdown.utils.markdown(value=post.body)
        soup = BeautifulSoup(html)
        try:
            ex = soup.p.string
            imgs = soup.findAll('img', {'src': True})
            if len(imgs) > 1:
                post.type = 4
            for img in imgs:
                url = img['src']
                imglist = Images.objects.filter(link=url)
                if len(imglist) == 0:
                    image = Images(link=url)
                    image.save()
                else:
                    image = imglist[0]
                post.imagelinks.add(image)
            post.save()
            post.excerpt = ex[0:330] + '...'
            post.save()
        except:
            pass

    return render_to_response('alwaysblue/index.html', {
        'tags': Tag.objects.all(),
        'posts': posts
    })
Ejemplo n.º 2
0
def add_image(request):
    if 'token' in request.POST:
        token = request.POST['token']

    userdetail = UserDetail(request).getLoginUser()
    user_id = userdetail['id']

    data = {}

    if 'file' in request.FILES:
        image = request.FILES.get('file')
        file_type = image.content_type.split('/')[0]

        print "\n\n type of image :   ", type(file_type)

        if str(file_type) != "image":
            data = {'is_valid': False, 'message': 'Please upload Images Only.'}
            return HttpResponse(json.dumps(data))
        try:
            images = Images(user_id=user_id, image=request.FILES.get('file'))
            images.save()
            token = images.token
            image_id = images.id
            image_name = images.image_name
            url = "http://" + request.META['HTTP_HOST'] + "/images/view/" + str(
                token) + "/" + str(image_id)
            data = {
                'is_valid': True,
                'name': image_name,
                'url': url,
                'token': token
            }
        except:
            data = {'is_valid': False, 'message': 'Cannot Be Uploaded.'}
    return HttpResponse(json.dumps(data))
Ejemplo n.º 3
0
def xmlparse():
    #pagecode = urllib.urlopen("http://www.esmadrid.com/opendata/alojamientos_v1_es.xml")
    pagecode = urllib.urlopen(
        "http://cursosweb.github.io/etc/alojamientos_es.xml")
    xmlsheet = pagecode.read()
    noticias = xmlsheet.split("<service ")
    for noticia in noticias[1:-1]:
        url = noticia.split("<web>")[1].split("</web>")[0]
        try:
            alojamiento = Alojamientos.objects.get(url=url)
        except Alojamientos.DoesNotExist:
            name = noticia.split("<name><![CDATA[")[1].split("]]></name>")[0]
            address = noticia.split("<address>")[1].split("</address>")[0]
            zipcode = noticia.split("<zipcode>")[1].split("</zipcode>")[0]
            country = noticia.split("<country>")[1].split("</country>")[0]
            latitude = noticia.split("<latitude>")[1].split("</latitude>")[0]
            longitude = noticia.split("<longitude>")[1].split(
                "</longitude>")[0]
            city = noticia.split("<subAdministrativeArea>")[1].split(
                "</subAdministrativeArea>")[0]
            alojamiento = Alojamientos(name=name,
                                       url=url,
                                       address=address,
                                       zipcode=zipcode,
                                       country=country,
                                       latitude=latitude,
                                       longitude=longitude,
                                       city=city)
            alojamiento.save()
            images = noticia.split('<url>')
            for image in images[1:6]:
                image_url = image.split('</url>')[0]
                image = Images(url=image_url, alojamiento=alojamiento)
                image.save()
Ejemplo n.º 4
0
def gallery(request, imagename=None):
    print imagename
    if request.method == 'POST':
        title = request.POST['pname']
        img_data = request.POST['pdata']
        p = Images(title=title, img_data=img_data)
        p.save()
    if request.method == 'GET':
        image = Images.objects.filter(title=imagename)
        for i in image:
            data = i.img_data
        print json.dumps(data)
        t = get_template('paint.html')
        html = t.render(Context({}))
        if data:
            html = """<script>var data=JSON.parse(' """ + data + """ ');</script>""" + html
        else:
            html = """<script>alert("Image not found")</script>""" + html
        return HttpResponse(html)
Ejemplo n.º 5
0
def gallery(request,imagename=None):
	print imagename
	if request.method == 'POST':
		title = request.POST['pname']
		img_data = request.POST['pdata']
		p = Images(title = title, img_data = img_data)
		p.save()
	if 	request.method == 'GET':
		image = Images.objects.filter(title = imagename)
		for i in image:
			data = i.img_data
		print json.dumps(data)
		t = get_template('paint.html')
		html = t.render(Context({}))
		if data:
			html="""<script>var data=JSON.parse(' """+data+""" ');</script>"""+html		
		else:
			html="""<script>alert("Image not found")</script>"""+html
		return HttpResponse(html)
Ejemplo n.º 6
0
def add_image(request):
    form = ImageForm()
    if request.POST:
        form = ImageForm(request.POST, request.FILES)
        if form.is_valid():
            image = request.FILES['image_file']
            comment = form.cleaned_data['comment']
            format = image.name.split('.')[-1]
            p = Images(comment = comment, name = '',
            useragent = request.META['HTTP_USER_AGENT'],
            ip = request.META['REMOTE_ADDR'], views = 0 ,views_last_hour = 0,
            md5 = 0, format = format)
            p.save()
            save_image(image, p.id)
            return HttpResponseRedirect('/%s' % to_62(p.id))
        else:
            form = ImageForm()
            return render_to_response("forms/add_image.html", {'form': form})
    else:
        return render_to_response("forms/add_image.html", {'form': form})
Ejemplo n.º 7
0
def add_image(request):
    #last_image_id = Images.objects.order_by('-id')[0].id else last_image_id = 0
    form = ImageForm()
    if request.POST:
        form = ImageForm(request.POST, request.FILES)
        if form.is_valid():
            image = request.FILES['image_file']
            
            save_image(image)
            
            #thumb_image = thumbnail(image)
            #save_image(thumb_image)
            p = Images(comment=request.POST['comment'], name = file.name,
            useragent=request.META['HTTP_USER_AGENT'],
            ip=request.META['REMOTE_ADDR'], views=0, md5=0 )
            p.save()
            return HttpResponse(image.name)
            #return render_to_response("forms/add_image.html", {'form': form})
        else:
            return render_to_response("forms/add_image.html", {'form': form})
    else:
        return render_to_response("forms/add_image.html", {'form': form})
Ejemplo n.º 8
0
def xmlparse():
    #pagecode = urllib.urlopen("http://www.esmadrid.com/opendata/alojamientos_v1_es.xml")
    pagecode = urllib.urlopen("http://cursosweb.github.io/etc/alojamientos_es.xml")
    xmlsheet = pagecode.read()
    noticias=xmlsheet.split("<service ")
    for noticia in noticias[1:-1]:
        url = noticia.split("<web>")[1].split("</web>")[0]
        try:
            alojamiento = Alojamientos.objects.get(url=url)
        except Alojamientos.DoesNotExist:
            name = noticia.split("<name><![CDATA[")[1].split("]]></name>")[0]
            address = noticia.split("<address>")[1].split("</address>")[0]
            zipcode = noticia.split("<zipcode>")[1].split("</zipcode>")[0]
            country = noticia.split("<country>")[1].split("</country>")[0]
            latitude = noticia.split("<latitude>")[1].split("</latitude>")[0]
            longitude = noticia.split("<longitude>")[1].split("</longitude>")[0]
            city = noticia.split("<subAdministrativeArea>")[1].split("</subAdministrativeArea>")[0]
            alojamiento = Alojamientos(name=name, url=url, address=address, zipcode=zipcode, country=country, latitude=latitude, longitude=longitude, city=city)
            alojamiento.save()
            images = noticia.split('<url>')
            for image in images[1:6]:
                image_url = image.split('</url>')[0]
                image = Images(url=image_url, alojamiento=alojamiento)
                image.save()
Ejemplo n.º 9
0
def unhash(request):
    if request.method == 'POST':
        photo = request.POST.get('photo')
        hashcode = request.POST.get('hashcode')
        encrypted = request.POST.get('encrypted')
        #caption is added
        caption = request.POST.get('caption')

        list = encrypted.split("_")
        print list

        #storing the geo-tagged information in variables

        lat = list[0]
        long = list[1]
        hr = list[2]
        min = list[3]
        day = list[4]
        month = list[5]
        yr = list[6]

        hard_location = "Jagatpura, Jaipur Municipal Corporation, Jaipur, Rajasthan, 302033, India"

        # forming the address and storing it in variable

        list.pop(2)
        list.pop(2)
        list.pop(2)
        list.pop(2)
        list.pop(2)
        try:
            geolocator = Nominatim()
            location = geolocator.reverse(list)

            address = (location.address)
        except:
            address = hard_location
        # saving the image in jpeg file

        image = open("image.jpeg", "wb")
        image.write(photo.decode('base64'))
        image.close()
        #generate the hash of the image
        #hash = hashlib.md5()
        hash = hashlib.sha256()
        print hash
        hash.update(open('image.jpeg', 'rb').read())

        generated_hash = (hash.digest()).encode('base64')

        user_obj = Images()

        # saving into database

        user_obj.hashcode = hashcode
        user_obj.caption = caption
        user_obj.latitude = lat
        user_obj.longitude = long
        user_obj.date = day
        user_obj.month = month
        user_obj.year = yr
        user_obj.ocr = 1
        user_obj.mse = 1
        user_obj.pic.save('image.jpeg', File(open('image.jpeg')), save=False)

        user_obj.location = address
        user_obj.generated_hash = generated_hash
        user_obj.save(force_insert=True)

        #ocr = ocr_process('image.jpeg')
        #mse = image_process('image.jpeg')
        #user_obj.ocr = ocr
        #user_obj.mse = mse
        #user_obj.save()
        ##########
        global new_name

        new_name = str("image_" + str(user_obj.Uid) + ".jpeg")
        os.rename("image.jpeg", new_name)
        new_name2 = "image_" + str(user_obj.Uid)
        new_name.encode('UTF-8')

        #returning the user id of the data user submitted
        print(user_obj.Uid)

        try:
            #thread.start_new_thread(return_Uid, ("Thread-1",user_obj.Uid,))
            thread.start_new_thread(constraint_match, (
                "Thread-2",
                user_obj.Uid,
            ))
        except Exception as e:
            print(e)
        return Response(user_obj.Uid)