예제 #1
0
    def setUp(self):
        from regions.models import Region
        from pages.models import Page
        from tags.models import Tag, PageTagSet

        self.factory = RequestFactory()

        # Create a new region and associate a domain with it
        self.sf = Region(full_name="San Francisco", slug="sf")
        self.sf.save()
        self.sf.regionsettings.domain = 'fakename.org'
        self.sf.regionsettings.save()

        self.user = User.objects.create_user(
            username='******', email='*****@*****.**', password='******')
        self.user.save()
       
        # Create a page in the SF region
        p = Page(name='Parks', content='<p>Hi</p>', region=self.sf)
        p.save(user=self.user)
        p.content += "!"
        p.save(user=self.user)

        # Add a tag to the page
        t = Tag(name='park', slug='park', region=self.sf)
        t.save(user=self.user)
        pts = PageTagSet(region=self.sf, page=p)
        pts.save(user=self.user)
        pts.tags.add(t)
        pts.save(user=self.user)
예제 #2
0
 def get_context_data(self, *args, **kwargs):
     context = super(RedirectPermissionsView,
                     self).get_context_data(*args, **kwargs)
     redirect = self.get_object()
     context['page'] = Page(name=redirect.source, region=redirect.region)
     context['redirect'] = redirect
     return context
예제 #3
0
def page_content_over_time(now):
    oldest_page = Page.versions.all().order_by(
        'history_date')[0].version_info.date

    graph = pyflot.Flot()
    page_dict = {}
    page_contents = []

    d = datetime(oldest_page.year, oldest_page.month, oldest_page.day)
    while (now.year, now.month, now.day) != (d.year, d.month, d.day):
        next_d = d + timedelta(days=1)

        page_edits_this_day = Page.versions.filter(
            version_info__date__gte=d, version_info__date__lt=next_d)
        # Group the edits by slug and annotate with the max history date
        # for the associated page.
        slugs_with_date = page_edits_this_day.values('slug').annotate(
            Max('history_date')).order_by()

        for item in slugs_with_date:
            p = Page(slug=item['slug'])
            # Grab the historical version at this date.
            p_h = p.versions.as_of(date=item['history_date__max'])
            page_dict[item['slug']] = len(p_h.content)

        total_content_today = 0
        for slug, length in page_dict.iteritems():
            total_content_today += length

        page_contents.append((d, total_content_today))
        d = next_d

    graph.add_time_series(page_contents)

    return [graph.prepare_series(s) for s in graph._series]
예제 #4
0
    def handle(self, *args, **options):

        for fp in FlatPage.objects.all():

            try:

                p = Page.objects.get(path=fp.url)

                print "%s already exists" % fp.url

            except Page.DoesNotExist:

                p = Page()

                p.path = fp.url
                p.title = fp.title
                p.content = fp.content
                p.content.markup_type = 'markdown'

                p.template = self.get_template(fp.template_name)
                p.is_published = True

                p.save()

                print "saved %s" % fp.url
예제 #5
0
파일: tests.py 프로젝트: jewelhuq/localwiki
    def test_include_width(self):
        a = Page(name='Front Page')
        a.content = ('<a class="plugin includepage" style="width: 100px"'
                     ' href="Explore">dummy</a>')
        a.save()

        b = Page(name='Explore')
        b.content = '<p>Some text</p>'
        b.save()

        context = Context({'page': a})
        template = Template(html_to_template_text(a.content, context))
        html = template.render(context)
        self.assertEqual(html,
            ('<div class="included_page_wrapper" style="width: 100px;">'
             '<p>Some text</p></div>'))
예제 #6
0
 def extra_context(self):
     context = super(CreatePageSearchView, self).extra_context()
     context['page_exists_for_query'] = Page.objects.filter(
         slug=slugify(self.query))
     context['query_slug'] = Page(name=self.query).pretty_slug
     context['keywords'] = self.query.split()
     return context
