def temp():
    currdict = {}
    currdict['emailid'] = '*****@*****.**'
    currdict['url'] = 'http://bit.ly'
    from werkzeug.datastructures import MultiDict
    from app.forms import URLForm
    formdata = MultiDict(mapping=currdict)
    form = URLForm(formdata, csrf_enabled=False)

    if form.validate():
        return "yes"

    else:
        # msg = ""
        # for prop in form:
        # 	print prop.name+" " +prop.data
        # 	msg = msg + str(prop.data) + " "
        #
        # # msg = msg + form.emailid.data+" "+form.password.data+" "+"no"
        # # msg = msg + str(form.emailid.errors)
        # # msg =  msg + str(form.password.errors)
        msg = ''
        msg = msg + str(form.errors)
        return msg
    return render_template("temp.html", temptext='temp')
def validjson():
    print 'here'
    print request
    print request.headers
    print request.data
    print request.json
    # currdict = {}
    # currdict['emailid']  = '*****@*****.**'
    # currdict['url'] = 'http://bit.ly'

    from werkzeug.datastructures import MultiDict
    from app.forms import URLForm
    formdata = MultiDict(mapping=request.json)
    form = URLForm(formdata, csrf_enabled=False)

    if form.validate():
        return jsonify({'message': 'yes'}), 200

    else:
        # msg = ""
        # for prop in form:
        # 	print prop.name+" " +prop.data
        # 	msg = msg + str(prop.data) + " "
        #
        # # msg = msg + form.emailid.data+" "+form.password.data+" "+"no"
        # # msg = msg + str(form.emailid.errors)
        # # msg =  msg + str(form.password.errors)

        reply = {}
        reply['message'] = 'no'
        reply['erros'] = form.errors
        return jsonify(reply)
Example #3
0
def validjson():
	print 'here'
	print request
	print request.headers
	print request.data
	print request.json
	# currdict = {}
	# currdict['emailid']  = '*****@*****.**'
	# currdict['url'] = 'http://bit.ly'
	
	from werkzeug.datastructures import MultiDict
	from app.forms import URLForm
	formdata = MultiDict(mapping=request.json)
	form = URLForm(formdata, csrf_enabled=False)

	if form.validate():
		return jsonify({'message':'yes'}), 200

	else:
		# msg = ""
		# for prop in form:
		# 	print prop.name+" " +prop.data
		# 	msg = msg + str(prop.data) + " "
		#
		# # msg = msg + form.emailid.data+" "+form.password.data+" "+"no"
		# # msg = msg + str(form.emailid.errors)
		# # msg =  msg + str(form.password.errors)

		reply = {}
		reply['message'] = 'no'
		reply['erros'] = form.errors
		return jsonify(reply)
Example #4
0
def index():
    form = URLForm()
    if form.validate_on_submit():
        url = form.url.data
        session['url'] = url
        return redirect(url_for('processing'))
    return render_template('url.html', title='Sign In', form=form)
Example #5
0
def temp():
	currdict = {}
	currdict['emailid']  = '*****@*****.**'
	currdict['url'] = 'http://bit.ly'
	from werkzeug.datastructures import MultiDict
	from app.forms import URLForm
	formdata = MultiDict(mapping=currdict)
	form = URLForm(formdata, csrf_enabled=False)

	if form.validate():
		return "yes"

	else:
		# msg = ""
		# for prop in form:
		# 	print prop.name+" " +prop.data
		# 	msg = msg + str(prop.data) + " "
		#
		# # msg = msg + form.emailid.data+" "+form.password.data+" "+"no"
		# # msg = msg + str(form.emailid.errors)
		# # msg =  msg + str(form.password.errors)
		msg = ''
		msg =  msg + str(form.errors)
		return msg
	return render_template("temp.html", temptext='temp')
