Пример #1
0
def add_page(key, title, url, views):
    p = Page(category=Category.objects.filter(name=key)[0],
             title=title,
             url=url,
             views=views)
    p.save()
    print(Page.objects.all())
Пример #2
0
def auto_add_page(request):
    context = RequestContext(request)
    context_dict = {}
    cat_id = None
    url = None
    title = None
    
    if request.method == "GET":
        title = request.GET['title']
        url = request.GET['url']
        cat_id = request.GET['category_id']
        print(title, url, cat_id)
        print("HEYYY")
        if cat_id:
            print("CHECK")
            category = Category.objects.get(id=int(cat_id))
            p = Page(title=title, url=url, category=category)
            p.save()
            pages = Page.objects.filter(category = category).order_by('-views')
            context_dict['pages'] = pages
            print("DUDE")
    else:
        pass

    return render(request, 'rango/page_list.html', context_dict, context)
Пример #3
0
 def test_ensure_views_are_positive(self):
     page = Page(category=Category(name='test'),
                 title="test page 1",
                 url="http://www.example.com",
                 views=-1)
     page.save()
     self.assertEqual((page.views >= 0), False)
Пример #4
0
	def test_ensure_last_visit_equal_after_first_visit(self):
		cat = Category(name='test')
		cat.save()
		t1 = timezone.now()
		t2 = timezone.now() + datetime.timedelta(days=30)
		pag = Page(category=cat, first_visit=t1, last_visit=t2)
		self.assertEqual(pag.is_last_visit_equal_after_first_visit(), True)
Пример #5
0
def auto_add_page(request):
    context = RequestContext(request)
    context_dict = {}
    cat_id = None
    url = None
    title = None

    if request.method == "GET":
        title = request.GET['title']
        url = request.GET['url']
        cat_id = request.GET['category_id']
        print(title, url, cat_id)
        print("HEYYY")
        if cat_id:
            print("CHECK")
            category = Category.objects.get(id=int(cat_id))
            p = Page(title=title, url=url, category=category)
            p.save()
            pages = Page.objects.filter(category=category).order_by('-views')
            context_dict['pages'] = pages
            print("DUDE")
    else:
        pass

    return render(request, 'rango/page_list.html', context_dict, context)
Пример #6
0
    def test_page_views_should_be_nonnegative(self):

        category = Category()
        category.save()
        page = Page(category=category, title='test page', views=-100)
        page.save()
        self.assertTrue(page.views >= 0)
Пример #7
0
def add_pages(request, category_name_slug):
    category = Category.objects.get(slug=category_name_slug)
    category_list = {}
    category_list['category_name'] = category.name
    try:
        cat = Category.objects.get(slug=category_name_slug)

    except Category.DoesNotExist:
        cat = none

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                Page = form.save(commit=False)
                Page.category = cat
                Page.views = 0
                Page.save()
                return category(request, category_name_slug)
            else:
                print form.errors
    else:
        form = PageForm()

    context_dict = {'form': form, 'categories': cat}

    return render(request, 'rango/add_pages.html', context_dict)
Пример #8
0
def create_page_and_category_example(request):
    # Page(title='new dj page', category=Category.objects.get(name='Django')).save()
    c = Category.objects.get(name='Django')
    p = Page()
    p.title = 'new dj page'
    p.category = c
    p.save()
Пример #9
0
 def test_ensure_last_visit_not_in_the_future(self):
     future_time = timezone.now() + datetime.timedelta(days=1)
     page = Page(category=Category(name='test'),
                 title="test page 3",
                 url="http://www.example.com",
                 last_visit=future_time)
     page.save()
     self.assertEqual((page.last_visit <= timezone.now()), False)
Пример #10
0
 def test_to_ensure_if_last_visit_and_first_visit_are_not_future(self):
     cat = add_cat('test',1,1)
     page = Page(title='Google.com', category = cat)
     page.save()
     self.assertEqual((page.first_visit > timezone.now()), False)
     sleep(5)
     page.save()
     self.assertEqual((page.last_visit > timezone.now()), False)
Пример #11
0
def add_page(cat, title, url, views, last_visit, first_visit):
    page = Page(category=cat,
                title=title,
                url=url,
                views=views,
                last_visit=last_visit,
                first_visit=first_visit)
    page.save()
    return page