예제 #7
0
def create_page(page):

  try:
    p = Page.objects.get(webKey=page.webKey, user=admin_user)
    print("Update Page: " + page.webKey)

    p.title       = page.title
    p.description = page.description
    p.htmlHead    = page.htmlHead
    p.htmlBody    = page.htmlBody
    p.sample      = page.sample
    p.public      = page.public
    p.javascript  = page.javascript
    p.css         = page.css

  except ObjectDoesNotExist:
    print("Create Page: " + page.webKey)
    p = Page(user=admin_user, webKey= page.webKey, title=page.title, description=page.description, htmlHead = page.htmlHead, htmlBody=page.htmlBody, sample=page.sample, public=page.public, javascript=page.javascript, css=page.css)

  p.save()
  p.tags.remove()
  p.save()

  for t in page.tags.split(' '):
    try:
      tag = Tag.objects.get(slug=t)
      p.tags.add(tag)
      p.save()
      print('Tag added: ' + tag.title)
    except ObjectDoesNotExist:
      print('Tag not found: ' + tag)
예제 #8
0
    def test_merge_conflict(self):
        p = Page()
        p.content = '<p>old content</p>'
        p.name = 'Front Page'
        p.save()

        a = PageForm(instance=p)
        b = PageForm(instance=p)
        b_post = b.initial
        b_post['content'] = '<p>b content</p>'
        b = PageForm(b_post, instance=p)
        self.failUnless(b.is_valid())
        b.save()

        p = Page.objects.get(pk=p.pk)
        a_post = a.initial
        a_post['content'] = '<p>a content</p>'
        a = PageForm(a_post, instance=p)
        self.failIf(a.is_valid())
        # + '' to force evaluation of lazy string
        self.failUnless(str(PageForm.conflict_error + '') in str(a.errors))

        a_post = a.data
        a = PageForm(a_post, instance=p)
        self.failUnless(a.is_valid())
        a.save()
        p = Page.objects.get(pk=p.pk)
        self.failUnless('Edit conflict!' in p.content)
예제 #9
0
 def _get_creole(self):
     "Get a Creole class for some PageVersion for generic testing"
     crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
     p = Page(offering=crs, label="Foo")
     p.save()
     pv = PageVersion(page=p)
     return ParserFor(crs, pv)
예제 #10
0
 def commit_items(self, response_dict):
     """
     Accepts a dict like this:
     {"items":[{"id":18697,"siteId":8162,"roleId":-1,"name":"Annual Report 2007 ...}],"totalItemsCount":1010,"skip":0,"limit":10}
     :param response_dict: dict of items
     :return:
     """
     for item in response_dict['items']:
         try:
             p = Page.objects.get(page_id=item.get('id'))
         except Page.DoesNotExist:
             p = Page()
         exp_date = item.get('expiryDate')
         exp_date = datetime.datetime.strptime(
             exp_date.split('T')[0], '%Y-%m-%d')
         p.name = item.get('name')
         p.url = item.get('pageUrl')
         p.enabled = item.get('enabled')
         p.expires = exp_date
         p.page_id = item.get('id')
         p.content = item.get('content')
         p.title = item.get('title')
         p.template_id = item.get('templateId')
         p.seo_description = item.get('seoMetadataDescription')
         p.save()
def import_pages():
    from pages.models import Page, slugify

    request = api.APIRequest(site, {
        'action': 'query',
        'list': 'allpages',
        'aplimit': '50',
    })
    print "Getting master page list (this may take a bit).."
    response_list = request.query(querycontinue=False)['query']['allpages']
    pages = pagelist.listFromQuery(site, response_list)
    print "Got master page list."
    for mw_p in pages[:100]:
        print "Importing %s" % mw_p.title
        wikitext = mw_p.getWikiText()
        if mw_p.isRedir():
            add_redirect(mw_p)
            continue
        html = render_wikitext(mw_p.title, wikitext)

        if Page.objects.filter(slug=slugify(mw_p.title)):
            # Page already exists with this slug.  This is probably because
            # MediaWiki has case-sensitive pagenames.
            other_page = Page.objects.get(slug=slugify(mw_p.title))
            if len(html) > other_page.content:
                # *This* page has more content.  Let's use it instead.
                for other_page_version in other_page.versions.all():
                    other_page_version.delete()
                other_page.delete(track_changes=False)

        p = Page(name=mw_p.title, content=html)
        p.content = process_html(p.content, p.name)
        p.clean_fields()
        p.save()
