コード例 #1
0
ファイル: views.py プロジェクト: RawEvan/sharephotos
def homepage(request):
    """
    Homepage of the website.
    """

    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)

    if request.user.is_authenticated():
        # if search
        if request.method == 'POST':
            form = forms.search_form(request.POST or None)
            if form.is_valid():
                search_word = request.POST['search_word']
                photo_list = dbControl.get_photos_of_tag(search_word)
            else:
                pass
        # not search, get photos may be interested in
        else:
            search_word = ''
            photo_list = dbControl.get_interested_photos(email=email)
    # not login
    else:
        search_word = ''
        photo_list = dbControl.get_latest_photos()

    return_dict = {'photo_list': photo_list,
                  'search_word': search_word,
                  'latest_tag_list': latest_tag_list,
                  'user_Email': email}
    return render(request, u'index.html', return_dict)
コード例 #2
0
ファイル: directory_app.py プロジェクト: ikon42/reddit-unite
 def GET(self):
     q = web.input()
     t = template.env.get_template('search.html')
     f = search_form()
     try:
         if q.query:
             results = []
             user_list = []
             query = q.query.split(' ')
             for i in User.all():
                 x = util.strip_private_data(i)
                 if x is not None:
                     user_list.append(x)
             for p in user_list:
                 for i in query:
                     if i in dict(p).values():
                         results.append(p)
             return t.render(util.data(
                 title='Find who you\'re looking for!',
                 form=f,
                 results=results if results else None,
             ))
         else:
             web.debug('q.query doesn\'t exist and it didn\'t thow an exception!')
             raise Warning('Odd, huh?')
     except:
         return t.render(util.data(
             title='Find who you\'re looking for!',
             form=f,
         ))
コード例 #3
0
ファイル: views.py プロジェクト: RawEvan/sharephotos
def search(request):
    """
    Get search_word from the search form and check it, then redirects to
    view 'tag'.
    """

    form = forms.search_form(request.GET or None)
    photo_list = []
    search_word = ''
    if form.is_valid():
        search_word = request.GET['search_word']
    return HttpResponseRedirect(reverse('tag', args=[search_word]))
コード例 #4
0
ファイル: views.py プロジェクト: zombrie/kerbie
def search(request):
	searched = False
	profiles = {}
	numProfiles = 0
	userId = 0
	n = ''
	if request.method == 'POST':
		form = search_form(request.POST)
		if form.is_valid():
			n = form.cleaned_data.get('name')
			all_profiles = userProfile.objects.all()
			profiles = all_profiles.filter(username=n)
			if len(profiles) != 0:
				numProfiles = len(profiles)
			searched = True
			request.session['from_method'] = 'search'
			request.session['search_for'] = n
		else:
			print form.errors
	else:
		form = search_form()
	return render(request, 'kerbie/search.html', {'form': form, 'username':n, 'searched':searched, 'numProfiles': numProfiles})
コード例 #5
0
ファイル: views.py プロジェクト: levi-p/aff
def search(request):
    if request.method=='GET':
        form=search_form(request.POST)
        qr=request.GET.get('q','')
        if qr!='':
            
            try:
                g=(Q(Location__icontains=qr)|
                   Q(Name__icontains=qr))
                   #Q(Discription__icontains=qr))
                results = place_details.objects.filter(g)
                if list(results)==[]:
                    result2='No results found'
                
            except: result2='No results found'
    
    return render(request,'search_results.html',locals())
コード例 #6
0
ファイル: routes.py プロジェクト: Adel-B/amazon_app_infos
def search():

    form = search_form()

    if request.method == "POST":
        if form.validate() == False:
            return render_template("home.html", form=form)
        else:
            appurl = form.url.data

            # getting the application page via the url
            ua = UserAgent()
            headers = {"User-Agent": ua.random}
            try:
                page = requests.get(appurl,
                                    headers=headers,
                                    timeout=15,
                                    verify=False)
            except requests.exceptions.HTTPError as errh:
                return render_template('display_search_results.html',
                                       error="Http Error: " + errh)
            except requests.exceptions.ConnectionError as errc:
                return render_template('display_search_results.html',
                                       error="Connection Error :" + errc)
            except requests.exceptions.Timeout as errt:
                return render_template('display_search_results.html',
                                       error="Timeout Error :" + errt)
            except requests.exceptions.RequestException as err:
                return render_template('display_search_results.html',
                                       error="OOps: ERROR :" + err)

            # getting the html code to be parsed using Soup
            html = page.text
            soup = BeautifulSoup(html, features="html.parser")

            # retrieving app info using xpath
            try:
                root = lxml.html.fromstring(page.content)
                app_name = root.xpath(
                    '//*[@id="mas-title"]/div/span/text()')[0]
                app_version = root.xpath(
                    './/*[@id="masTechnicalDetails-btf"]/div[2]/span[2]/text()'
                )[0]
                app_changelog = root.xpath(
                    '//*[@id="mas-latest-updates"]/ul/li/span/text()')[0]
            except (IndexError, ValueError):
                err_msg = "No App info is found. please try with a different URL. Example: https://www.amazon.com/Instagram/dp/B00KZP2DTQ"
                return render_template('display_search_results.html',
                                       error=err_msg)

            # retrieving release date info using soup
            try:
                info_table = soup.find('table', id='productDetailsTable')
                row = info_table.findAll("li")
                app_original_release_date = row[1].getText().strip(
                    row[1].find("b").getText())
            except Exception as e:
                err_msg = "No App info is found. please try with a different URL. Example: https://www.amazon.com/Instagram/dp/B00KZP2DTQ"
                return render_template('display_search_results.html',
                                       error=err_msg)

            return render_template("display_search_results.html",
                                   name=app_name,
                                   version=app_version,
                                   changelog=app_changelog,
                                   release_date=app_original_release_date)

    elif request.method == 'GET':
        return render_template('home.html', form=form)