Esempio n. 1
0
def category(request, category_name_slug):

    context_dict = {}
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':

        #Using try here cause page is expected search POST
        #But sometimes gets a re-direct from add_page causing this to break
        try:
            query = request.POST['query'].strip()

            if query:
                # Run our Bing function to get the results list!
                result_list = run_query(query)

                context_dict['result_list'] = result_list
                context_dict['query'] = query
        except:
            pass

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
def category(request, category_name_url):
    context = RequestContext(request)
    cat_list = get_category_list()
    category_name = decode_url(category_name_url)
    query = category_name
    context_dict = {
        'cat_list': cat_list,
        'category_name': category_name,
        'category_name_url': category_name_url,
        'query': query
    }

    try:
        category = Category.objects.get(name=category_name)

        # Add category to the context so that we can access the id and likes
        context_dict['category'] = category

        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages

        result_list = []
        if request.method == 'POST':
            query = request.POST['query'].strip()
            if query:
                # Run our google function to get the results list!
                result_list = run_query(query)
                context_dict['result_list'] = result_list
                context_dict['query'] = query

    except Category.DoesNotExist:
        pass
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 3
0
def category(request, category_name_slug):
    context_dict = {'slug': category_name_slug}
    template = 'rango/category.html'
    result_list = []

    if request.method == 'POST':
        if 'query' in request.POST:
            query = request.POST['query'].strip()
            if query:
                # Run our Bing function to get the results list!
                result_list = run_query(query)
                context_dict['result_list'] = result_list
    try:
        # Can we find a category name slug with the given name?
        # If we can't, the .get() method raises a DoesNotExist exception.
        # So the .get() method returns one model instance or raises an exception.
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name

        # Retrieve all of the associated pages.
        # Note that filter returns >= 1 model instance.
        pages = Page.objects.filter(category=category).order_by('-views')

        # Adds our results list to the  template context under name pages.
        context_dict['pages'] = pages
        # We also add the category object from the database to the context dictionary.
        # We'll use this in the template to verify that the category exists.
        context_dict['category'] = category
    except Category.DoesNotExist:
        # We get here if we didn't find the specified category.
        # Don't do anything - the template display the "no category" message for us.
        pass

    # Go render the reponse and return it to the client.
    return render(request, template, context_dict)
Esempio n. 4
0
def category(request, category_name_url):
    context = RequestContext(request)
    category_name = decode_url(category_name_url)
    context_dict = {'category_name': category_name}
    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list
    try:
        category = Category.objects.get(name=category_name)
        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_url'] = category_name_url
    except Category.DoesNotExist:
        pass

    try:
        category = Category.objects.get(name__iexact=category_name)
        context_dict['category'] = category
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
    except Category.DoesNotExist:
        pass
    if request.method == 'POST':
        query = request.POST.get('query', False)  #.strip()
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list
    return render(request, 'rango/category.html', context_dict, context)
Esempio n. 5
0
def category(request, category_name_slug):

    context_dict = {}

    try:

        #can we find a category name slug with the given name?
        # if we can't, the .get() method raises a doesnotexist exception
        # so the .get() method returns one model instance or raises an exception
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        context_dict['category_name_slug'] = category_name_slug
        #retriveve all of the associated pages.
        #note that filter returns >=1 model instance

        pages = Page.objects.filter(category=category)

        #adds our results list to the template context under name pages
        context_dict['pages'] = pages
        #we also add the category object from the database to the conext dictionary
        # we use this in the template to verify if the category exists
        context_dict['category'] = category
    except Category.DoesNotExist:
        pass

    if request.method == 'POST':
        query = request.POST.get('query')
        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

        #render the response and return it to the client
    return render(request, 'rango/category.html', context_dict)
Esempio n. 6
0
def category(request, category_name_slug):

    #Create a blank dict for the rendering engine
	context_dict = {}

	if request.method == 'POST':
		query = request.POST['query'].strip()

		if query:

			#run the bing search function
			result_list = run_query(query)

		return render(request, 'rango/search.html', {'result_list': result_list})

	else:

		try:
	        #find the category that matches the slug url
			category = Category.objects.get(slug=category_name_slug)
			context_dict['category_name'] = category.name
			print category
			pages = Page.objects.filter(category=category)

			context_dict['pages'] = pages
			context_dict['category'] = category

		except Category.DoesNotExist:
	        #If nothing is found
			pass
	#Render it up
	return render(request, 'rango/category.html', context_dict)
Esempio n. 7
0
def category(request, category_name_url):
    context = RequestContext(request)
    category_name = decode_url(category_name_url)#category_name_url.replace('_', ' ')
    context_dict = {'category_name': category_name}

    try:
        category = Category.objects.get(name=category_name)
        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_url'] = category_name_url
    except Category.DoesNotExist:
        pass
    context_dict['cat_list'] = get_category_list()

    ##search###
    result_list = []
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)


    context_dict['result_list'] = result_list


    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 8