예제 #12
0
    def test_markup_choice(self):
        """
        Check the distinction between Creole and Markdown pages
        """
        offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        memb = Member.objects.get(offering=offering, person__userid="ggbaker")

        p = Page(offering=offering, label="Test")
        p.save()
        v1 = PageVersion(page=p,
                         title="T1",
                         wikitext='A //test//.',
                         editor=memb,
                         comment="original page")
        v1.save()
        self.assertEqual(v1.html_contents(), '<p>A <em>test</em>.</p>')

        v2 = PageVersion(page=p,
                         title="T1",
                         wikitext='A *test*.',
                         editor=memb,
                         comment="original page")
        v2.set_markup('markdown')
        v2.save()
        self.assertEqual(v2.html_contents(), '<p>A <em>test</em>.</p>')
예제 #13
0
파일: tests.py 프로젝트: jewelhuq/localwiki
 def test_amp_in_link_with_class(self):
     page = Page(name='Explore')
     html = ('<p><a class="external something" '
                'href="http://example.org/?t=1&amp;i=2">hi</a></p>')
     template = Template(html_to_template_text(html))
     rendered = template.render(Context({'page': page}))
     self.failUnless('http://example.org/?t=1&amp;i=2' in rendered)
예제 #14
0
    def test_fix_tags(self):
        """
        Test the `fix_tags` utility function.
        """
        from pages.models import Page
        from tags.tag_utils import fix_tags

        #########################
        # Create some test regions
        #########################
       
        sf = Region(full_name="San Francisco Test", slug='sftest')
        sf.save()

        mission = Region(full_name="Mission", slug="mission")
        mission.save()

        #########################
        # Create some test tags
        #########################

        park = Tag(name='park', region=sf)
        park.save()

        fun = Tag(name='fun', region=sf)
        fun.save()

        #########################
        # Add the tags to a test page
        #########################

        page = Page(name="Duboce Park", content="<p>Park.</p>", region=sf)
        page.save()

        pts = PageTagSet(
            page=page,
            region=sf
        )
        pts.save()
        pts.tags.add(park)
        pts.tags.add(fun)
        pts.save()

        # Now do something odd and make one of the referenced `Tag`s point
        # to a different region than the PageTagSet.
        fun.region = mission
        fun.save()

        self.assertTrue(pts.tags.filter(region=mission).exists())

        # Then attempt a fix:
        fix_tags(sf, PageTagSet.objects.filter(id=pts.id))

        pts = PageTagSet.objects.get(page=page, region=sf)
        self.assertFalse(pts.tags.filter(region=mission).exists())

        # Check that this is fixed in historical versions as well
        for pts_h in pts.versions.all():
            self.assertFalse(pts_h.tags.filter(region=mission).exists())
예제 #15
0
파일: tests.py 프로젝트: whpeddyc/8bitmooc
 def setUp(self):
     self.c = Client()
     
     self.u1 = User.objects.create_user("ishara",
                                        "*****@*****.**",
                                        "ishararulz")
     self.u1.save()
     self.s1 = Student( user=self.u1 )
     self.s1.save()
     
     p = Page(name="index", content="Hello world")
     p.save()
     p = Page(name="test", content="This is a test.")
     p.save()
 
     # Give the test users memorable names.
     self.ishara = self.s1
예제 #16
0
    def get_object(self):
        page = Page(slug=slugify(self.kwargs['slug']))  # A dummy page object.
        latest_page = page.versions.most_recent()
        # Need to set the pk on the dummy page for correct MapData lookup.
        page.pk = latest_page.id
        page.name = latest_page.name

        return MapData(page=page)
예제 #17
0
    def test_double_include(self):
        """ Multiple includes are ok
        """
        a = Page(name='Front Page')
        a.content = ('<a class="plugin includepage" href="Explore">dummy</a>'
                     '<a class="plugin includepage" href="Explore">dummy</a>')
        a.save()

        b = Page(name='Explore')
        b.content = '<p>Some text</p>'
        b.save()

        context = Context({'page': a})
        template = Template(html_to_template_text(a.content, context))
        html = template.render(context)
        self.assertEqual(html,
            ('<div><p>Some text</p></div><div><p>Some text</p></div>'))
예제 #18
0
파일: views.py 프로젝트: andresokol/ALaWiki
def submit_changes(request, title):
    try:
        page = Page.objects.get(title=title)
        page.change(request.POST['text-field'])
    except:
        page = Page(title=title, article=request.POST['text-field'])
    page.save()
    return HttpResponseRedirect('/wiki/' + title)
