Esempio n. 1
0
 def save(self, data, include_default=False):
     """Saves the primary site details and creates a new collection to house 
     the pages in.  It also creates a default (Home) page if needed.
     """
     doc = self.get_conn(app=self.appname).SiteDocument()
     doc["title"] = self.title = data["site"]["title"]
     doc["slug"] = self.slug = self.__name__ = str(h.urlify(self.title))
     doc.save()
     # Create default (home) page?
     if include_default:
         page = Page(parent=self)
         page.create(dict(page=dict(title=u"Home", source="sample.home")))
     return self
Esempio n. 2
0
 def save(self, data, include_default=False):
     """Saves the primary site details and creates a new collection to house 
     the pages in.  It also creates a default (Home) page if needed.
     """
     doc = self.get_conn(app=self.appname).SiteDocument()
     doc['title'] = self.title = data['site']['title']
     doc['slug'] = self.slug = self.__name__ = str(h.urlify(self.title))
     doc.save()
     #Create default (home) page?
     if include_default:
         page = Page(parent=self)
         page.create(dict(page=dict(title=u'Home', source='sample.home')))
     return self
Esempio n. 3
0
def new_site(context, request):
    """Add a new site.
    """
    # Handle submission
    if 'form.submitted' in request.params:
        title = request.params['title']
        slug = str(h.urlify(title))
        # Persist
        site = ctx.Site(key=slug, parent=context, title=title,
                        slug=slug).save(include_default=True)
        return HTTPFound(location=request.resource_url(context, site.__name__))
    save_site_url = request.resource_url(context, 'new-site')
    # Respond
    return dict(page_title="New Site", save_site_url=save_site_url)
Esempio n. 4
0
 def update(self, data, archive=True):
     """Update myself with data (and copy to the archives collection)
     """
     doc = self.pages_data().PageDocument.get_from_id(self.id)
     doc["title"] = self.title = data["page"]["title"]
     doc["slug"] = self.slug = self.__name__ = str(h.urlify(data["page"]["slug"]))
     doc["data"] = self.data = data["data"]
     doc["version"] = doc["version"] + 1
     doc.save(validate=False)
     # Create archived version?
     if archive:
         ver = deepcopy(doc)
         ver["pageid"] = doc["_id"]
         ver["archived"] = h.now()
         del (ver["_id"])
         self.history_data().insert(ver, validate=False)
     return self
Esempio n. 5
0
 def update(self, data, archive=True):
     """Update myself with data (and copy to the archives collection)
     """
     doc = self.pages_data().PageDocument.get_from_id(self.id)
     doc['title'] = self.title = data['page']['title']
     doc['slug'] = self.slug = self.__name__ = str(h.urlify(data['page']['slug']))
     doc['data'] = self.data = data['data']
     doc['version'] = doc['version'] + 1
     doc.save(validate=False)
     #Create archived version?
     if archive:
         ver = deepcopy(doc)
         ver['pageid'] = doc['_id']
         ver['archived'] = h.now()
         del(ver['_id'])
         self.history_data().insert(ver, validate=False)
     return self
Esempio n. 6
0
File: sites.py Progetto: kjq/piano
def new_site(context, request):
    """Add a new site.
    """
    # Handle submission
    if 'form.submitted' in request.params:
        title = request.params['title']
        slug = str(h.urlify(title))
        # Persist
        site = ctx.Site(
            key=slug,
            parent=context,
            title=title,
            slug=slug).save(include_default=True);
        return HTTPFound(location=request.resource_url(context, site.__name__))
    save_site_url = request.resource_url(context, 'new-site')
    # Respond
    return dict(
        page_title="New Site",
        save_site_url=save_site_url)
Esempio n. 7
0
def save_page(context, request):
    """Add, edit, and save a page.
    """
    # Handle submission
    if 'form.submitted' in request.params:
        title = request.params['title']
        slug = str(h.urlify(title))
        source = request.params['source']
        # Persist Page (home)
        page = ctx.Page(key=slug,
                        parent=context,
                        title=title,
                        slug=slug,
                        source=source).save()
        return HTTPFound(location=request.resource_url(context, page.__name__))
    save_page_url = request.resource_url(context, 'save-page')
    # Respond
    return dict(page_title="Edit Page",
                page_slug=context.__name__,
                save_page_url=save_page_url)
Esempio n. 8
0
File: pages.py Progetto: kjq/piano
def save_page(context, request):
    """Add, edit, and save a page.
    """
    # Handle submission
    if 'form.submitted' in request.params:
        title = request.params['title']
        slug = str(h.urlify(title))
        source = request.params['source']
        # Persist Page (home)
        page = ctx.Page(
            key=slug,
            parent=context,
            title=title,
            slug=slug,
            source=source).save()
        return HTTPFound(location=request.resource_url(context, page.__name__))
    save_page_url = request.resource_url(context, 'save-page')
    # Respond
    return dict(page_title="Edit Page",
                page_slug=context.__name__,
                save_page_url=save_page_url)
Esempio n. 9
0
 def create(self, data):
     """Creates a new page and associates it to a parent.
     """
     doc = self.pages_data().PageDocument()
     doc["title"] = self.title = data["page"]["title"]
     doc["slug"] = self.slug = self.__name__ = str(h.urlify(self.title))
     doc["source"] = self.source = str(data["page"]["source"])
     doc["parent"] = str(self.__parent__.__name__)
     # Try to import custom models and get doc
     try:
         # Explicitly look for a 'models' module with a 'PageModel' class
         mod = __import__(".".join([self.source, c.MODEL_PATH]), fromlist=[self.source])
         pdoc = getattr(mod, c.MODEL_NAME)
     except ImportError:
         logger.warn("Cannot import '%s.models' module" % self.source)
     except AttributeError:
         logger.warn("Cannot load '%s.models.PageModel' class" % self.source)
     else:
         # Embed a new document
         doc["data"] = pdoc()
     doc.save()
     return self
Esempio n. 10
0
 def create(self, data):
     """Creates a new page and associates it to a parent.
     """
     doc = self.pages_data().PageDocument()
     doc['title'] = self.title = data['page']['title']
     doc['slug'] = self.slug = self.__name__ = str(h.urlify(self.title))
     doc['source'] = self.source = str(data['page']['source'])
     doc['parent'] = str(self.__parent__.__name__)
     #Try to import custom models and get doc
     try:
         #Explicitly look for a 'models' module with a 'PageModel' class
         mod = __import__('.'.join([self.source, c.MODEL_PATH]), fromlist=[self.source])
         pdoc = getattr(mod, c.MODEL_NAME)
     except ImportError:
         logger.warn("Cannot import '%s.models' module" % self.source)
     except AttributeError:
         logger.warn("Cannot load '%s.models.PageModel' class" % self.source)
     else:
         #Embed a new document
         doc['data'] = pdoc()
     doc.save()
     return self