0
File: views.py Progetto: dskvyra/twd
def category(request, category_name_url):
    context = RequestContext(request)
    category_name = decode_url(category_name_url)
    cat_list = get_category_list()
    context_dict = {'category_name': category_name,
                    'category_name_url': category_name_url,
                    'cat_list': cat_list,}

    try:
        # category = Category.objects.get(name=category_name)
        category = Category.objects.get(name__iexact=category_name)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['category'] = category
        context_dict['pages'] = pages
    except Category.DoesNotExist:
        pass

    if request.method == 'POST' and request.POST.has_key('query'):
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 9
0
def category(request, category_name_slug):
	# context dictionary to pass to the template rendering engine
	context_dict = {}
	context_dict['result_list'] = None
	context_dict['query'] = None
	if request.method == 'POST':
		query = request.POST['query'].strip()
		if query:
			# Run the Bing function to get the result list
			result_list = run_query(query)
			context_dict['result_list'] = result_list
			context_dict['query'] = query

	try:
		# if we cannot find the slug-name, get() raises DoesNotExist exception
		category = Category.objects.get(slug=category_name_slug)
		context_dict['category_name'] = category.name

		# retrieve all the pages
		pages = Page.objects.filter(category=category).order_by('-views')
		# Adds results list to the template context 
		context_dict['pages'] = pages
		# also add category object from db to the context 
		context_dict['category'] = category
		context_dict['category_name_slug'] = category_name_slug
	except Category.DoesNotExist:
		# dont do anything
		pass

	return render(request, 'rango/category.html', context_dict)
Esempio n. 10
0
def show_category(request, category_name_slug):
    context_dict = {}
    result_list = []
    query = ""
    if request.method == "POST":
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
    context_dict['query'] = query
    context_dict['result_list'] = result_list
    try:
        category = Category.objects.get(slug=category_name_slug)
        if request.method == 'GET':
            category.views = category.views + 1
            category.save()
            # form = update_cat(request.POST, category)
        category = Category.objects.get(slug=category_name_slug)
        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        context_dict['category'] = None
        context_dict['pages'] = None

    return render(request, 'rango_t/category.html', context_dict)
Esempio n. 11
0
def show_category(request, category_name_slug):
    context_dict = {}

    try:
        category = Category.objects.get(slug=category_name_slug)
        category.views = category.views + 1

        pages = Page.objects.filter(category=category)

        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['views'] = category.views
        
        category.save()
    except Category.DoesNotExist:
        context_dict['category'] = None
        context_dict['pages'] = None

    print("Show category wali: ",request)
    #search func
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':
        query = request.POST.get('query')
        print(query)
        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context_dict['result_list'] = result_list
            context_dict['query'] = query

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
Esempio n. 12
0
def category(request, category_name_slug):

    context_dict = {}
    context_dict['query'] = None

    result_list = []
    # Search request
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context_dict['result_list'] = result_list
            context_dict['query'] = query

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name

        pages = Page.objects.filter(category=category).order_by('-views')

        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_slug'] = category_name_slug
    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
    def post(self, request, category_name_slug):
        # create context dict to pass to template rendering engine
        context_dict = {}
        try:
            # try to find a category with the given name
            # if no .get() raise DoesNotExist exception
            # get() method returns model instance or raises exception
            category = Category.objects.get(slug=category_name_slug)

            # Retrieve associated pages
            # filter( returns list of page objects or empty list
            pages = Page.objects.filter(category=category).order_by('-views')

            # Add results list to template context under name pages
            context_dict['pages'] = pages

            # Also add category object from database to context dict
            # to verify existance in template
            context_dict['category'] = category
        except:
            # if there is no such category
            context_dict['category'] = None
            context_dict['pages'] = None
        # render the response and return to client

        context_dict['result_list'] = []
        context_dict['query'] = ""
        if request.method == 'POST':
            context_dict['query'] = request.POST['query'].strip()
            if context_dict['query']:
                context_dict['result_list'] = run_query(context_dict['query'])

        return render(request, 'rango/category.html', context_dict)
Esempio n. 14
0
def search(request):
    result_list = []
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:  # Run our Bing function to get the results list!
            result_list = run_query(query)
    return render(request, 'rango/category.html', {'result_list': result_list})
