Пример #1
0
    def _setup_unittest_plugin(self):
        if os.path.exists(UNITTEST_PLUGIN_DST_PATH):
            print "unitest plugin already exist in: %r" % UNITTEST_PLUGIN_DST_PATH
        else:
            print "insert unittest plugin via symlink:"
            print "%s -> %s" % (UNITTEST_PLUGIN_SRC_PATH, UNITTEST_PLUGIN_DST_PATH)
            os.symlink(UNITTEST_PLUGIN_SRC_PATH, UNITTEST_PLUGIN_DST_PATH)

        template_dir = os.path.join(UNITTEST_PLUGIN_DST_PATH, "templates")
        if not template_dir in settings.TEMPLATE_DIRS:
            print "unittest_plugin added to settings.TEMPLATE_DIRS"
            settings.TEMPLATE_DIRS += (template_dir,)

        plugin_name = "pylucid_project.pylucid_plugins.unittest_plugin"
        if not plugin_name in settings.INSTALLED_APPS:
            print "unittest_plugin added to settings.INSTALLED_APPS"
            settings.INSTALLED_APPS.append(plugin_name)

        if not "unittest_plugin" in PYLUCID_PLUGINS:
            pkg_path = os.path.join(PYLUCID_PROJECT_ROOT, "pylucid_plugins")
            PYLUCID_PLUGINS["unittest_plugin"] = PyLucidPlugin(
                pkg_path, section="pylucid_project",
                pkg_dir="pylucid_plugins", plugin_name="unittest_plugin"
            )
            print "unittest_plugin added to PYLUCID_PLUGINS"
            print PYLUCID_PLUGINS.keys()
Пример #2
0
    def _setup_unittest_plugin(self):
        if os.path.exists(UNITTEST_PLUGIN_DST_PATH):
            print "unitest plugin already exist in: %r" % UNITTEST_PLUGIN_DST_PATH
        else:
            print "insert unittest plugin via symlink:"
            print "%s -> %s" % (UNITTEST_PLUGIN_SRC_PATH,
                                UNITTEST_PLUGIN_DST_PATH)
            os.symlink(UNITTEST_PLUGIN_SRC_PATH, UNITTEST_PLUGIN_DST_PATH)

        template_dir = os.path.join(UNITTEST_PLUGIN_DST_PATH, "templates")
        if not template_dir in settings.TEMPLATE_DIRS:
            print "unittest_plugin added to settings.TEMPLATE_DIRS"
            settings.TEMPLATE_DIRS += (template_dir, )

        plugin_name = "pylucid_project.pylucid_plugins.unittest_plugin"
        if not plugin_name in settings.INSTALLED_APPS:
            print "unittest_plugin added to settings.INSTALLED_APPS"
            settings.INSTALLED_APPS += (plugin_name, )

        if not "unittest_plugin" in PYLUCID_PLUGINS:
            pkg_path = os.path.join(PYLUCID_PROJECT_ROOT, "pylucid_plugins")
            PYLUCID_PLUGINS["unittest_plugin"] = PyLucidPlugin(
                pkg_path,
                section="pylucid_project",
                pkg_dir="pylucid_plugins",
                plugin_name="unittest_plugin")
            print "unittest_plugin added to PYLUCID_PLUGINS"
            print PYLUCID_PLUGINS.keys()
Пример #3
0
def _update08plugins(request, language):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 plugin data"
    out = SimpleStringIO()

    method_kwargs = {
        "out": out,
        "language": language,
    }

    filename = settings.PYLUCID.UPDATE08_PLUGIN_FILENAME
    view_name = settings.PYLUCID.UPDATE08_PLUGIN_VIEWNAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            plugin_instance.call_plugin_view(request, filename, view_name,
                                             method_kwargs)
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no update API
                continue
            if settings.DEBUG:
                raise
            messages.error(request, "failed updating %s." % plugin_name)
            messages.debug(request,
                           mark_safe("<pre>%s</pre>" % traceback.format_exc()))
        else:
            out.write(" --- %s END ---" % plugin_name)