Example #6
0
def user_decks(user_id):
    user = current_user
    form = URLForm()
    url = ''
    if form.validate_on_submit():
        url = form.url.data
        ad = ArticleDeck.query.filter_by(url=url)
        if any(a for a in ad):
            deck = ad[0]
            ud = UserDeck.query.filter_by(user=user, deck=deck)
            if not any(d for d in ud):
                ud = UserDeck(user=user)
                ud.populate(ad[0])
        else:
            scraper = get_scraper(url)
            dm = DeckMaker(scraper.process_page())
            deck = dm.create_article(title=scraper.title, url=scraper.url)
            ud = UserDeck(user=user)
            ud.populate(deck)

    decks = user.get_decks()
    return render_template('user_decks.html',
                           title='My decks',
                           url=url,
                           form=form,
                           user=user,
                           user_decks=decks)
 def validateUrl(self, url):
     from werkzeug.datastructures import MultiDict
 	from app.forms import URLForm
     urldata = {}
     urldata['url']= url
 	formdata = MultiDict(mapping=urldata)
 	form = URLForm(formdata, csrf_enabled=False)
     return form.validate()
Example #8
0
def index():
    form = URLForm()
    if form.validate_on_submit():
        if not validators.url(form.url.data):
            return jsonify(success=False)
        alias = URLMap.insert(form.url.data)
        return jsonify(success=True, alias=alias)
    return render_template('index.html', form=form)
 def validateUrl(self, url):
     from werkzeug.datastructures import MultiDict
     from app.forms import URLForm
     urldata = {}
     urldata['url'] = url
     formdata = MultiDict(mapping=urldata)
     form = URLForm(formdata, csrf_enabled=False)
     return form.validate()
Example #10
0
def index():

    form = URLForm()

    form.name.choices = [(a.id, a.name)
                         for a in Product.query.order_by('name')]

    if form.validate_on_submit():
        return render_template('/product page/<name>', form=form)
    return render_template('index.html', form=form, product=Product)
Example #11
0
def thumbnail():
    """Fetch the thumbnail for an URL."""
    form = URLForm()

    thumbnail_url = None
    if form.validate_on_submit():
        # thumbnail_url = fetch_thumbnail(form.url.data)
        pass

    return render_template('tests/fetch_thumbnail.html', form = form, thumbnail_url = thumbnail_url)
Example #12
0
def read():
    """Fetch the readable content from an URL."""

    form = URLForm()

    readable = None
    if form.validate_on_submit():
        html = fetch_html(form.url.data)
        readable = get_readable(html, form.url.data)

    return render_template('tests/fetch_article.html', form = form, html_readable = readable)
Example #13
0
def url():
    form = URLForm()

    if form.validate_on_submit():
        result = perform_url_request(form.url.data, form.task.data)

        return render_template('result.html',
                               title='Results',
                               res=result,
                               task=form.task.data.lower())

    return render_template('url.html', title='URL', form=form)
Example #14
0
def new_task():
    # TODO: validate URL
    form_for_url = URLForm()
    if form_for_url.validate_on_submit():
        task_id = uuid.uuid4().hex
        db.session.add(Task(id=task_id, url=form_for_url.URL.data, status='added'))
        db.session.commit()

        send_task(task_id)
        flash('Your URL: {0} parsing with task №{1}'.format(form_for_url.URL.data, task_id))

        return task_id

    return redirect(url_for('index'))
Example #15
0
def index():
    form = URLForm()
    if form.validate_on_submit():
        flash('Playlist requested for URL {}'.format(form.url.data))
        session['reddit_url'] = form.url.data
        sp_oauth = spotipy.oauth2.SpotifyOAuth(client_id=client_id,
                                               client_secret=client_secret,
                                               redirect_uri=redirect_uri,
                                               scope=SCOPE)
        auth_url = sp_oauth.get_authorize_url()
        print(auth_url)
        return redirect(auth_url)

    if 'result' in session:
        return render_template('base.html',
                               form=form,
                               result=session.pop('result', None),
                               now=datetime.utcnow())
    else:
        return render_template('base.html', form=form, now=datetime.utcnow())