Esempio n. 15
0
def category(request, category_name_url):
    # Request our context from the request passed to us.
    context = RequestContext(request)

    # Change underscores in the category name to spaces.
    # URLs don't handle spaces well, so we encode them as underscores.
    # We can then simply replace the underscores with spaces again to get the name.
    category_name = decode_url(category_name_url)

    # Create a context dictionary which we can pass to the template rendering engine.
    # We start by containing the name of the category passed by the user.
    context_dict = {'category_name': category_name, 'category_name_url': category_name_url}

    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list

    try:
        category = Category.objects.get(name__iexact=category_name)
        context_dict['category'] = category
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages

    except Category.DoesNotExist:
        pass

    if request.method == 'POST':
        query = request.POST.get('query')
        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    # Go render the response and return it to the client.
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 16
0
def category(request, category_name_url):
    context = RequestContext(request)
    cat_list = get_category_list()
    category_name = decode_url(category_name_url)

    context_dict = {'cat_list': cat_list, 'category_name': category_name, 'category_name_url': category_name_url}

    try:
        category = Category.objects.get(name=category_name)
    
        # Add category to the context so that we can access the id and likes
        context_dict['category'] = category
    
        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
    except Category.DoesNotExist:
        pass
    
    if request.method == 'POST':
        print "IN POST"
        query = request.POST.get('query')
        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 17
0
def category(request, category_name_url):
	# Request our context from request
	context = RequestContext(request)

	# change underscores in category name to spaces
	category_name = decode_url(category_name_url)

	# create context dictionary to pass to template
	context_dict = {'category_name': category_name}
	context_dict['category_name_url'] = encode_url(category_name_url)
	cat_list = get_category_list()
	context_dict['cat_list'] = cat_list

	try:
		category = Category.objects.get(name=category_name)

		pages = Page.objects.filter(category=category).order_by('-views')

		# Add pages and category to the context dicitionary
		context_dict['pages'] = pages
		context_dict['category'] = category
	except Category.DoesNotExist:
		pass

	if request.method == 'POST':
		query = request.POST['query'].strip()
		if query:
			result_list = run_query(query)
			context_dict['result_list'] = result_list

	return render_to_response('rango/category.html', context_dict, context)
Esempio n. 18
0
def search(request):
    results = []
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            results = run_query(query)
    return render(request, 'rango/search.html', {'results': results})
Esempio n. 19
0
def category(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)
    category_valid = get_object_or_404(Category, name=category_name)
    cat_list = get_category_list()
    context_dict = {'category_name_url': category_name_url,
                    'category': category_name,
                    'category_valid': category_valid,
                    'cat_list': cat_list,
                    }
    try:
        category = Category.objects.get(name=category_name)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category

    except Category.DoesNotExist:
        pass

    if request.method == "POST":
        if 'query' in request.POST:
            query = request.POST['query'].strip()

            if query:
                result_list = run_query(query)
                context_dict['result_list'] = result_list
                return render_to_response('rango/category.html', context_dict, context)

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 20
0
def show_category(request, category_name_slug):
    context_dict = {}

    try:
        category = Category.objects.get(slug=category_name_slug)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category

    except Category.DoesNotExist:
        context_dict['category'] = None
        context_dict['pages'] = None

    # Code here to handle POST request
    context_dict['query'] = category.name

    result_list = []
    if request.method == 'POST':
        query = request.POST
        if query:
            # Run Bing search, append result to context_dict
            result_list = run_query(query)
            context_dict['query'] = query
            context_dict['result_list'] = result_list

    return render(request, 'rango/category.html', context_dict)
Esempio n. 21
0
File: views.py Progetto: onty/django
def category(request, category_name_url):
    context = RequestContext(request)
    #category_name = category_name_url.replace('_',' ')
    category_name = UrlHelper('decode',category_name_url)
    context_dict = {'category_name': category_name}

    try:
        category = Category.objects.get(name__iexact=category_name)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_url'] = category_name_url
        context_dict['cat_list'] = get_category_list
    except  Category.DoesNotExist:
        return render_to_response('rango/category_not_found.html', context_dict, context)

    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 22
0
def category(request, category_name_url):
	# REquest our context from the request passed to us
	context = RequestContext(request)
	category_name = category_name_url.replace('_',' ')
	context_dict = {'category_name':category_name}
	context_dict['cats'] = get_category_list()
	try: 
		category = Category.objects.get(name=category_name)
		pages = Page.objects.filter(category=category) #Get the corresponding pages for the Category Object)\
		context_dict['pages'] = pages   #Adding the pages to the dict
		context_dict['category']= category   #Adding the category to dict to check the category in the template
		context_dict['category_name_url']= category_name_url
	except Category.DoesNotExist:
		pass
	
	#Search Functionality
	result_list = []
	if request.method == 'POST':
		query = request.POST['query'].strip()
		if query:
			result_list = run_query(query)
	context_dict['cats']=get_category_list()
	context_dict['result_list'] = result_list
	
	return render_to_response('rango/category.html', context_dict, context)