Пример #4
0
def _update08plugins(request, language):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 plugin data"
    out = SimpleStringIO()

    method_kwargs = {
        "out": out,
        "language": language,
    }

    filename = settings.PYLUCID.UPDATE08_PLUGIN_FILENAME
    view_name = settings.PYLUCID.UPDATE08_PLUGIN_VIEWNAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            plugin_instance.call_plugin_view(request, filename, view_name,
                                             method_kwargs)
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no update API
                continue
            if settings.DEBUG:
                raise
            messages.error(request, "failed updating %s." % plugin_name)
            messages.debug(request,
                           mark_safe("<pre>%s</pre>" % traceback.format_exc()))
        else:
            out.write(" --- %s END ---" % plugin_name)
Пример #5
0
    def call_searchs(self, search_languages, search_strings, search_results):
        """ Call every plugin, witch has the search API. """
        filename = settings.PYLUCID.SEARCH_FILENAME
        class_name = settings.PYLUCID.SEARCH_CLASSNAME

        max_hits = self.preferences["max_hits"]

        plugin_count = 0
        too_much_hits = 0
        use_plugin = 0
        for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
            try:
                SearchClass = plugin_instance.get_plugin_object(filename, class_name)
#                plugin_instance.call_plugin_view(self.request, filename, view_name, method_kwargs)
            except plugin_instance.ObjectNotFound:
                # Plugin has no search API
                continue
            except Exception:
                if self.request.debug or self.request.user.is_staff:
                    messages.error(self.request, "Can't collect search results from %s." % plugin_name)
                    messages.debug(self.request, mark_safe("<pre>%s</pre>" % traceback.format_exc()))
                continue

            try:
                search_instance = SearchClass()
            except PluginNotOnSite, err:
                # Plugin is not used on this SITE
                if self.request.debug or self.request.user.is_staff:
                    messages.debug(self.request, "Skip %s: %s" % (plugin_name, err))
                continue
            else:
                plugin_count += 1

            queryset = search_instance.get_queryset(self.request, search_languages, search_strings)
            count = queryset.count()
            if self.request.user.is_staff:
                messages.info(self.request, "%s hits in %s" % (count, plugin_name))

            if count >= max_hits:
                too_much_hits += 1
                messages.info(self.request, "Skip too many results from %s" % plugin_name)
                LogEntry.objects.log_action(
                    app_label="search", action="too mutch hits",
                    message="Skip %s hits in %s for %s" % (count, plugin_name, repr(search_strings)),
                    data={
                        "search_strings": search_strings,
                        "hits": count,
                    }
                )
                continue

            use_plugin += 1

            if count > 0:
                search_instance.add_search_results(self.request, queryset, search_results)
Пример #6
0
 def __init__(self):
     """
     Collect all context_middleware class objects from all existing pylucid plugins
     """
     for plugin_name, plugin_instance in PYLUCID_PLUGINS.items():
         try:
             middleware_class = plugin_instance.get_plugin_object("context_middleware", "ContextMiddleware")
         except plugin_instance.ObjectNotFound, err:
             pass
         else:
             self._MIDDLEWARES[plugin_name] = middleware_class
Пример #7
0
 def __init__(self):
     """
     Collect all context_middleware class objects from all existing pylucid plugins
     """
     for plugin_name, plugin_instance in PYLUCID_PLUGINS.items():
         try:
             middleware_class = plugin_instance.get_plugin_object("context_middleware", "ContextMiddleware")
         except plugin_instance.ObjectNotFound, err:
             pass
         else:
             self._MIDDLEWARES[plugin_name] = middleware_class
Пример #8
0
    def __init__(self, request, out):
        self.request = request
        self.out = out

        for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
            if plugin_name == "pylucid":
                continue
            out.write("\tplugin: %r" % plugin_name)
            out.write("\t\tpath: %r" % plugin_instance.fs_path)
            self.test_objects(plugin_instance)
            self.test_modules(plugin_instance)
Пример #9
0
def tag_list(request):
    """ Create a list of all existing lucidTag plugin views. """
    lucid_tags = []
    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            lucidtag_view = plugin_instance.get_plugin_object(
                mod_name="views", obj_name="lucidTag"
            )
        except plugin_instance.ObjectNotFound, err:
            continue
        except Exception, err:
            if settings.DEBUG:
                raise
            messages.error(request, "Can't get plugin view: %s" % err)
            continue
