Exemplo n.º 1
0
def upload():
    form = UploadForm()
    if form.validate():
        if form.title.data == "":
            flash("Must include title")
            return redirect(request.referrer + "#add_form")
        filename = secure_filename(form.photo.data.filename)
        pos = filename.rfind('.')
        if pos < 0 or (pos >= 0 and (not filename[pos + 1 : ] in ALLOWED_EXTENSIONS)):
            flash("Error: Invalid extension, pleases use jpg or png")
            return redirect(request.referrer + '#add_form')
        while os.path.isfile(os.path.join(current_app.config['UPLOAD_FOLDER'], filename)):
            filename = '_' + filename
        form.photo.file.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
        pin = Pin(title=form.title.data,
                  img=filename,
                  dscrp=form.dscrp.data,
                  orig=True,
                  date=datetime.now(),
                  pinner=current_user.to_dbref(),
                  repins=0,
                  like_count=0)
        pin.save()
        flash("Image has been uploaded.")
    else:
        flash("Image upload error.")
    return redirect('viewprofile/%s/pins' % str(current_user.uname) + "#add_form")
Exemplo n.º 2
0
def createPin(title, img, dscrp):
    """Creates pin
    - title : the pin title
    - img : the image path
    - dscrp : the image description 
    """
    if allowed_file(img):
        orig = True
        try:
            pinQuery = Pin.objects.get(img_path=img_path)
            if pinQuery is not None:
                orig = False
        except Pin.DoesNotExist:
            pass

        pin = Pin(
            title=title,
            img=img,
            pinner=current_user.to_dbref(),
            dscrp=dscrp,
            orig=orig,
            date=datetime.now(),
            repins=0,
            like_count=0,
        )
        pin.save()
        if pin.repins == None:
            fix_repins()
Exemplo n.º 3
0
def make():
    pin = Pin(title="Settings 1", img="img1.jpg", dscrp="Description 1", orig=True, date=datetime.now(), pinner=current_user.to_dbref())
    pin.save()
    pin = Pin(title="Settings 2", img="img2.jpg", dscrp="Description 2", orig=True, date=datetime.now(), pinner=current_user.to_dbref())
    pin.save()
    pin = Pin(title="Settings 3", img="img3.jpg", dscrp="Description 3", orig=True, date=datetime.now(), pinner=current_user.to_dbref())
    pin.save()
    pin = Pin(title="Settings 4", img="img4.jpg", dscrp="Description 4", orig=True, date=datetime.now(), pinner=current_user.to_dbref())
    pin.save()
    flash("Pins Created!")
    return redirect(url_for('index'))
Exemplo n.º 4
0
def repin():
    id = request.form.get('id')
    pin = Pin.objects.get(id=id)
    newpin = Pin(title=pin.title,
                 img=pin.img,
                 dscrp=pin.dscrp,
                 orig=False,
                 date=datetime.now(),
                 pinner=current_user.to_dbref(),
                 repins=0,
                 like_count=0)
    newpin.save()
    if pin.repins == None:
        fix_repins()
        pin = Pin.objects.get(id=id)
    pin.repins = pin.repins + 1
    pin.save()
    flash("Pin repinned")
    return redirect('/viewprofile')