Esempio n. 23
0
def category(request, category_name_url):

	context = RequestContext(request)
	category_list = get_category_list()

	category_name = category_name_url.replace('_', ' ')

	context_dict = {'category_name': category_name, 'categories': category_list}

	try:
		category = Category.objects.get(name=category_name)

		pages = Page.objects.filter(category=category).order_by('-views')

		context_dict['pages'] = pages

		context_dict['category'] = category

		context_dict['category_name_url'] = category_name_url
	
	except Category.DoesNotExist:
		pass

	if request.method == 'POST':
		query = request.POST['query'].strip()

		if query:
			#Bing function:
			result_list = run_query(query)
			context_dict['result_list'] = result_list

	return render_to_response('rango/category.html', context_dict, context)
Esempio n. 24
0
def category(request, category_name_slug):

    context_dict = {}
    
    try:
        
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        
        pages = Page.objects.filter(category= category)
        
        context_dict['pages'] = pages
        
        context_dict['category'] = category
        
        context_dict['slug'] = category_name_slug
        
        context_dict['results'] = []
    
        if request.method =='POST':
            query = request.POST['query'].strip()
        
            if query:
        
                context_dict['results'] = run_query(query)
    
    except Category.DoesNotExist:
        pass
        
    return render(request, 'rango/category.html', context_dict)
Esempio n. 25
0
def category(request, category_name_slug):

    context_dict = {}
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':

    #Using try here cause page is expected search POST
    #But sometimes gets a re-direct from add_page causing this to break
        try:
            query = request.POST['query'].strip()

            if query:
                # Run our Bing function to get the results list!
                result_list = run_query(query)

                context_dict['result_list'] = result_list
                context_dict['query'] = query
        except:
            pass

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
Esempio n. 26
0
def category(request, category_name_url):


    context = RequestContext(request)
    category_name = endecode(category_name_url)
    category_list = get_5_categories()

    context_dict = {'category_name': category_name, 'category_name_url': category_name_url, 'categories': category_list}

    try:

        category = Category.objects.get(name=category_name)
        context_dict['category'] = category

        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages

    except Category.DoesNotExist:
        pass


    if request.method == 'POST':
        if 'query' in request.POST:
            query = request.POST['query'].strip()
            print query

            if query:
                result_list = run_query(query)
                print result_list
                context_dict['result_list'] = result_list


    # Go render the response and return it to the client.
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 27
0
File: views.py Progetto: 400yk/tango
def category(request, category_name_url):
    context = RequestContext(request)
    # URL doesn't handle space well, we encode them into underscores
    category_name = encoding(category_name_url)
    context_dict = {'category_name' : category_name}

    try:
        category = Category.objects.get(name = category_name)
        pages = Page.objects.filter(category = category).order_by('-views')

        context_dict['pages'] = pages
        context_dict['category_name_url'] = category_name_url
        context_dict['category'] = category
        context_dict['categories'] = get_categories()

    except Category.DoesNotExist:
        pass

    result_list = []

    if request.method == "POST":
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 28
0
def category(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)

    context_dict = {
        'category_name_url': category_name_url,
        'cat_list': get_category_list()
    }

    try:
        category = Category.objects.get(name=category_name)

        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        # Will trigger the template to display the 'no category' message.
        pass

    # This is a bug when redirected to Category? I think.
    if request.method == 'POST':
        query = request.POST.get('query', '').strip()
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 29
0
def category(request, category_name_slug):

    context_dict = {}
    context_dict["result_list"] = None
    context_dict["query"] = None
    if request.method == "POST":
        query = request.POST["query"].strip()

        if query:
            result_list = run_query(query)
            context_dict["result_list"] = result_list
            context_dict["query"] = query

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict["category_name"] = category.name

        pages = Page.objects.filter(category=category)

        context_dict["pages"] = pages
        context_dict["category"] = category
    except Category.DoesNotExist:
        pass

    return render(request, "rango/category.html", context_dict)
Esempio n. 30
0
def category(request, category_name_slug):
    context_dict = {}
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)

            context_dict['result_list'] = result_list
            context_dict['query'] = query

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        try:
            context_dict['query'] = category.name
            context_dict['notfound'] = False
        except:
            context_dict['notfound'] = True
            pass

    return render(request, 'rango/category.html', context_dict)
