Пример #1
0
    def post(self, request, **kwargs):
        category = request.POST.get('category')
        location = request.POST.get('location')

        context = self.get_context_data(**kwargs)
        context['map'] = True

        if category:
            search = Search(**{'text': 'Category: {0}'.format(category)})
            search.save()
            museums = Museum.objects.filter(types__code=category)
            geojson = self.get_geojson(**{'name': category, 'museums': museums})
            context["jsonfile"] = category
        elif location:
            search = Search(**{'text': location})
            search.save()
            # Inputs: If just a state/abbrev given, show all items for that state only, no radius
            # Otherwise, geocode the result, run the vicenty distance
            if location.lower() in self.states_and_abbrevs:
                if len(location) != 2:
                    location = STATES_NORMALIZED.get(location.lower())
                context["jsonfile"] = location
                # TEMPORARY: EXCLUDE 11K GENERAL MUSEUMS FOR NOW -- Can always add them back later
                museums = Museum.objects.filter(state=location).exclude(types__code='GMU')
                if museums.count() > 0:
                    geojson = self.get_geojson(**{'name': location, 'museums': museums})
                    # By this point, location is always a two-letter abbreviation
                    address, (latitude, longitude) = self.geolocator.geocode(''.join([state_tuple[1] for state_tuple in US_STATES if state_tuple[0] == location]))
            else:
                try:
                    museums = []
                    address, (latitude, longitude) = self.geolocator.geocode(location)
                except Exception:
                    context["jsonfile"] = ""
                else:
                    if latitude and longitude:
                        all_museums = Museum.objects.exclude(types__code='GMU')

                        for museum in all_museums:
                            dist = vincenty(
                                (museum.latitude, museum.longitude), 
                                (latitude, longitude)
                            ).miles

                            if dist <= RADIUS:
                                museums.append(museum)

                        context["jsonfile"] = hashlib.sha256(location).hexdigest()[:8]
                        geojson = self.get_geojson(**{'name': context["jsonfile"], 'museums': museums})
                        context["latitude"] = latitude
                        context["longitude"] = longitude

        # context["geojson_path"] = PATH_PREFIX
        context['museums'] = museums

        return render(request, self.template_name, context)
Пример #2
0
def search_box(request):
	if request.method == 'GET':
		recent_search = Search(search_term=request.GET['search_term'].replace(" ",""),attribute=request.GET['attr'])
		recent_search.save()
		if request.GET['attr']=='movies':
			search_movie = request.GET['search_term'].replace(" ","")
			return HttpResponseRedirect ('/moviesearch/'+search_movie+'/')
		else:
			search_actor = request.GET['search_term'].replace(" ","")
			return HttpResponseRedirect ('/actorsearch/'+search_actor+'/')
Пример #3
0
 def get(self, request, format=None):
     try:
         query = request.GET.get('query')
         try:
             if request.user is AnonymousUser:
                 raise User.DoesNotExist()
             search = Search(user=request.user, query=query)
             search.save()
         except User.DoesNotExist:
             print "Anonymous Search"
         songs = search_songs(query)
         serial = SongSerializer(songs, many=True)
         return Response(serial.data, status=status.HTTP_200_OK)
     except MultiValueDictKeyError:
         return Response(request.data, status=status.HTTP_400_BAD_REQUEST)
Пример #4
0
    def save_to_db(self, const):
        # store in db, uses self.data Extract objects, iterate through and generate the appropriate injections for the db

        if const is "search_term":
            s_db = Search(date=timezone.now(), term=self.data[0].search_term)
            print "Adding %s data into db." % s_db
            s_db.save()
            for q in self.data:
                print q
                # save data around Search term for each Extract object in self.data
                # each Extract object has multiple links, get them all and associate to the created search term
                try:
                    for url in q.job_urls:
                        l_db = Links(search=s_db, link=url)
                        l_db.save()
                    # each Extract object has a single location, get it and associate it to search term
                    if q.loc != "":
                        loc_db = Location(city=q.city, state=q.state)
                        loc_db.save()
                    # each Extract object has a summary attribute that has all the data, modify the data pool to fit the parameters specified by user
                    # and store the data in a Results table associated to its Search table
                    summary = q.pool_summary(
                        pos=self.pos, with_filter=self.with_filter, lower=self.lower, with_bigrams=self.with_bigrams
                    )
                    data = summary[("Word", "Word_Count", "POS_Tag")]
                    for tup in data:
                        w = str(tup[0])
                        c = tup[1]
                        try:
                            p = str(tup[2])
                        except IndexError:
                            p = ""
                        r_db = Results(
                            search=s_db, location=loc_db, word=w, count=c, pos=p, is_bigram=self.with_bigrams
                        )
                        r_db.save()
                except:
                    if q.loc != "":
                        loc_db = Location(city=q.city, state=q.state)
                        loc_db.save()
                    r_db = Results(search=s_db, location=loc_db, word="N/A", count=0, pos="", is_bigram=False)
                    r_db.save()
Пример #5
0
def index(request):
    if request.method == 'POST':  # If the form has been submitted...
        form = SearchForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass

            valor = Search()

            valor.sdata = request.POST['sdata']
            valor.sdate = request.POST['sdate']

            valor.save()

            return render(request, 'form.html', {
                'form': form,
            })
    else:
        form = SearchForm()  # An unbound form

    return render(request, 'form.html', {
        'form': form,
    })
Пример #6
0
 def save_to_db(self,const):
     # store in db, uses self.data Extract objects, iterate through and generate the appropriate injections for the db
     
     if const is "search_term":
         s_db = Search(date=timezone.now(),term=self.data[0].search_term)
         print "Adding %s data into db."% s_db
         s_db.save()
         for q in self.data:
             print q
             # save data around Search term for each Extract object in self.data
             # each Extract object has multiple links, get them all and associate to the created search term
             try:
                 for url in q.job_urls:
                     l_db = Links(search=s_db, link=url)
                     l_db.save()
                 # each Extract object has a single location, get it and associate it to search term
                 if q.loc != "":
                     loc_db = Location(city=q.city,state=q.state)
                     loc_db.save()
                 # each Extract object has a summary attribute that has all the data, modify the data pool to fit the parameters specified by user
                 # and store the data in a Results table associated to its Search table
                 summary = q.pool_summary(pos=self.pos, with_filter=self.with_filter, lower=self.lower, with_bigrams=self.with_bigrams)
                 data = summary[('Word', 'Word_Count', 'POS_Tag')]
                 for tup in data:
                     w = str(tup[0])
                     c = tup[1]
                     try:
                         p = str(tup[2])
                     except IndexError:
                         p = ""
                     r_db = Results(search=s_db,location=loc_db,word=w,count=c,pos=p,is_bigram=self.with_bigrams)
                     r_db.save()
             except:
                 if q.loc != "":
                     loc_db = Location(city=q.city,state=q.state)
                     loc_db.save()
                 r_db = Results(search=s_db,location=loc_db,word="N/A",count=0,pos="",is_bigram=False)
                 r_db.save()