Пример #12
0
 def test_ensure_last_visit_or_first_visit_not_in_future(self):
     """
     ensure that the last_visti and first_visit are not in future.
     """
     cat = add_cat('test', 1, 1)
     page = Page(category=cat, title='test_page', url='http://www.example.com', views=1, first_visit=datetime.now()+timedelta(hours=6), last_visit=datetime.now()+timedelta(hours=6))
     page.save()
     self.assertEqual((page.first_visit <= datetime.now()), True)
     self.assertEqual((page.last_visit <= datetime.now()), True)
Пример #13
0
    def test_page_contains(self):
        """
        test_category_contains tests whether the save() function is working correctly.
        """

        category = Category()
        category.save()
        page = Page(category=category, title='test page', views=21)
        page.save()
        self.assertEqual(Page.objects.filter(pk=page.pk).exists(), True)
Пример #14
0
 def test_ensure_valid_date(self):
     '''
     ensure_valid date checks to make sure that last_visit is bigger or equal than first_visit
     :return:
     '''
     Category.objects.get_or_create(name='test_cat')
     cat = Category.objects.get(name='test_cat')
     page = Page(category=cat, title="test", first_visit=datetime.strptime("20120912", '%Y%m%d'))
     page.save()
     self.assertLessEqual(page.first_visit, page.last_visit)
Пример #15
0
 def test_last_visit_equal_to_or_after_the_first_visit(self):
     cat = add_cat('test', 1, 1)
     page = Page(category=cat,
                 title='testpage',
                 url='http://example.com',
                 views=0,
                 first_visit=datetime.now() + timedelta(days=30),
                 last_visit=datetime.now() - timedelta(days=30))
     page.save()
     self.assertEqual((page.last_visit >= page.first_visit), True)
Пример #16
0
    def test_to_insure_if_last_visit_and_first_visit_are_equals_or_in_right_order(self):
        cat = add_cat('test',1,1)
        page = Page(title='Google.com', category = cat)
        page.save()
        #self.assertEqual(page.last_visit == page.first_visit or page.last_visit > page.first_visit, True)
        self.assertEqual(page.last_visit == page.first_visit, True)

        sleep(5)
        page.save()
        self.assertEqual(page.last_visit > page.first_visit, True)
Пример #17
0
 def test_ensure_first_and_last_visit(self):
     cat = Category(name="test", views=1, likes=0)
     cat.save()
     p = Page(title="xixi", category=cat)
     p.save()
     # response = self.client.get(reverse('add_page',kwargs={'catgory_slug_name':cat.slug}))
     response = self.client.get(reverse("goto"))
     first_visit = p.first_visit
     last_visit = p.last_visit
     self.assertEqual((first_visit < last_visit), True)
Пример #18
0
 def test_last_view_is_not_in_future(self):
     cat = add_cat('test', 1, 1)
     page = Page(category=cat,
                 title='testpage',
                 url='http://example.com',
                 views=0,
                 first_visit=datetime.now(),
                 last_visit=datetime.now() + timedelta(days=30))
     page.save()
     self.assertEqual((page.last_visit <= datetime.now()), True)
Пример #19
0
	def test_last_visit_and_first_visit_validation(self):

		"""
		last_visit_and_first_visit_validation check both last_visit and first_visit are not in the future
		"""
		now = datetime.datetime.now()
		time_in_the_future = now + datetime.timedelta(hours=1)
		cat = Category(name='test')
		cat.save()
		page = Page(category=cat, title="test", url="http://www.test.com", last_visit=time_in_the_future, first_visit=time_in_the_future+datetime.timedelta(hours=2))
		page.save()
Пример #20
0
 def test_ensure_last_visit_later_than_first_visit(self):
     past_time = timezone.now() - datetime.timedelta(days=1)
     now = timezone.now()
     page = Page(
         category=Category(name='test'),
         title="test page 4",
         url="http://www.example.com",
         first_visit=now,
         last_visit=past_time
     )  # Here first_visit and last_visit can't be assigned as timezone.now, which is an instance of now()
     page.save()
     self.assertEqual((page.last_visit >= page.first_visit), False)
Пример #21
0
 def test_ensure_last_visit_not_before_first(self):
     category = Category(name='test')
     category.save()
     page = Page(category=category,
                 title='test',
                 url='http://www.google.com',
                 views=1,
                 last_visit=datetime.date.today() +
                 datetime.timedelta(days=1),
                 first_visit=datetime.date.today())
     page.save()
     self.assertEqual((page.last_visit <= page.first_visit), True)