Esempio n. 31
0
def show_category(request, category_name_slug):
    context_dict = {}
    try:
        # Get category_name_slug if exist, if not it'll raise a DoesNotExist exception
        category = Category.objects.get(slug=category_name_slug)
        # Return a filtered list of objects or an empty list
        pages = Page.objects.filter(category=category)
        # Set or append data to context dict/rango
        context_dict['pages'] = pages
        context_dict['category'] = category
    except Category.DoesNotExist:
        # Do nothing if not exist, the template will display 'no category' message
        context_dict['category'] = None
        context_dict['pages'] = None

    # Handle POST request from the search field
    result_list = []
    curr_query = ''
    if request.method == 'POST':
        query = request.POST['query'].strip()
        curr_query = query
        # Check if there's a query
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list
            context_dict['query'] = curr_query
    # print('Yes' if Page.objects.filter(title='TWICE "YES or YES" M/V - YouTube').exists() else 'No')
    return render(request,
                  'rango/category.html',
                  context_dict)
Esempio n. 32
0
def category(request, category_name_slug):
    
    context_dict = {'category_name_slug': category_name_slug}
        
    try:
        
        category = Category.objects.get(slug = category_name_slug)
        
        context_dict['category_name'] = category.name
        
        pages = Page.objects.filter(category = category)
        
        context_dict['pages'] = pages
        
        context_dict['category'] = category
        
    except Category.DoesNotExist:
        my_str = category_name_slug.split('-')
        context_dict['category_name'] = ' '.join([i.capitalize() for i in my_str])
        
    result_list = []
    query = ''
    
    if request.method == 'POST':
        if request.POST.get('query', False):
            query = request.POST['query'].strip()
        
        if query:
            result_list = run_query(query)
            
    context_dict['result_list'] = result_list
    context_dict['query'] = query
        
    
    return render(request, 'rango/category.html', context_dict)
Esempio n. 33
0
def category(request, category_name_slug):
    context_dict = {}
    context_dict["result_list"] = None
    context_dict["query"] = None
    if request.method == "POST":
        query = request.POST["query"].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)

            context_dict["result_list"] = result_list
            context_dict["query"] = query

    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict["category_name"] = category.name
        pages = Page.objects.filter(category=category).order_by("-views")
        context_dict["pages"] = pages
        context_dict["category"] = category
    except Category.DoesNotExist:
        pass

    if not context_dict["query"]:
        context_dict["query"] = category.name

    return render(request, "rango/category.html", context_dict)
Esempio n. 34
0
def show_category(request, category_name_slug):
    #creare a context dictionary which we can pass
    # to the template rendeing engine
    context_dict = {}
    try:
        #can we find a category slug with the given name?
        #if we cannot, the .get() method raises a dosenotexist exception
        #so the .get() method returns one model instance or raises an exception
        category = Category.objects.get(slug=category_name_slug)
        #retrive all of the associated pages
        #note that filter() will return a list of page objects or an empty list
        pages = Page.objects.filter(category=category).order_by('-views')
        #add our results list to the template context under name pages
        context_dict['pages'] = pages
        #we also add the category object from the database to the dictionary
        #we will use this in the template to verify that the category exists
        context_dict['category'] = category
    except Category.DoesNotExist:
        #we get here if we did not find thet specified category
        # don't do anything
        # the template will display the no category message for Us
        context_dict['category'] = None
        context_dict['pages'] = None
    # start new search functionality
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            #run our bing function to get the results list!
            context_dict['result_list'] = run_query(query)
            context_dict['query'] = query
    #render the response and return it ti the client
    return render(request, 'rango/category.html', context_dict)
Esempio n. 35
0
def category(request, category_name_slug):
    # Create a context dictionary which we can pass to the template rendering engine
    context_dict = {}
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list
            context_dict['query'] = query
    try:
        # Can we find a category name slug with the given name?
        # If we can't, the .get() method raised a DoesNotExist exception
        # So the .get() method return one model instance or raise an exception
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name


        # Rtrieve all of associated pages
        # Note that filter return >= 1 model instance.
        pages = Page.objects.filter(category=category)

        # Add our result list to template context under name pages
        context_dict['pages'] = pages

        # we also add category object from database to the context dictionary.
        # we'll use thie in the template to verify that category exist.
        context_dict['category'] = category
    except Category.DoesNotExist:
        # we get here if we have not find the specified category
        # Don't do anything - the template display the "no category" message for us
        pass
    # Go render the response and return it to the client
    return render(request, 'rango/category.html', context_dict)
Esempio n. 36
0
def category(request, category_name_url):
    context = RequestContext(request)
    cat_list = get_category_list()
    category_name = decode_url(category_name_url)

    context_dict = {
        'cat_list': cat_list,
        'category_name': category_name,
        'category_name_url': category_name_url
    }

    try:
        category = Category.objects.get(name=category_name)

        # Add category to the context so that we can access the id and likes
        context_dict['category'] = category

        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
    except Category.DoesNotExist:
        pass

    if request.method == 'POST':
        print "IN POST"
        query = request.POST.get('query')
        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 37