예제 #19
0
파일: tests.py 프로젝트: jewelhuq/localwiki
    def test_include_showtitle(self):
        a = Page(name='Front Page')
        a.content = ('<a class="plugin includepage includepage_showtitle"'
                     ' href="Explore">dummy</a>')
        a.save()

        b = Page(name='Explore')
        b.content = '<p>Some text</p>'
        b.save()

        context = Context({'page': a})
        template = Template(html_to_template_text(a.content, context))
        html = template.render(context)
        self.assertEqual(html,
                    ('<div class="included_page_wrapper">'
                     '<h2><a href="/Explore">Explore</a></h2>'
                     '<p>Some text</p>'
                     '</div>'))
예제 #20
0
파일: views.py 프로젝트: schlos/localwiki
 def get_context_data(self, **kwargs):
     context = super(RedirectDeleteView, self).get_context_data(**kwargs)
     p = Page.objects.filter(slug=self.object.source)
     if p:
         context['page'] = p[0]
     else:
         context['page'] = Page(slug=self.object.source,
                                name=self.object.source)
     return context
예제 #21
0
파일: test_blog.py 프로젝트: e4c5/lamp-blog
 def testSlug(self):
     p = Page(link = 'bada')
     p.put()
     self.assertEqual(1, len(Page.query().fetch(2)))
     
     link = create_link('bada')
     self.assertNotEqual(link, 'bada')
     
     print link
    def setUp(self):
        super(RedirectAPITests, self).setUp()

        # Create the edit user and add it to the authenticated group
        self.edit_user = User(
            username="******", email="*****@*****.**", password="******")
        self.edit_user.save()
        all_group, created = Group.objects.get_or_create(name=settings.USERS_DEFAULT_GROUP)
        self.edit_user.groups.add(all_group)
        self.edit_user.save()

        self.edit_user_2 = User(
            username="******", email="*****@*****.**", password="******")
        self.edit_user_2.save()
        all_group, created = Group.objects.get_or_create(name=settings.USERS_DEFAULT_GROUP)
        self.edit_user_2.groups.add(all_group)
        self.edit_user_2.save()

        self.sf = Region(full_name="San Francisco", slug="sf")
        self.sf.save()
        self.oak = Region(full_name="Oakland", slug="oak")
        self.oak.save()

        self.dolores_park = Page(name="Dolores Park", content="<p>Hi</p>", region=self.sf)
        self.dolores_park.save()

        self.duboce_park = Page(name="Duboce Park", content="<p>Hi</p>", region=self.sf)
        self.duboce_park.save()

        self.mission_dolores_park = Redirect(
            source="mission dolores park",
            destination=self.dolores_park,
            region=self.sf
        )
        self.mission_dolores_park.save()

        self.dog_park = Redirect(
            source="dog park",
            destination=self.duboce_park,
            region=self.sf
        )
        self.dog_park.save()
예제 #23
0
    def get_queryset(self):
        region = self.get_region()
        # A dummy page object.
        page = Page(slug=slugify(self.kwargs['slug']), region=region)
        latest_page = page.versions.most_recent()
        # Need to set the pk on the dummy page for correct MapData lookup.
        page.pk = latest_page.id
        page.name = latest_page.name

        self.mapdata = MapData(page=page, region=region)
        return self.mapdata.versions.all()
예제 #24
0
    def test_move_exists(self):
        ###########################################################
        # Moving a page that already exists should just silently
        # continue.
        ###########################################################

        p_sf = Page(region=self.sf)
        p_sf.content = "<p>Hello, world in SF.</p>"
        p_sf.name = "Page A"
        p_sf.save()

        p_oak = Page(region=self.oak)
        p_oak.content = "<p>Hello, world started on Oak.</p>"
        p_oak.name = "Page A"
        p_oak.save()

        move_to_region(self.sf, pages=[p_sf])
        # Shouldn't have been moved.
        p = Page.objects.filter(region=self.sf, name="Page A")[0]
        self.assertEqual(p.content, "<p>Hello, world in SF.</p>")