Пример #10
0
def install_plugins(request):
    """
    Simple call all plugin install view, if exist.
    
    TODO: create a "install plugins" managment command and call it here! (This is useful for unittests)
    """
    output = []

    # Delete all items
    PyLucidAdminPage.objects.all().delete()

    output.append("*** Install Plugins:")

    filename = settings.ADMIN.VIEW_FILENAME
    view_name = settings.ADMIN.PLUGIN_INSTALL_VIEW_NAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            response = plugin_instance.call_plugin_view(request,
                                                        filename,
                                                        view_name,
                                                        method_kwargs={})
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no install API
                if settings.DEBUG:
                    output.append(
                        "Skip plugin %r, because it has no install view (%s)" %
                        (plugin_name, err))
                continue

            messages.error(
                request,
                "failed call %s.%s: %s" % (plugin_name, view_name, err))
            continue

        output.append("_" * 79)
        output.append(" *** install plugin %r ***" % plugin_name)
        assert isinstance(
            response, basestring
        ) == True, "Plugin install view must return a basestring!"
        output.append(response)

        output.append(" --- %s END ---" % plugin_name)
        output.append("")
Пример #11
0
def install_plugins(request):
    """
    Simple call all plugin install view, if exist.
    
    TODO: create a "install plugins" managment command and call it here! (This is useful for unittests)
    """
    output = []

    # Delete all items
    PyLucidAdminPage.objects.all().delete()

    output.append("*** Install Plugins:")

    filename = settings.ADMIN.VIEW_FILENAME
    view_name = settings.ADMIN.PLUGIN_INSTALL_VIEW_NAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            response = plugin_instance.call_plugin_view(request, filename, view_name, method_kwargs={})
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no install API
                if settings.DEBUG:
                    output.append("Skip plugin %r, because it has no install view (%s)" % (plugin_name, err))
                continue

            messages.error(request, "failed call %s.%s: %s" % (plugin_name, view_name, err))
            continue

        output.append("_" * 79)
        output.append(" *** install plugin %r ***" % plugin_name)
        assert isinstance(response, basestring) == True, "Plugin install view must return a basestring!"
        output.append(response)

        output.append(" --- %s END ---" % plugin_name)
        output.append("")
Пример #12
0
    def call_searchs(self, search_languages, search_strings, search_results):
        """ Call every plugin, witch has the search API. """
        method_kwargs = {
            "search_languages": search_languages,
            "search_strings": search_strings,
            "search_results": search_results
        }

        filename = settings.PYLUCID.SEARCH_FILENAME
        view_name = settings.PYLUCID.SEARCH_VIEWNAME

        plugin_count = 0
        for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
            try:
                plugin_instance.call_plugin_view(self.request, filename, view_name, method_kwargs)
            except Exception, err:
                if str(err).endswith("No module named %s" % filename):
                    # Plugin has no search API
                    continue
                if settings.DEBUG or self.request.user.is_staff:
                    messages.error(self.request, "Can't collect search results from %s." % plugin_name)
                    messages.debug(self.request, mark_safe("<pre>%s</pre>" % traceback.format_exc()))
            else:
                plugin_count += 1
Пример #13
0
        if settings.DEBUG or settings.PYLUCID.I18N_DEBUG:
            messages.error(request,
                "Language code in url %r is wrong! Redirect to %r." % (url_lang_code, new_url)
            )
        # redirect the client to the right url
        return http.HttpResponsePermanentRedirect(new_url)

    # Create initial context object
    request.PYLUCID.context = context = RequestContext(request)

    # it will be filled either by plugin or by PageContent:
    context["page_content"] = None

    # call a pylucid plugin "html get view", if exist
    get_view_response = PYLUCID_PLUGINS.call_get_views(request)
    if isinstance(get_view_response, http.HttpResponse):
        # Plugin would be build the complete html page
        return get_view_response
    elif isinstance(get_view_response, basestring):
        # Plugin replace the page content
        context["page_content"] = get_view_response
    elif get_view_response is not None: # Use plugin response
        raise TypeError(
            "Plugin view must return None or basestring or HttpResponse! (returned: %r)"
        ) % type(get_view_response)


    # call page plugin, if current page is a plugin page and no get view has filled the page content
    page_plugin_response = None
    if is_plugin_page and context["page_content"] is None:
Пример #14
0
def render_page(request, url_lang_code, url_path):
    """ render a PageContent page """
    path_info = request.PYLUCID.path_info
    pagetree = request.PYLUCID.pagetree
    pagemeta = request.PYLUCID.pagemeta

    # Should never happen, because all Plugin Pages should be catched
    # in url.py before
    assert pagetree.page_type == PageTree.PAGE_TYPE

    url_lang_code = path_info.url_lang_code

    # Check the language code in the url, if exist
    if url_lang_code.lower() != pagemeta.language.code.lower():
        # The language code in the url is wrong. e.g.: The client followed a external url with was wrong.
        # Note: The main_manu doesn't show links to not existing PageMeta entries!

        # change only the lang code in the url:
        new_url = i18n.change_url(request, new_lang_code=pagemeta.language.code)

        if settings.DEBUG or settings.PYLUCID.I18N_DEBUG:
            messages.error(request,
                "Language code in url %r is wrong! Redirect to %r." % (url_lang_code, new_url)
            )
        # redirect the client to the right url
        return http.HttpResponsePermanentRedirect(new_url)

    # Create initial context object
    context = request.PYLUCID.context = RequestContext(request)

    # it will be filled either by plugin or by PageContent:
    context["page_content"] = None

    # call a pylucid plugin "html get view", if exist
    get_view_response = PYLUCID_PLUGINS.call_get_views(request)
    if isinstance(get_view_response, http.HttpResponse):
        # Plugin would be build the complete html page
        return get_view_response
    elif isinstance(get_view_response, basestring):
        # Plugin replace the page content
        context["page_content"] = get_view_response
    elif get_view_response is not None: # Use plugin response
        raise # Should never happen here, because PYLUCID_PLUGINS.call_get_views() should raise before

    if context["page_content"] is None:
        # Plugin has not filled the page content
        pagecontent_instance = _get_page_content(request)
        request.PYLUCID.pagecontent = request.PYLUCID.updateinfo_object = pagecontent_instance
        context["page_content"] = apply_markup(
            pagecontent_instance.content, pagecontent_instance.markup, request
        )

    # put update information into context
    for itemname in ("createby", "lastupdateby", "createtime", "lastupdatetime"):
        context["page_%s" % itemname] = getattr(request.PYLUCID.updateinfo_object, itemname, None)

    # Render django tags in PageContent with the global context
    context["page_content"] = render.render_string_template(context["page_content"], context)

    template_name = context["base_template_name"] # Added in pylucid.context_processors
    page_template = loader.get_template(template_name)
    pre_render_global_template.send(sender=None, request=request, page_template=page_template)

    # Render django tags in global template with global context
    complete_page = page_template.render(context)

    # create response object
    response = http.HttpResponse(complete_page, mimetype="text/html")
    response["content-language"] = context["page_language"]

    return response