0
def category(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)
    cat_list = get_category_list()

    context_dict = {"category_name": category_name, "category_name_url": category_name_url, "cat_list": cat_list}

    try:
        category = Category.objects.get(name__iexact=category_name)

        pages = Page.objects.filter(category=category).order_by("-views")

        context_dict["pages"] = pages

        context_dict["category"] = category

    except Category.DoesNotExist:
        pass

    if request.method == "POST":
        query = request.POST.get("query")
        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict["result_list"] = result_list

    return render_to_response("rango/category.html", context_dict, context)
Esempio n. 38
0
def category(request, category_name_slug):
    context_dict = { 'query': None, 'result_list': None }

    if request.method == "POST":
        query = request.POST['query'].strip()
        if query:
            context_dict['query'] = query
            context_dict['result_list'] = run_query(query)

    try:
        cat = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = cat.name
        context_dict['category_name_slug'] = category_name_slug

        pages = Page.objects.filter(category=cat).order_by('-views')

        context_dict['pages'] = pages
        context_dict['category'] = cat
    except Category.DoesNotExist:
        context_dict['category_name'] = category_name_slug

    if not context_dict['query']:
        context_dict['query'] = cat.name

    return render(request, 'rango/category.html', context_dict)
Esempio n. 39
0
def category(request, category_name_slug):
    result_list = None
    query = None
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
    try:
        # Can we find a category name slug with the given name?
        # If we can't, the .get() method raises a DoesNotExist exception.
        # So the .get() method returns one model instance or raises an exception.
        category = Category.objects.get(slug=category_name_slug)
        category_name = category.name
        # Retrieve all of the associated pages.
        # Note that filter returns >= 1 model instance.
        pages = Page.objects.filter(category=category).order_by('-views')
    except Category.DoesNotExist:
        # We get here if we didn't find the specified category.
        # Don't do anything - the template displays the "no category" message for us.
        pass
    
    if not query:
        assert isinstance(category.name, object)
        query = category.name

    return render(request, 'rango/category.html', {'category': category, 'category_name': category_name,
                                                   'pages': pages, 'category_name_slug': category_name_slug,
                                                   'result_list': result_list, 'query': query})
Esempio n. 40
0
def category(request, category_name_url):
    
    context = RequestContext(request)
    category_name = decode_url(category_name_url)

    # search function    
    result_list = []
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
    
    context_dict = {}
    
    try:
        category = Category.objects.get(name__exact=category_name)
        pages = Page.objects.filter(category=category)
        
        
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name'] = category.name
        context_dict['category_name_url'] = category_name_url
        context_dict['cat_list'] = get_category_list()
        context_dict['search_result_list'] = result_list
    except Category.DoesNotExist:
        pass
    
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 41
0
def category(request, category_name_slug):
    context = {}
    try:
        category = Category.objects.filter(slug=category_name_slug)[0]
        context['category_name'] = category.name
        category.views+=1
        category.save()

        pages = Page.objects.filter(category=category)
        context['pages'] = pages

        context['category'] = category
    except:
        pass

    result_list = []

    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context['result_list'] = result_list


    return render(request, 'rango/category.html', context)
Esempio n. 42
0
def category(request, category_name_url):
    context = RequestContext(request)
    # Replace undrescores in ulr to spaces
    category_name = decode_category_name(category_name_url)
    category_list = get_category_list()
    context_dict = {'category_name': category_name, 'categories': category_list,}
    if request.method == "POST":
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list


    try:
        category = Category.objects.get(name=category_name)
        # return pages associated to the category
        pages = Page.objects.filter(category=category)
        # Add category to context dictionary to verify category exists
        context_dict['category'] = category
        context_dict['pages'] = pages
        context_dict['category_name_url'] = category_name_url

    except Category.DoesNotExist:
        # Template will display "Does not exist" message
        pass

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 43
0
def search(request):
    result_list = []
    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
    return render(request, 'rango/search.html', {'result_list': result_list})
Esempio n. 44
0
def category(request, category_name_url):
    context = RequestContext(request)
    category_name = decode_url(
        category_name_url)  #category_name_url.replace('_', ' ')
    context_dict = {'category_name': category_name}

    try:
        category = Category.objects.get(name=category_name)
        pages = Page.objects.filter(category=category)
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_url'] = category_name_url
    except Category.DoesNotExist:
        pass
    context_dict['cat_list'] = get_category_list()

    ##search###
    result_list = []
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)

    context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 45
0
def category(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)

    context_dict = {'category_name': category_name, 'category_name_url': category_name_url}

    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list

    try:

        category = Category.objects.get(name__iexact=category_name)
        context_dict['category'] = category

        pages = Page.objects.filter(category=category).order_by('-views')


        context_dict['pages'] = pages
    except Category.DoesNotExist:
        pass

    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 46