예제 #25
0
 def test_endless_include(self):
     """ Should detect endless loops and give an error message
     """
     a = Page(name='Front Page')
     a.content = '<a class="plugin includepage" href="Front_Page">dummy</a>'
     a.save()
     context = Context({'page': a})
     template = Template(html_to_template_text(a.content, context))
     html = template.render(context)
     self.failUnless(('Unable to include <a href="/Front_Page">Front Page'
                      '</a>: endless include loop') in html)
예제 #26
0
 def test_include_nonexistant(self):
     """ Should give an error message when including nonexistant page
     """
     a = Page(name='Front Page')
     a.content = '<a class="plugin includepage" href="New page">dummy</a>'
     a.save()
     context = Context({'page': a})
     template = Template(html_to_template_text(a.content, context))
     html = template.render(context)
     self.failUnless(('Unable to include <a href="/New_page"'
                      ' class="missing_link">New page</a>') in html)
예제 #27
0
    def _sample_setup(self):
        crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        memb = Member.objects.get(offering=crs, person__userid="ggbaker")

        p = Page(offering=crs, label="Index")
        p.save()
        v = PageVersion(page=p,
                        title="Index Page",
                        wikitext="Original Contents",
                        editor=memb)
        v.save()
        p = Page(offering=crs, label="OtherPage")
        p.save()
        v = PageVersion(page=p,
                        title="Other Page",
                        wikitext="Original Contents",
                        editor=memb)
        v.save()

        return crs
예제 #28
0
    def test_updating(self):
        """
        Test the way the full text index updates

        The real-time indexing is disabled in the tests environments: slows things down too much. Disabled these tests
        as a result, since they don't really match the deployed or devel behaviour.
        """
        return

        res = SearchQuerySet().models(CourseOffering).filter(text='Babbling')
        self.assertEqual(len(res), 1)
        self.assertEquals(res[0].object, self.offering)

        # don't expect CourseOfferings to update automatically
        self.offering.title = 'Something Else'
        self.offering.save()
        res = SearchQuerySet().models(CourseOffering).filter(text='Babbling')
        self.assertEqual(len(res), 1)

        # but a manual refresh should find changes
        self._update_index()
        res = SearchQuerySet().models(CourseOffering).filter(text='Babbling')
        self.assertEqual(len(res), 0)
        res = SearchQuerySet().models(CourseOffering).filter(text='Something')
        self.assertEqual(len(res), 1)

        # but we do update Pages in real time
        res = SearchQuerySet().models(Page).filter(text='fernwhizzles')
        self.assertEqual(len(res), 0)

        # create a page
        p = Page(offering=self.offering,
                 label='SomePage',
                 can_read='ALL',
                 can_write='STAF')
        p.save()
        pv = PageVersion(page=p,
                         title='Some Page',
                         wikitext='This is a page about fernwhizzles.',
                         editor=self.instructor)
        pv.save()
        res = SearchQuerySet().models(Page).filter(text='fernwhizzles')
        self.assertEqual(len(res), 1)

        # update a page
        pv = PageVersion(page=p,
                         title='Some Page',
                         wikitext='This is a page about bobdazzles.',
                         editor=self.instructor)
        pv.save()
        res = SearchQuerySet().models(Page).filter(text='fernwhizzles')
        self.assertEqual(len(res), 0)
        res = SearchQuerySet().models(Page).filter(text='bobdazzles')
        self.assertEqual(len(res), 1)
예제 #29
0
파일: views.py 프로젝트: tnq/localwiki
 def handler404(self, request, *args, **kwargs):
     page_slug = kwargs.get('slug')
     try:
         page = Page.objects.get(slug=slugify(page_slug))
     except Page.DoesNotExist:
         page = Page(slug=slugify(page_slug))
     mapdata = MapData(page=page)
     return HttpResponseNotFound(
         direct_to_template(request, 'maps/mapdata_new.html',
             {'page': page, 'mapdata': mapdata})
     )
예제 #30
0
 def _get_or_create_page(self):
     pagename = self.request.GET.get('pagename')
     region = self.get_region()
     has_page = Page.objects.filter(slug=slugify(pagename), region=region)
     if has_page:
         page = has_page[0]
     else:
         content = _('<p>What do you know about %s?</p>') % pagename
         page = Page(slug=slugify(pagename),
                     name=pagename,
                     content=content,
                     region=region)
     return page