Example #16
0
def fetch(request):
    print("inside fetch")
    message = None
    if request.method == 'POST':
        print("inside fetch request post")
        url_form = URLForm(data=request.POST)
        if url_form.is_valid():
            url = request.POST.get("url")
            content = Content.objects.filter(
                Q(url=url) & Q(username=request.user)).values()
            if (len(content) == 0):
                print("inside fetch validity")
                url_obj = url_form.save(commit=True)
                data = get_content(url)
                if (data):
                    url_obj.username.add(request.user)
                    url_obj.response = data
                    url_obj.save()
                    return render(request, "app/content.html", {'data': data})
                else:
                    message = 'something went wrong, either check your internet connectivity or enter a valid url'

            else:
                data = content[0]['response']
                return render(request, "app/content.html", {'data': data})
        else:
            print(url_form.errors)
    else:
        url_form = URLForm()
    return render(request, 'app/fetch.html', {
        'url_form': url_form,
        'message': message
    })
Example #17
0
def url():
    form = URLForm()
    if form.validate_on_submit():
        return redirect(url_for('processing', input_url=form.input_url.data))
    return render_template('URL.html', title='Spotify 2019', form=form)
Example #18
0
def index():
    form_for_url = URLForm()
    form_for_task = TaskForm()
    all_tasks = Task.query.order_by(Task.start_time).all()
    return render_template('index.html', URLForm=form_for_url, TaskForm=form_for_task, tasks=all_tasks)
Example #19
0
def index():
    form=URLForm()
    return render_template('index.html', form=form)