0
def category(request, category_name_url):
    context = RequestContext(request)
    #category_name = category_name_url.replace('_',' ')
    category_name = UrlHelper('decode', category_name_url)
    context_dict = {'category_name': category_name}

    try:
        category = Category.objects.get(name__iexact=category_name)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category
        context_dict['category_name_url'] = category_name_url
        context_dict['cat_list'] = get_category_list
    except Category.DoesNotExist:
        return render_to_response('rango/category_not_found.html',
                                  context_dict, context)

    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 47
0
def category(request, category_name_slug):
    context_dict = {}
    context_dict['result_list']= None
    context_dict['query']=  None

    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)

        context_dict['result_list']= result_list
        context_dict['query']=  query


    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name']= category.name

        pages = Page.objects.filter(category= category).order_by('-views')
        context_dict['pages']=pages
        context_dict['category']= category
        context_dict['category_name_slug']= category_name_slug

    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
Esempio n. 48
0
def show_category(request, category_name_slug):
    context_dict = {}
    try:
        category = Category.objects.get(slug=category_name_slug)
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['category'] = category
        context_dict['pages'] = pages
        if request.method == "POST":
            form = request.POST
            query = form['query'].strip()
            results = [{}]
            try:
                results = bing_search.run_query(query)
            except IOError:
                results[0]['title'] = 'bing.key file not found!'
            except KeyError:
                results[0]['title'] = 'key not found!'
            except Warning:
                results[0][
                    'title'] = 'Search Error, check the key file and web connection!'
            context_dict['results'] = results
            context_dict['query'] = query
    except Category.DoesNotExist:
        context_dict['category'] = None
        context_dict['pages'] = None
    return render(request, 'rango/category.html', context=context_dict)
Esempio n. 49
0
def show_category(request, category_name_url):
    query = ""
    result_list = []
    context_dict = {}
    if request.method == 'POST' and 'query' in request.POST:
        query = request.POST['query'].strip()
        if query:
            # Run our Bing function to get the results list!
            result_list = run_query(query)
            context_dict['result_list'] = result_list
            context_dict['query'] = query
    try:
        category = Category.objects.get(slug=category_name_url)
        if request.method == 'GET':
            category.view = category.view + 1
            category.save()
        page = Page.objects.filter(category=category).order_by('-views')
        context_dict['views'] = category.view
        context_dict['pages'] = page
        context_dict['category'] = category
    except Category.DoesNotExist:
        context_dict['pages'] = None
        context_dict['category'] = None

    return render(request, 'rango/category.html', context_dict)
Esempio n. 50
0
def category(request, category_name_slug):
	context_dict = {}
	result_list = []
	context_dict['result_list'] = None
	context_dict['query'] = None
	
	if request.method == "POST":
		query = request.POST['query'].strip()
		if query:
			result_list = run_query(query)
			context_dict['result_list'] = result_list
			context_dict['query'] = query

	try:
		category = Category.objects.get(slug=category_name_slug)
		context_dict['category_name'] = category.name
		
		pages = Page.objects.filter(category=category)
		
		context_dict['pages'] = pages
		
		context_dict['category'] = category
		context_dict['category_name_slug'] = category_name_slug
	except Category.DoesNotExist:
		pass
			
	if not context_dict["query"]:
		context_dict['query'] = category.name		
		
	return render(request, 'rango/category.html', context_dict)
def category(request, category_name_slug):
    context_dict = {}
    context_dict['result_list'] = None
    context_dict['query'] = None
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            result_list = run_query(query)

            context_dict['result_list'] = result_list
            context_dict['query'] = query


    #print category_name_slug
    try:
        category = Category.objects.get(slug=category_name_slug)
        context_dict['category_name'] = category.name
        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
        context_dict['category'] = category

    except Category.DoesNotExist:
        pass

    if not context_dict['query']:
        context_dict['query'] = category.name

    return render(request, 'rango/category.html', context_dict)
Esempio n. 52
0
def category(request, category_name_url):
    context = RequestContext(request)
#    category_name = category_name_url.replace('_', ' ')
    category_name = decode_url(category_name_url)
    context_dict = {'category_name': category_name, 'category_name_url': category_name_url}

#    This needs to be passed in order to display categories on side-bar
    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list

    try:
        category = Category.objects.get(name__iexact=category_name)
        # Add category to the context so that we can access the id and likes
        context_dict['category'] = category

        pages = Page.objects.filter(category=category).order_by('-views')
        context_dict['pages'] = pages
#        context_dict['category_name_url'] = category_name_url
    except Category.DoesNotExist:
        pass

    if request.method == 'POST':
        query = request.POST.get('query')

        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 53
