~yeliabmas/sloecode/wiki-merge-proposal

« back to all changes in this revision

Viewing changes to sloecode/controllers/wiki.py

  • Committer: Sam Bailey
  • Date: 2012-09-12 21:47:02 UTC
  • Revision ID: yeliabmas@gmail.com-20120912214702-mvg6locka8cjnlh3
Replaced the wikkidviewadapters class structure with one file

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from wikkid.filestore.bzr import BranchFileStore
23
23
from bzrlib.workingtree import WorkingTree
24
24
from wikkid.context import ExecutionContext
25
 
from sloecode.wikkidviewadapters.factory import ViewAdapterFactory
 
25
from sloecode.wikkid_view_adapters import get_page_fragments
26
26
 
27
27
log = logging.getLogger(__name__)
28
 
factory = ViewAdapterFactory()
29
28
 
30
29
def _get_context(path):
31
 
    """Sets prefix to be the url minus the wiki path 
 
30
    """Sets prefix to be the url minus the wiki path
32
31
    (everything after /p/<project-name>/wiki/ is the wiki path)
33
32
    and returns an ExecutionContext with this as the script_name.
34
33
    """
35
 
    prefix = urllib.unquote(h.url.current())    
 
34
    prefix = urllib.unquote(h.url.current())
36
35
    if len(path) > 0:
37
36
        prefix = prefix[:-(len(path) + 1)]
38
37
    log.info("Prefix: '%s', current url: '%s'", prefix, h.url.current())
59
58
 
60
59
class WikiController(BaseController):
61
60
 
62
 
    def serve_wiki_page(self,path, branch, viewAdapter=None):
 
61
    def serve_wiki_page(self, path, branch, view_name=None):
63
62
        """Returns the fragments from the determined WikkidViewAdapter.
64
63
        Alternatively, WikkidViewAdapter can be specified in the parameter.
65
64
        """
76
75
        #Translate bzr user to Wikkid user
77
76
        environ['wikkid.user'] = create_bzr_user_from_author_string("%s <%s>"%(user.name, user.email))
78
77
 
79
 
        if viewAdapter is None:
80
 
            adapter = factory.get_view_adapter(app, environ)
81
 
        else:
82
 
            adapter = factory.get_specified_adapter(viewAdapter)
83
 
 
84
 
        new_environ = copy.copy(environ)
85
 
        app_request, path = app.preprocess_environ(new_environ)
 
78
        app_request, path = app.preprocess_environ(environ)
86
79
        log.info("Path: " + path)
87
80
 
88
 
        #Go through the WikkidApp for static files of if view adapter can't be found (mostly used for binary/images)
89
 
        if (path.startswith('/static/')) or (adapter is None):
 
81
        fragments = get_page_fragments(app, environ)
 
82
 
 
83
        #Go through the WikkidApp for static files of if view adapter can't
 
84
        # be found (mostly used for binary/images)
 
85
        if (path.startswith('/static/')) or (fragments is None):
90
86
            return app(environ, self.start_response)
91
87
 
92
 
        fragments = adapter.get_page_fragments(app, environ)
93
 
 
94
88
        if fragments['breadcrumbs'] is not None:
95
89
            fragments['breadcrumbs'] = _change_home_crumb_name(fragments['breadcrumbs'])
96
90
 
132
126
        prefix = urllib.unquote(h.url.current())
133
127
        prefix = prefix[1:-len(postfix)]
134
128
        log.info("Prefix: '%s', current url: '%s'", prefix, h.url.current())
135
 
                
 
129
 
136
130
 
137
131
        #Test that the project exists and has a branch called 'wiki'
138
132
        projects = Project.get(name=project_name)