def wikiHelper(kind, obj, objid, work):

    from app.models.graphmodels.graph_handle import GraphHandle
    from app.forms import AddRelationForm, URLForm
    from app.utils.commonutils import Utils
    # from py2neo import Node, Relationship
    gg = GraphHandle()

    copyobj = gg.coredb.copyObjectAsItIs(kind, obj)

    labels = diffLabelsNeeded(kind)

    needed = diffPropsNeeded(copyobj, kind=kind)
    ##helps!!
    for prop in needed:
        copyobj[prop] = ''

    form = ''
    form2 = URLForm()

    if kind == 'relation':

        form = AddRelationForm()

    if 'editForm' in request.form:  ##life saviour line! ##editForm is the submit button!

        ##TODO: remove uselsss flashes from here
        sourceurl = request.form.get('sourceurl')

        # print sourceurl
        # print len(sourceurl)
        flash(sourceurl)

        ##the ones that have arrived
        propnames = request.form.getlist('propname[]')
        propvals = request.form.getlist('propval[]')

        ##the ones that wre original
        orignames = request.form.getlist('actualpropname[]')
        origvals = request.form.getlist('actualpropval[]')

        ##will be empty if relation
        origlabels = request.form.getlist('origlabel[]')
        newlabels = request.form.getlist('newlabel[]')

        newobj = gg.coredb.copyObjectAsItIs(kind, copyobj)

        # ignore uuid
        # if props with same name again , consider later one

        flash(str(propnames) + " ::::: " + str(propvals))
        newpropdict = {
        }  ##will use later to see if contains orig prop that we mentioned
        ll = len(propnames)
        for i in range(ll):
            if (len(propnames[i].strip()) > 1):
                if (len(propvals[i].strip()) > 0):
                    newpropdict[propnames[i]] = propvals[
                        i]  #--------------VAR--------

        flash(str(orignames) + " :::::: " + str(origvals))
        #flash(str(needednames) +" :::::: "+str(neededvals))
        flash(str(newlabels))

        newlabelsnonempty = []  ##actual labels after striping
        for label in newlabels:
            if len(label.strip()) > 0:
                newlabelsnonempty.append(
                    label.strip())  #--------------VAR--------

        newobj = gg.coredb.copyObjectAsItIs(
            kind, copyobj
        )  ##we copy the object from core graph #--------------VAR--------
        ##so that it is a new object
        ##it is actually the copy of the original

        ll = len(origvals)
        origpropdict = {}
        for i in range(ll):
            if (len(orignames[i].strip()) > 1):
                if (len(origvals[i].strip()) >
                        0):  ##THOUGH HERE TOO WE HAVE KEEP HOLD ON '' name
                    newobj[orignames[i].strip()] = origvals[i].strip(
                    )  #--------------VAR--------

        flag = False
        msg = ""  ##todo: make alist

        if sourceurl is None or len(sourceurl) < 10:
            msg = msg + 'sourceurl check again' + ';;;'
            flag = True

        if kind == 'node':  ##THIS TAKES CARE OF NAME, very imp for add node
            if len(str(newobj['name']).strip()) < 3:  ##TODO: name validation
                msg = msg + ' name property too short' + ';;;'
                flag = True

        for prop in newpropdict:  ##THIS WILL TAKE CARE OF UUID OR RELID
            if prop in newobj:
                msg = msg + ' Added a custom prop that has same name as in our required prop list' + ';;;'
                flag = True

        ##soururl check
        ##new props names check
        ##type of our internalPropsConverter
        from app.apis.apivalidations import Validate
        validate = Validate()

        res, prop = validate.checkAllPropnamesValid(newpropdict)
        if not res:
            flag = True
            msg = msg + " error in propname: " + prop + ';;; '

        if not validate.validateUrl(sourceurl):
            flag = True
            msg = msg + " error in sourceurl ;;; "

        if flag:
            flash(msg)
            return render_template('user_edit.html',
                                   sourceurl=sourceurl,
                                   obj=newobj,
                                   newpropdict=newpropdict,
                                   needed=needed,
                                   labels=labels,
                                   newlabels=newlabelsnonempty,
                                   kind=kind,
                                   objid=objid,
                                   form=form,
                                   work=work)

        ##the newobj was a dummy, using the newobj
        nayaobj = gg.coredb.copyObjectAsItIs(kind, newobj)

        for label in newlabelsnonempty:
            nayaobj.labels.add(label)

        for prop in newpropdict:
            nayaobj[prop] = newpropdict[prop]

        for prop in newobj.properties:
            if len(str(newobj[prop]).strip()) == 0:
                nayaobj[prop] = None

        res, prop = validate.checkInternalProps(nayaobj.properties)
        if not res:
            flash("error in prop : " + prop)
            return render_template('user_edit.html',
                                   sourceurl=sourceurl,
                                   obj=newobj,
                                   newpropdict=newpropdict,
                                   needed=needed,
                                   labels=labels,
                                   newlabels=newlabelsnonempty,
                                   kind=kind,
                                   objid=objid,
                                   form=form,
                                   work=work)

        validate.internalPropsConverter(nayaobj.properties)

        # for prop in copyobj:
        # 	if type(copyobj[prop]) is list:
        # 		if prop in nayaobj: ##though it will be there
        # 			nayaobj[prop] = Utils.csvtolist(nayaobj[prop])

        ##adding MVP patch for wiki:
        # from app.constants import MVPLIST
        # for prop in MVPLIST:
        # 	if prop in nayaobj:
        # 		aliaslist = nayaobj[prop].split(',')
        # 		nayaobj[prop] = []
        # 		for alias in aliaslist:
        # 			if len(str(alias))>0:
        # 				nayaobj[prop].append(alias)

        ###XXX:
        ##jsonvalidatehelper
        ##make a json TODO
        ##validate json api call normal without token
        ##whould give true
        #json object to be made at this point for this object remove uuid and stuff
        ###and then validate that json using the code in api, when merge! TODO

        someobj = gg.wikiObjCreate(kind, nayaobj, session['userid'], sourceurl)

        flash(str(someobj))

        flash('Successfully pushed for moderation')

        if objid is not None:
            if kind == 'node':
                return redirect(url_for('readEntity', uuid=objid))
            if kind == 'relation':
                return redirect(url_for('readRelation', relid=objid))
        else:
            return redirect(url_for('home'))

    return render_template('user_edit.html',
                           sourceurl='',
                           obj=copyobj,
                           needed=needed,
                           labels=labels,
                           kind=kind,
                           objid=objid,
                           form=form,
                           work=work)