0
def category(request, category_name_url):
    # Request our context from the request passed to us.
    context = RequestContext(request)

    # Change underscores in the category name to spaces.
    # URLs don't handle spaces well, so we encode them as underscores.
    # We can then simply replace the underscores with spaces again to get the name.
    category_name = category_name_url.replace(
        '_', ' ')  # or decode(category_name_url)

    # Create a context dictionary which we can pass to the template rendering engine.
    # We start by containing the name of the category passed by the user.
    context_dict = {
        'category_name': category_name,
        'category_name_url': category_name_url
    }

    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list

    try:
        # Can we find a category with the given name?
        # If we can't, the .get() method raises a DoesNotExist exception.
        # So the .get() method returns one model instance or raises an exception.
        category = Category.objects.get(name__iexact=category_name)

        # Retrieve all of the associated pages.
        # Note that filter returns >= 1 model instance.
        pages = Page.objects.filter(category=category).order_by('-views')

        # Adds our results list to the template context under name pages.
        context_dict['pages'] = pages
        # We also add the category object from the database to the context dictionary.
        # We'll use this in the template to verify that the category exists.
        # Add category to the context so that we can access the id and likes
        context_dict['category'] = category
    except Category.DoesNotExist:
        # We get here if we didn't find the specified category.
        # Don't do anything - the template displays the "no category" message for us.
        pass
        # could be
        # from django.http import Http404
        # raise Http404
        # or shortcut using 'get_object_or_404(Category, pk=name)'

    context_dict['submitted'] = request.POST  # zeby dac 'noresults found'
    # tylko wtedy gdy submitujemy
    # pusty form,
    # see category.html result_list
    if request.method == 'POST':
        query = request.POST['query'].strip()

        if query:
            query = query.strip()
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    # Go render the response and return it to the client.
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 54
0
 def post(self, request, category_name_slug):
     query = request.POST['query'].strip()
     if query:
         # Run our Bing function to get the results list!
         result_list = run_query(query)
         context_dict['result_list'] = result_list
         context_dict['query'] = query
     return render(request, 'rango/category.html', context=context_dict)
    def post(self, request, category_name_slug):
        context_dict = self.create_context_dict(category_name_slug)
        query = request.POST['query'].strip()

        if query:
            context_dict['result_list'] = run_query(query)
            context_dict['query'] = query

        return render(request, 'rango/category.html', context_dict)
Esempio n. 56
0
def category(request, category_name_url):
    # Request our context
    context = RequestContext(request)

    # Change underscores in the category name to spaces.
    # URL's don't handle spaces well, so we encode them as underscores.
    category_name = decode_url(category_name_url)

    # Build up the dictionary we will use as out template context dictionary.
    context_dict = {
        'category_name': category_name,
        'category_name_url': category_name_url
    }
    #context_dict = {'category_name': category_name, 'category_name_url': category_name}

    cat_list = get_category_list()
    context_dict['cat_list'] = cat_list

    try:
        # Find the category with the given name.
        # Raises an exception if the category doesn't exist.
        # We also do a case insensitive match.
        category = Category.objects.get(name__iexact=category_name)
        context_dict['category'] = category
        # Retrieve all the associated pages.
        # Note that filter returns >= 1 model instance.
        pages = Page.objects.filter(category=category).order_by('-views')

        # Adds our results list to the template context under name pages.
        context_dict['pages'] = pages
    except Category.DoesNotExist:
        # We get here if the category does not exist.
        # Will trigger the template to display the 'no category' message.
        pass

    if request.method == 'POST':
        #query = request.POST['query'].strip()
        query = request.POST.get('query')
        if query:
            result_list = run_query(query)
            context_dict['result_list'] = result_list

    #pag_list = get_category_list()
    # page_name = decode_category(page_name_url)
    # pag = Page.objects.get(name=page_name)

    # if pag:
    #         # selects all the pages associated with the selected category
    #         pages = Page.objects.filter(category=cat)
    #         category_id = cat.id
    #         likes = cat.likes
    # context_dict = {'pag_list': pag_list, 'page_name_url': page_name_url, 'page_name': page_name, 'page_id': page_id, 'mylikes': pagelikes}
    #context = RequestContext(request, context_dict)

    # Go render the response and return it to the client.
    return render_to_response('rango/category.html', context_dict, context)
Esempio n. 57
0
def search(request):
    context = RequestContext(request)
    result_list = []

    if request.method == 'POST':
        query = request.POST['query'].strip()
        if query:
            result_list = run_query(query)
    return render_to_response('rango/search.html',
                              {'result_list': result_list}, context)
Esempio n. 58
0
    def post(self, request, category_name_slug):
        context_dict = self.create_context_dict(category_name_slug)
        query = request.POST['query'].strip()

        if query:
            context_dict['result_list'] = run_query(query)
            context_dict['query'] = query

        # Выполните рендеринг ответа и верните его клиенту.
        return render(request, 'rango/category.html', context_dict)