Beispiel #1
0
    def make_instance(self, environ, start_response):
        req = Request(environ)
        try:
            user = auth.get_user(req, self.shared_secret_filename)
        except:
            return webob.exc.HTTPForbidden("not logged in")(
                environ, start_response)
        role = find_role_for_user(user, 
                                  environ['HTTP_X_OPENPLANS_PROJECT'],
                                  environ)
        if role != "ProjectAdmin":
            return webob.exc.HTTPForbidden("can't do that now")(
                environ, start_response)

        blog_url = "%s://%s%s" % (
            environ['HTTP_X_FORWARDED_SCHEME'],
            environ['HTTP_X_FORWARDED_SERVER'],
            environ['HTTP_X_FORWARDED_PATH'])

        instance = self.get_instance_folder(environ)
        dburi = "sqlite:///%s/database.db" % instance
        if not os.path.exists(os.path.dirname(dburi)):
            os.mkdir(os.path.dirname(dburi))
        new_instance(dburi,
                     instance,
                     blog_url)
        return webob.exc.HTTPFound(location=blog_url)(
            environ, start_response)
    def make_instance(self, environ, start_response):
        req = Request(environ)
        try:
            user = auth.get_user(req, self.shared_secret_filename)
        except:
            return webob.exc.HTTPForbidden("not logged in")(
                environ, start_response)
        role = find_role_for_user(user, 
                                  environ['HTTP_X_OPENPLANS_PROJECT'],
                                  environ)
        if role != "ProjectAdmin":
            return webob.exc.HTTPForbidden("can't do that now")(
                environ, start_response)

        blog_url = "%s://%s%s/%s" % (
            environ['HTTP_X_FORWARDED_SCHEME'],
            environ['HTTP_X_FORWARDED_SERVER'],
            environ['HTTP_X_FORWARDED_PATH'],
            Request(environ).path_info_peek())
        print blog_url

        blog_url = '/'.join((Request(environ).application_url, 
                             Request(environ).path_info_peek()))
        # blog_url must end in a trailing slash for url generation to work properly,
        # otherwise zine.utils.http:make_external_url will swallow it when building urls to posts;
        #  make_external_url("http://coactivate.org/foo", "bar/baz") -> "http://coactivate.org/bar/baz")
        #  make_external_url("http://coactivate.org/foo/", "bar/baz") -> "http://coactivate.org/foo/bar/baz")
        blog_url = blog_url.rstrip("/") + '/'

        instance = self.get_instance_folder(environ)
        dburi = "sqlite:///%s/database.db" % instance
        if not os.path.exists(instance):
            os.makedirs(instance)
        new_instance(dburi,
                     instance,
                     blog_url)
        return webob.exc.HTTPFound(location=blog_url)(
            environ, start_response)