Пример #15
0
def render_page(request, url_lang_code, url_path):
    """ render a PageContent page """
    path_info = request.PYLUCID.path_info
    pagetree = request.PYLUCID.pagetree
    pagemeta = request.PYLUCID.pagemeta

    # Should never happen, because all Plugin Pages should be catched
    # in url.py before
    assert pagetree.page_type == PageTree.PAGE_TYPE

    url_lang_code = path_info.url_lang_code

    # Check the language code in the url, if exist
    if url_lang_code.lower() != pagemeta.language.code.lower():
        # The language code in the url is wrong. e.g.: The client followed a external url with was wrong.
        # Note: The main_manu doesn't show links to not existing PageMeta entries!

        # change only the lang code in the url:
        new_url = i18n.change_url(request,
                                  new_lang_code=pagemeta.language.code)

        if settings.DEBUG or settings.PYLUCID.I18N_DEBUG:
            messages.error(
                request, "Language code in url %r is wrong! Redirect to %r." %
                (url_lang_code, new_url))
        # redirect the client to the right url
        return http.HttpResponsePermanentRedirect(new_url)

    # Create initial context object
    context = request.PYLUCID.context = RequestContext(request)

    # it will be filled either by plugin or by PageContent:
    context["page_content"] = None

    # call a pylucid plugin "html get view", if exist
    get_view_response = PYLUCID_PLUGINS.call_get_views(request)
    if isinstance(get_view_response, http.HttpResponse):
        # Plugin would be build the complete html page
        return get_view_response
    elif isinstance(get_view_response, basestring):
        # Plugin replace the page content
        context["page_content"] = get_view_response
    elif get_view_response is not None:  # Use plugin response
        raise  # Should never happen here, because PYLUCID_PLUGINS.call_get_views() should raise before

    if context["page_content"] is None:
        # Plugin has not filled the page content
        pagecontent_instance = _get_page_content(request)
        request.PYLUCID.pagecontent = request.PYLUCID.updateinfo_object = pagecontent_instance
        context["page_content"] = apply_markup(pagecontent_instance.content,
                                               pagecontent_instance.markup,
                                               request)

    # put update information into context
    for itemname in ("createby", "lastupdateby", "createtime",
                     "lastupdatetime"):
        context["page_%s" % itemname] = getattr(
            request.PYLUCID.updateinfo_object, itemname, None)

    # Render django tags in PageContent with the global context
    context["page_content"] = render.render_string_template(
        context["page_content"], context)

    template_name = context[
        "base_template_name"]  # Added in pylucid.context_processors
    page_template = loader.get_template(template_name)
    pre_render_global_template.send(sender=None,
                                    request=request,
                                    page_template=page_template)

    # Render django tags in global template with global context
    complete_page = page_template.render(context)

    # create response object
    response = http.HttpResponse(complete_page, mimetype="text/html")
    response["content-language"] = context["page_language"]

    return response
Пример #16
0
    $Rev$
    $Author:$

    :copyleft: 2009 by the PyLucid team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""
from django.conf import settings
from django.conf.urls import patterns, url, include

from pylucid_project.apps.pylucid_admin import views
from pylucid_project.system.pylucid_plugins import PYLUCID_PLUGINS

from pylucid_project.apps.pylucid.decorators import superuser_only


plugin_admin_urls = PYLUCID_PLUGINS.get_admin_urls()


# from pylucid_project.utils.url_debug import UrlPatternInfo
# for url_dict in UrlPatternInfo().get_url_info(plugin_admin_urls[:]):
#     print "*", url_dict.get("url", "-")


urlpatterns = patterns('',
    url(r'^menu/$', views.menu, name='PyLucidAdmin-menu'),

    url(r'^plugins/', include(plugin_admin_urls)),

    url(r'^install/pylucid/$', superuser_only(views.install_pylucid), name='PyLucidAdmin-install_pylucid'),
    url(r'^install/plugins/$', superuser_only(views.install_plugins), name='PyLucidAdmin-install_plugins'),
)
Пример #17
0
    PyLucid admin url patterns
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Last commit info:
    ~~~~~~~~~~~~~~~~~
    $LastChangedDate$
    $Rev$
    $Author:$

    :copyleft: 2009 by the PyLucid team, see AUTHORS for more details.
    :license: GNU GPL v3 or above, see LICENSE for more details.
"""
from django.conf import settings
from django.conf.urls.defaults import patterns, url, include

from pylucid_project.apps.pylucid_admin import views
from pylucid_project.system.pylucid_plugins import PYLUCID_PLUGINS

from pylucid_project.apps.pylucid.decorators import superuser_only

plugin_admin_urls = PYLUCID_PLUGINS.get_admin_urls()

urlpatterns = patterns('',
    url(r'^menu/$', views.menu, name='PyLucidAdmin-menu'),

    url(r'^plugins/', include(plugin_admin_urls)),

    url(r'^install/pylucid/$', superuser_only(views.install_pylucid), name='PyLucidAdmin-install_pylucid'),
    url(r'^install/plugins/$', superuser_only(views.install_plugins), name='PyLucidAdmin-install_plugins'),
)