Esempio n. 1
0
def hash():

	# get Idea form from models.py
	photo_upload_form = models.photo_upload_form(request.form)
	
	# if form was submitted and it is valid...
	if request.method == "POST" and photo_upload_form.validate():
		
		new_post = models.Question.objects.order_by('-timestamp').first()
		new_post.guitar = request.form.get("guitar")
		new_post.typewriter = request.form.get("typewriter")
		new_post.still = request.form.get("still")
		new_post.video = request.form.get("video")
		new_post.prompt = request.form.get("prompt")
		new_post.prompt2 = request.form.get("prompt2")
		new_post.prompt3 = request.form.get("prompt3")
		new_post.prompt4 = request.form.get("prompt4")
				
				
		if new_post.save():

			return redirect('/')

		else:
			return "error " 



	else:
		# get existing images
		
		prompts = models.Question.objects.order_by('-timestamp')
		
		# render the template
		templateData = {
			
			'form' : photo_upload_form,
			'prompts' : prompts
		}

		return render_template("hashtags.html", **templateData)
Esempio n. 2
0
def index():

    # get Idea form from models.py
    photo_upload_form = models.photo_upload_form(request.form)

    # if form was submitted and it is valid...
    if request.method == "POST" and photo_upload_form.validate():
        uploaded_file = request.files['fileupload']
        # app.logger.info(file)
        # app.logger.info(file.mimetype)
        # app.logger.info(dir(file))

        # Uploading is fun
        # 1 - Generate a file name with the datetime prefixing filename
        # 2 - Connect to s3
        # 3 - Get the s3 bucket, put the file
        # 4 - After saving to s3, save data to database

        if uploaded_file and allowed_file(uploaded_file.filename):
            # create filename, prefixed with datetime
            now = datetime.datetime.now()
            filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(
                uploaded_file.filename)
            thumb_filename = now.strftime(
                '%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)

            # connect to s3
            s3conn = boto.connect_s3(os.environ.get('AWS_ACCESS_KEY_ID'),
                                     os.environ.get('AWS_SECRET_ACCESS_KEY'))

            # open s3 bucket, create new Key/file
            # set the mimetype, content and access control
            b = s3conn.get_bucket(
                os.environ.get('AWS_BUCKET'))  # bucket name defined in .env
            k = b.new_key(b)
            k.key = filename
            k.set_metadata("Content-Type", uploaded_file.mimetype)
            k.set_contents_from_string(uploaded_file.stream.read())
            k.make_public()

            # save information to MONGO database
            if k and k.size > 0:

                submitted_image = models.Image()
                submitted_image.title = request.form.get('title')
                submitted_image.description = request.form.get('description')

                #submitted_image.category = request.form.get('category')

                submitted_image.venues = request.form.get('venue')

                submitted_image.postedby = request.form.get('postedby')
                submitted_image.filename = filename  # same filename of s3 bucket file
                submitted_image.save()

            return redirect('/')

        else:
            return "uhoh there was an error " + uploaded_file.filename

    else:
        # get existing images
        images = models.Image.objects.order_by('-timestamp')

        # render the template
        templateData = {'images': images, 'form': photo_upload_form}

        return render_template("main.html", **templateData)
Esempio n. 3
0
def index():

	# get Idea form from models.py
	photo_upload_form = models.photo_upload_form(request.form)
	
	# if form was submitted and it is valid...
	if request.method == "POST" and photo_upload_form.validate():
		
		uploaded_file = request.files['fileupload']
		# app.logger.info(file)
		# app.logger.info(file.mimetype)
		# app.logger.info(dir(file))
		
		# Uploading is fun
		# 1 - Generate a file name with the datetime prefixing filename
		# 2 - Connect to s3
		# 3 - Get the s3 bucket, put the file
		# 4 - After saving to s3, save data to database

		if uploaded_file and allowed_file(uploaded_file.filename):
			# create filename, prefixed with datetime
			now = datetime.datetime.now()
			filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)
			# thumb_filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)

			# connect to s3
			s3conn = boto.connect_s3(os.environ.get('AWS_ACCESS_KEY_ID'),os.environ.get('AWS_SECRET_ACCESS_KEY'))

			# open s3 bucket, create new Key/file
			# set the mimetype, content and access control
			b = s3conn.get_bucket(os.environ.get('AWS_BUCKET')) # bucket name defined in .env
			
			k = b.new_key(b) # create a new Key (like a file)
			k.key = filename # set filename
			k.set_metadata("Content-Type", uploaded_file.mimetype) # identify MIME type
			k.set_contents_from_string(uploaded_file.stream.read()) # file contents to be added
                        k.make_public()

			# if content was actually saved to S3 - save info to Database
			if k and k.size > 0:
				
				submitted_image = models.Image()
				submitted_image.title = request.form.get('title')
				submitted_image.description = request.form.get('description')
				submitted_image.postedby = request.form.get('postedby')
                                submitted_image.url = k.generate_url(expires_in=0, query_auth=False, force_http=True)
				submitted_image.filename = filename # same filename of s3 bucket file
				submitted_image.save()


			return redirect('/')

		else:
			return "uhoh there was an error " + uploaded_file.filename



	else:
		# get existing images
		images = models.Image.objects.order_by('-timestamp')
		
		# render the template
		templateData = {
			'images' : images,
			'form' : photo_upload_form
		}

		return render_template("main.html", **templateData)
