示例#1
0
文件: pin.py 项目: AlQemy/UCRinterest
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()
示例#2
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")
示例#3
0
def search_results(query):
    #tokenize
    terms = re.split('\s', query)
    #generate regular expression from tokens
    x = "|".join(map(str, terms))
    regx = re.compile(x, re.IGNORECASE)
    #query database
    pins = Pin.objects(Q(title=regx) | Q(dscrp=regx))
    if current_user != None:
        pins = Pin.objects(Q(title=regx) | Q(dscrp=regx))
        valid_pins = getValidBrowserPins(pins, current_user)
    return render_template("index.html", pins=valid_pins, upform=UploadForm())
示例#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')
示例#5
0
def search():
    #get form input
    query = request.form.get('q')
    #tokenize
    terms = re.split('\s', query)
    #generate regular expression from tokens
    x = "|".join(map(str, terms))
    regx = re.compile(x, re.IGNORECASE)
    #query database
    pins = Pin.objects(Q(title=regx) | Q(dscrp=regx))
    return render_template("index.html", pins=pins, upform=UploadForm())
示例#6
0
def favorites(uname):
    user = User.objects.get(uname=uname)
    pins = Pin.objects(favs__contains=user.to_dbref())
    valid_pins = getValidBrowserPins(pins, current_user)
    return render_template('profilepins.html', pins=valid_pins, upform=UploadForm(), user=user)
示例#7
0
def profile_pins(uname):
    user = User.objects.get(uname=uname)
    pins = Pin.objects(pinner=user.to_dbref()).order_by('-date')
    valid_pins = getValidBrowserPins(pins, current_user)
    return render_template('profilepins.html', pins=valid_pins, upform=UploadForm(), user=user)
示例#8
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'))
示例#9
0
def favorites():
    pins = Pin.objects(favs__contains=current_user.to_dbref())
    return render_template("profilepins.html", pins=pins, upform=UploadForm())
示例#10
0
def profilepins():
    pins = Pin.objects(pinner=current_user.to_dbref()).order_by("-date")
    return render_template("profilepins.html", pins=pins, upform=UploadForm())
示例#11
0
def favorites(uname):
    user = User.objects.get(uname=uname)
    pins = Pin.objects(favs__contains=user.to_dbref())
    return render_template('profilepins.html', pins=pins, upform=UploadForm(), user=user)
示例#12
0
def profilepins(uname):
    user = User.objects.get(uname=uname)
    pins = Pin.objects(pinner=user.to_dbref()).order_by('-date')
    return render_template('profilepins.html', pins=pins, upform=UploadForm(), user=user)