Пример #22
0
    def test_time_not_in_the_future(self):
        c = Category(name='demo')
        c.save()
        p = Page(title='page', url='https://www.baidu.com')
        p.category = c
        p.save()

        response = self.client.get(reverse('rango:goto')+'?page_id='+str(p.id))
        self.assertEqual(response.status_code, 302)
        page = Page.objects.get(id=p.id)
        self.assertTrue(page.last_visit <= timezone.now())
        self.assertTrue(page.first_visit <= timezone.now())
        sleep(2)
        self.client.get(reverse('rango:goto') + '?page_id=' + str(p.id))
        self.assertTrue(page.first_visit <= page.last_visit)
Пример #23
0
 def test_Page_dates(self):
     cat = Category(name='test')
     page = Page(category=cat, title='test_page')
     self.assertFalse(page.last_visit > datetime.now())
     self.assertFalse(page.first_visit > datetime.now())
     self.assertTrue(page.last_visit >= page.first_visit,
                     '%s - %s' % (page.last_visit, page.first_visit))
Пример #24
0
def quick_add_page(request):
    context = RequestContext(request)
    context_dict = {}

    if request.GET.has_key('cat') and request.GET.has_key('url') and request.GET.has_key('title'):
        try:
            cat_id = Category.objects.get(name=decode_url(request.GET['cat']))
            try:
                page = Page.objects.get(title=request.GET['title'])
            except:
                new_page = Page(category=cat_id, title=request.GET['title'], url=request.GET['url'])
                new_page.save()
            context_dict['pages'] = Page.objects.filter(category=cat_id).order_by('-views')
        except Exception as e:
            print "Error:: ",e

    return render_to_response('rango/ajax/category_page_list.html',context_dict,context)
Пример #25
0
def create_pages(categories):
    # List of pages
    pages = []

    # For each category create 2 pages
    for i in range (0, len(categories)):
        category = categories[i]

        # Name the pages according to the links and create a fake url
        for j in range(0, 2):
            page_number = i * 2 + j + 1
            page = Page(category=category, title="Page " + str(page_number),
                        url="http://www.page" + str(page_number) + ".com", views=page_number)
            page.save()
            pages.append(page)

    return pages
Пример #26
0
def create_pages(categories):
    # List of pages
    pages = []

    # For each category create 2 pages
    for i in xrange (0, len(categories)):
        category = categories[i]

        # Name the pages according to the links and create a fake url
        for j in xrange(0, 2):
            page_number = i * 2 + j + 1
            page = Page(category=category, title="Page " + str(page_number),
                        url="http://www.page" + str(page_number) + ".com", views=page_number)
            page.save()
            pages.append(page)

    return pages
Пример #27
0
def add_page_ajax(request):
	print "in add_page_ajax()"

	if request.method == 'GET':
		#print "333333333", request.GET
		valor = request.GET['values'].split('>|||<')
		valor = [str(val) for val in valor]
		print "lista_valor: ", valor
		for v in valor:
			print "valor: ", v
	try:
		cat = Category.objects.get(name=valor[2])
	except Category.DoesNotExist:
		cat = None

	new_page = Page()
	new_page.category = cat
	new_page.title = valor[0]
	new_page.url = valor[1]
	new_page.views = 0
	new_page.save()
	print "id", new_page.id
	print "*****", new_page
	valor.append(new_page.id)
	valor = json.dumps(valor)

	return HttpResponse(valor)
Пример #28
0
def add_page(category, title, url, views=0):
    try:
        p = Page.objects.get(title=title)
    except Page.DoesNotExist:
        p = Page()
    p.title = title
    p.category = category
    p.url = url
    p.views = views
    p.save()
    return p