Esempio n. 4
0
def submit():

    # get Experience form from models.py
    photo_upload_form = models.photo_upload_form(request.form)

    # get created lists
    app.logger.debug(request.form.getlist("interest"))
    app.logger.debug(request.form.getlist("mood"))
    app.logger.debug(request.form.getlist("period"))

    # if form was submitted and it is valid...
    if request.method == "POST" and photo_upload_form.validate():

        uploaded_file = request.files["fileupload"]

        # Uploading is fun
        # 1 - Generate a file name with the datetime prefixing filename
        # 2 - Connect to s3
        # 3 - Get the s3 bucket, put the file
        # 4 - After saving to s3, save data to database

        if uploaded_file and allowed_file(uploaded_file.filename):
            # create filename, prefixed with datetime
            now = datetime.datetime.now()
            filename = now.strftime("%Y%m%d%H%M%s") + "-" + secure_filename(uploaded_file.filename)
            # thumb_filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)

            # connect to s3
            s3conn = boto.connect_s3(os.environ.get("AWS_ACCESS_KEY_ID"), os.environ.get("AWS_SECRET_ACCESS_KEY"))

            # open s3 bucket, create new Key/file
            # set the mimetype, content and access control
            b = s3conn.get_bucket(os.environ.get("AWS_BUCKET"))  # bucket name defined in .env
            k = b.new_key(b)
            k.key = filename
            k.set_metadata("Content-Type", uploaded_file.mimetype)
            k.set_contents_from_string(uploaded_file.stream.read())
            k.make_public()

            # save information to MONGO database
            # did something actually save to S3
            if k and k.size > 0:

                experience = models.Experience()
                experience.title = request.form.get("title")
                experience.slug = slugify(experience.title)
                experience.interest = request.form.getlist("interest")
                experience.mood = request.form.getlist("mood")
                experience.period = request.form.getlist("period")
                experience.description = request.form.get("description")
                experience.postedby = request.form.get("postedby")
                experience.filename = filename  # same filename of s3 bucket file
                experience.save()

            return redirect("/submit")

        else:
            return "uhoh there was an error " + uploaded_file.filename

    else:
        # get existing experiences
        experiences = models.Experience.objects.order_by("-timestamp")

        if request.form.getlist("interest"):
            for i in request.form.getlist("interest"):
                photo_upload_form.interest.append_entry(i)

        if request.form.getlist("mood"):
            for m in request.form.getlist("mood"):
                photo_upload_form.mood.append_entry(m)

        if request.form.getlist("period"):
            for p in request.form.getlist("period"):
                photo_upload_form.period.append_entry(p)

                # render the template
        templateData = {
            "experiences": experiences,
            "interest": interest,
            "mood": mood,
            "period": period,
            "form": photo_upload_form,
        }

        return render_template("submit.html", **templateData)
Esempio n. 5
0
def index():

	#PHOTO upload route section
	# get Idea form from models.py
	photo_upload_form = models.photo_upload_form(request.form)
	
	# if form was submitted and it is valid...
	if request.method == "POST" and photo_upload_form.validate():
		
		uploaded_file = request.files['fileupload']
		# app.logger.info(file)
		# app.logger.info(file.mimetype)
		# app.logger.info(dir(file))
		
		# Uploading is fun
		# 1 - Generate a file name with the datetime prefixing filename
		# 2 - Connect to s3
		# 3 - Get the s3 bucket, put the file
		# 4 - After saving to s3, save data to database
		# get form data - create new idea
		idea = models.Idea()
		idea.creator = request.form.get('creator','anonymous')
		idea.title = request.form.get('title','no title')
		idea.slug = slugify(idea.title + " " + idea.creator)
		idea.idea = request.form.get('idea','')
		idea.restaurant_name = request.form.get('restaurant_name','')
		idea.latitude = request.form.get('latitude','')
		idea.longitude = request.form.get('longitude','')
		idea.categories = request.form.getlist('categories') # getlist will pull multiple items 'categories' into a list
					
		# idea.save() # save it
			
			# redirect to the new idea page
		# return redirect('/ideas/%s' % idea.slug)

		if uploaded_file and allowed_file(uploaded_file.filename):
			# return "upload file"
			# create filename, prefixed with datetime
			now = datetime.datetime.now()
			filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)
			# thumb_filename = now.strftime('%Y%m%d%H%M%s') + "-" + secure_filename(uploaded_file.filename)

			# connect to s3
			s3conn = boto.connect_s3(os.environ.get('AWS_ACCESS_KEY_ID'),os.environ.get('AWS_SECRET_ACCESS_KEY'))

			# open s3 bucket, create new Key/file
			# set the mimetype, content and access control
			b = s3conn.get_bucket(os.environ.get('AWS_BUCKET')) # bucket name defined in .env
			
			k = b.new_key(b) # create a new Key (like a file)
			k.key = filename # set filename
			k.set_metadata("Content-Type", uploaded_file.mimetype) # identify MIME type
			k.set_contents_from_string(uploaded_file.stream.read()) # file contents to be added
			k.set_acl('public-read') # make publicly readable

			# if content was actually saved to S3 - save info to Database
			if k and k.size > 0:
				
				# submitted_image = models.Image()
				# submitted_image.title = request.form.get('title')
				# submitted_image.description = request.form.get('description')
				# submitted_image.postedby = request.form.get('postedby')
				# submitted_image.filename = filename # same filename of s3 bucket file
				# submitted_image.save()
				
				idea.filename = filename
				idea.save()	#save it


			return redirect('/ideas/%s' % idea.slug)

		else:
			# return "uhoh there was an error " + uploaded_file.filename
			idea.save()
			return redirect('/ideas/%s' % idea.slug)


	else:
		# get existing images
		images = models.Idea.objects.order_by('-timestamp')
		
		# render the template
		templateData = {
			# 'images' : images,
			'ideas' : models.Idea.objects(),
			'form' : photo_upload_form,
			'categories' : categories,
		}

		# app.logger.debug(templateData)
		return render_template("main.html", **templateData)