Пример #29
0
def add_page(request, category_name_url):
    context = RequestContext(request)

    category_name = decode_url(category_name_url)

    if request.method == 'POST':
        form = PageForm(request.POST)

        if form.is_valid():
            # This time we cannot commit straight away.
            # Not all fields are automatically populated!
            Page = form.save(commit=False)

            # Retrieve the associated Category object so we can add it.
            # Wrap the code in a try block - check if the category actually exists!
            try:
                cat = Category.objects.get(name=category_name)
                Page.category = cat
            except Category.DoesNotExist:
                # If we get here, the category does not exist.
                # Go back and render the add category form as a way of saying the category does not exist.
                return render_to_response('rango/add_category.html', {}, context)

            # Also, create a default value for the number of views.
            Page.views = 0

            # With this, we can then save our new model instance.
            Page.save()

            # Now that the page is saved, display the category instead.
            return category(request, category_name_url)
        else:
            print form.errors
    else:
        form = PageForm()

    return render_to_response('rango/add_page.html', 
            {'category_name_url': category_name_url,
             'category_name': category_name, 
             'form': form},
             context)
Пример #30
0
def auto_add_page(request):
  context = RequestContext(request)
  page_list = []
  if request.method == 'GET':
    cat_id = request.GET.get('cat_id', '')
    title = request.GET.get('title', '')
    url = request.GET.get('url', '')
    if cat_id and title and url:
      try:
        category = Category.objects.get(pk=int(cat_id))
        p = Page(category=category, title=title, url=url)
        p.save()
        page_list = Page.objects.filter(category=category).order_by('-views')
        print "New Page was added: %r" % p
      except Exception as e:
        print e
    else:
      print "Request empty. category: %d, title: %s, url: %s" % (cat_id, title, url)
  else:
    print 'Invalid Request'
  return render_to_response('rango/page_list.html', {'pages': page_list}, context)
Пример #31
0
def create_page_and_category_example(request):
    # Page(title='new dj page', category=Category.objects.get(name='Django')).save()
    c = Category.objects.get(name='Django')
    p = Page()
    p.title = 'new dj page'
    p.category = c
    p.save()
Пример #32
0
def auto_add_page(request):
    cat_id = request.GET['category_id']
    cat = Category.objects.get(id=int(cat_id))
    if request.method == 'GET':
        title = cleanhtml(request.GET['page_name'])
        url = request.GET['page_url']
        page = Page()
        page.category = cat
        page.title = title
        page.url = url
        page.views = 0
        page.save()

    return HttpResponseRedirect(reverse('category'))
Пример #33
0
def add_page(request, category_name_slug=None):
    form = PageForm(category_name_slug)
    if request.method == 'POST':
        form = PageForm(category_name_slug, request.POST)
        if form.is_valid():
            page = Page()
            page.title = form.cleaned_data['title']
            page.url = form.cleaned_data['url']
            page.category = Category.objects.filter(name=form.cleaned_data['category'])[0]
            page.save()
            messages.success(request, 'Page successfully included in category '+page.category.name)
            return redirect('index')
        else:
            messages.error(request, 'Page not included, invalid form!')
            print(form.errors)
    return render(request, 'rango/add_page.html', {'form': form})
Пример #34
0
def auto_addpage(request):
    context = RequestContext(request)
    if request.method == 'GET':
        cat_id = request.GET['category_id']
        page_title = request.GET['page_title']
        page_url = request.GET['page_url']
        context_dict = {}

        category = Category.objects.get(id=int(cat_id))
        pages = Page()
        pages.category = category
        pages.title = page_title
        pages.url = page_url
        pages.save()

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

    return render_to_response('rango/page_list.html', context_dict, context)
Пример #35
0
class ModelPageTest(ModelTestSupport):

    def setUp(self):
        self.page = Page(title='title name')

    def test_model(self):
        self.model_default_test(self.page._meta)

    def test_id_field(self):
        self.field_test(self.page._meta.get_field('id'),
                        blank=True, verbose_name=u'ID',
                        max_length=None, unique=True,
                        type=models.fields.AutoField)

    def test_title_field(self):
        self.field_test(self.page._meta.get_field('title'),
                        max_length=128,
                        type=models.fields.CharField)

    def test_url_field(self):
        self.field_test(self.page._meta.get_field('url'),
                        max_length=200,
                        type=models.fields.URLField)

    def test_views_field(self):
        self.field_test(self.page._meta.get_field('views'),
                        max_length=None,
                        type=models.fields.IntegerField)

    def test_category_field(self):
        self.field_test(self.page._meta.get_field('category'),
                        max_length=None,
                        type=models.fields.related.ForeignKey,
                        rel_type=models.fields.related.ManyToOneRel)

    def test_attrs_values(self):
        self.assertEqual(self.page.title, 'title name')

    def test_unicode(self):
        self.assertEqual(self.page.__unicode__(), 'title name')
Пример #36
0
def auto_addpage(request):
    context = RequestContext(request)
    if request.method == 'GET':
        cat_id = request.GET['category_id']
        page_title = request.GET['page_title']
        page_url = request.GET['page_url']
        context_dict = {}

        category = Category.objects.get(id=int(cat_id))
        pages = Page()
        pages.category = category
        pages.title = page_title
        pages.url = page_url
        pages.save()

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


    return render_to_response('rango/page_list.html', context_dict, context)
Пример #37
0
from rango.models import Category, Page

c = Category(name='home')
c.save()
Page(category=c,
     title='Home - Property Search',
     url='http://www.home.co.uk',
     views=0).save()
Page(category=c, title='Right Move', url='http://www.rightmove.co.uk',
     views=0).save()
c = Category(name='sport')
c.save()
Page(category=c,
     title='BBC Sport',
     url='http://www.bbc.co.uk/sport/0/',
     views=0).save()
Page(category=c, title='Sky Sports', url='http://www.skysports.com/',
     views=0).save()
Page(category=c, title='Sports News', url='http://www.sport.co.uk/',
     views=0).save()
c = Category(name='fun')
c.save()
Page(category=c,
     title='The Fun Theory',
     url='http://www.thefuntheory.com/',
     views=0).save()
Page(category=c,
     title='Comp. Sci. for Fun',
     url='http://www.cs4fn.org/',
     views=0).save()
Пример #38
0
 def test_page_visit_not_in_future(self):
     cat = Category(name="test", views=-1, likes=0)
     cat.save()
     page = Page(category=cat)
     page.save()
     self.assertLessEqual(page.last_visit, datetime.now())
Пример #39
0
    def test_create_pages_for_categories(self):
        cat = Category(name="Python")
        cat.save()

        # create 2 pages for category python
        python_page = Page()
        python_page.category = cat
        python_page.title = "Official Python Tutorial"
        python_page.url = "http://docs.python.org/2/tutorial/"
        python_page.save()

        django_page = Page()
        django_page.category = cat
        django_page.title = "Django"
        django_page.url = "https://docs.djangoproject.com/en/1.5/intro/tutorial01/"
        django_page.save()

        # Check if they both were saved
        python_pages = cat.page_set.all()
        self.assertEquals(python_pages.count(), 2)

        #Check if they were saved properly
        first_page = python_pages[0]
        self.assertEquals(first_page, python_page)
        self.assertEquals(first_page.title, "Official Python Tutorial")
        self.assertEquals(first_page.url, "http://docs.python.org/2/tutorial/")
Пример #40
0
 def test_last_visit_equal_after_first_visit(self):
     cat = Category(name="test", views=-1, likes=0)
     cat.save()
     page = Page(category=cat)
     page.save()
Пример #41
0
def add_page(cat,title,url,views,last_visit,first_visit):
	page=Page(category=cat,title=title,url=url,views=views,
			last_visit=last_visit,first_visit=first_visit)
	page.save()
	return page
Пример #42
0
 def setUp(self):
     self.page = Page(title='title name')
Пример #43
0
	def test_ensure_visits_not_in_future(self):
		cat = Category(name='test')
		cat.save()
		future_time = timezone.now() + datetime.timedelta(days=30)
		pag = Page(category=cat, first_visit=future_time, last_visit=future_time)
		self.assertEqual(pag.is_visit_in_future(), True)
Пример #44
0
	def test_page(self):
		page = Page(title='page',category_id = 1,views=5)
		page.save()

		self.assertEqual(page.views,5)
Пример #45
0
    def test_create_pages_for_categories(self):
        cat = Category(name="Python")
        cat.save()

        # create 2 pages for category python
        python_page = Page()
        python_page.category = cat
        python_page.title="Official Python Tutorial"
        python_page.url="http://docs.python.org/2/tutorial/"
        python_page.save()

        django_page = Page()
        django_page.category = cat
        django_page.title="Django"
        django_page.url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/"
        django_page.save()

        # Check if they both were saved
        python_pages = cat.page_set.all()
        self.assertEquals(python_pages.count(), 2)

        #Check if they were saved properly
        first_page = python_pages[0]
        self.assertEquals(first_page, python_page)
        self.assertEquals(first_page.title , "Official Python Tutorial")
        self.assertEquals(first_page.url, "http://docs.python.org/2/tutorial/")