Changeset 2071

Show
Ignore:
Timestamp:
07/03/09 09:34:57 (9 months ago)
Author:
JensDiemer
Message:

* add PyLucid objects via middleware. So it's exist everywhere.
* add a "robots" field in PageMeta? for {{ page_robots }}
* add "urls_filename" in PluginPage?: It's for admin views.
* setup lang_entry direct in PyLucid objects.

Location:
branches/0.9/pylucid_project
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/apps/pylucid/models.py

    r2069 r2071  
    156156 
    157157 
    158  
    159158class PageTree(UpdateInfoBaseModel): 
    160159    """ 
     
    291290    description = models.CharField(blank=True, max_length=255, help_text="For html header") 
    292291 
     292    robots = models.CharField(max_length=255, default="index,follow", 
     293        help_text="for html 'robots' meta content." 
     294    ) 
     295 
    293296    permitViewGroup = models.ForeignKey(Group, related_name="%(class)s_permitViewGroup", 
    294297        help_text="Limit viewable to a group?", 
     
    331334    app_label = models.CharField(max_length=256, choices=APP_LABEL_CHOICES, 
    332335        help_text="The app lable witch is in settings.INSTALLED_APPS" 
     336    ) 
     337    urls_filename = models.CharField(max_length=256, default="urls.py", 
     338        help_text="Filename of the urls.py" 
    333339    ) 
    334340 
  • branches/0.9/pylucid_project/apps/pylucid/system/pylucid_objects.py

    r2037 r2071  
    1919""" 
    2020 
     21from django.conf import settings 
     22 
    2123from pylucid.models import Language 
    2224from pylucid.system import extrahead 
    2325from pylucid.preference_forms import SystemPreferencesForm 
    2426 
     27 
    2528class PyLucidRequestObjects(object): 
    2629    """ PyLucid request objects """ 
    27     def __init__(self): 
     30    def __init__(self, request): 
    2831        self.system_preferences = SystemPreferencesForm().get_preferences() 
    2932        default_lang_code = self.system_preferences["lang_code"] 
    3033        self.default_lang_code = default_lang_code 
    3134        self.default_lang_entry = Language.objects.get(code=default_lang_code) 
    32          
     35 
     36        # The current language instance 
     37        try: 
     38            self.lang_entry = Language.objects.get(code=request.LANGUAGE_CODE) 
     39        except Language.DoesNotExist: 
     40            self.lang_entry = self.default_lang_entry 
     41            if settings.PYLUCID.I18N_DEBUG: 
     42                request.page_msg.error( 
     43                    'Favored language "%s" does not exist -> use default lang from system preferences' % ( 
     44                        request.LANGUAGE_CODE 
     45                    ) 
     46                ) 
     47 
    3348        # Storing extra html head code from plugins, used in: 
    3449        # pylucid.defaulttags.extraheadBlock - redirect {% extrahead %} block tag content 
    3550        # pylucid_plugin.extrahead.context_middleware - insert the data into the global page 
    3651        self.extrahead = extrahead.ExtraHead() 
    37          
     52 
    3853        # objects witch will be set later: 
    3954        #self.pagetree - The current PageTree model instance 
    4055        #self.pagemeta - The current PageMeta model instance 
    4156        #self.pagecontent - PageContent instance, but only if the current page is not a PagePlugin! 
    42         #self.lang_entry - The current language instance 
    4357        #self.page_template - The globale page template as a string 
    4458        #self.context - The globale context 
  • branches/0.9/pylucid_project/apps/pylucid/views.py

    r2065 r2071  
    9797        "page_keywords": pagemeta.keywords, 
    9898        "page_description": pagemeta.description, 
     99        "page_robots": pagemeta.robots, 
    99100        "page_language": pagemeta.lang.code, 
    100101    }) 
     
    207208 
    208209 
    209 def _add_pylucid_request_objects(request): 
    210     """ Add PyLucid objects to the request object """ 
    211     request.PYLUCID = pylucid_objects.PyLucidRequestObjects() 
    212  
    213  
    214210def _prepage_request(request, lang_entry): 
    215211    """ 
     
    233229def root_page(request): 
    234230    """ render the first root page in system default language """ 
    235     _add_pylucid_request_objects(request) 
    236  
    237231    # activate language via auto detection 
    238232    i18n.activate_auto_language(request) 
     
    243237def lang_root_page(request, url_lang_code): 
    244238    """ url with lang code but no page slug """ 
    245     _add_pylucid_request_objects(request) 
    246  
    247239    try: 
    248240        lang_entry = Language.objects.get(code=url_lang_code) 
     
    283275def resolve_url(request, url_lang_code, url_path): 
    284276    """ url with lang_code and sub page path """ 
    285     _add_pylucid_request_objects(request) 
    286  
    287277    try: 
    288278        lang_entry = Language.objects.get(code=url_lang_code) 
     
    305295    We redirect to a url with language code. 
    306296    """ 
    307     _add_pylucid_request_objects(request) 
    308  
    309297    # redirect to a url with the default language code. 
    310298    return _i18n_redirect(request, url_path) 
  • branches/0.9/pylucid_project/apps/pylucid_update/views.py

    r2056 r2071  
    5252    out.write("\n______________________________________________________________") 
    5353    out.write("Move JS-SHA-Login data into new UserProfile\n") 
    54     for old_entry in JS_LoginData08.objects.all():        
     54    for old_entry in JS_LoginData08.objects.all(): 
    5555        user = old_entry.user 
    5656        sha_login_checksum = old_entry.sha_checksum 
    5757        sha_login_salt = old_entry.salt 
    58          
    59         userprofile, created = UserProfile.objects.get_or_create(user = user) 
     58 
     59        userprofile, created = UserProfile.objects.get_or_create(user=user) 
    6060        #userprofile.site.add(site)            
    6161        if created: 
     
    6363        else: 
    6464            out.write("UserProfile for user '%s' exist." % user.username) 
    65              
     65 
    6666        if not userprofile.sha_login_checksum: 
    6767            # Add old sha login data, only if not exist. 
     
    7777        new_template_name = settings.SITE_TEMPLATE_PREFIX + template.name + ".html" 
    7878        new_template, created = Template.objects.get_or_create( 
    79             name = new_template_name, 
    80             defaults = { 
     79            name=new_template_name, 
     80            defaults={ 
    8181                "content": template.content, 
    8282                "creation_date": template.createtime, 
     
    9797    for style in Style08.objects.all(): 
    9898        new_staticfile, created = EditableHtmlHeadFile.objects.get_or_create( 
    99             filepath = settings.SITE_TEMPLATE_PREFIX + style.name + ".css", 
    100             defaults = { 
     99            filepath=settings.SITE_TEMPLATE_PREFIX + style.name + ".css", 
     100            defaults={ 
    101101                "description": style.description, 
    102102                "content": style.content, 
     
    124124        #--------------------------------------------------------------------- 
    125125        # create/get Design entry 
    126          
     126 
    127127        design_key = "%s %s" % (old_page.template.name, old_page.style.name) 
    128128        if design_key not in designs: 
     
    133133            else: 
    134134                new_design_name = "%s + %s" % (old_page.template.name, style_name) 
    135                  
     135 
    136136            design, created = Design.objects.get_or_create( 
    137                 name = new_design_name, 
    138                 defaults = { 
     137                name=new_design_name, 
     138                defaults={ 
    139139                    "template": templates[old_page.template.name], 
    140140                } 
     
    149149            assert isinstance(css_file, EditableHtmlHeadFile) 
    150150            design.headfiles.add(css_file) 
    151                  
     151 
    152152            colorscheme, created = ColorScheme.objects.get_or_create(name=style_name) 
    153153            if created: 
     
    156156            else: 
    157157                out.write("Use color scheme: %s" % colorscheme.name) 
    158                  
     158 
    159159            design.colorscheme = colorscheme 
    160160            design.save() 
     
    163163            design = designs[design_key] 
    164164            out.write("Use existing Design: %r" % design) 
    165              
     165 
    166166        #--------------------------------------------------------------------- 
    167167        # create/get PageTree entry 
     
    173173 
    174174        tree_entry, created = PageTree.objects.get_or_create( 
    175             site = site, 
    176             slug = old_page.shortcut, 
    177             parent = parent, 
    178             defaults = { 
     175            site=site, 
     176            slug=old_page.shortcut, 
     177            parent=parent, 
     178            defaults={ 
    179179                "position": old_page.position, 
    180180 
     
    198198 
    199199        page_dict[old_page.id] = tree_entry 
    200          
     200 
    201201        #--------------------------------------------------------------------- 
    202202        # create/get PageMeta entry 
    203          
     203 
    204204        pagemeta_entry, created = PageMeta.objects.get_or_create( 
    205             page = tree_entry, 
    206             lang = language, 
    207             defaults = { 
     205            page=tree_entry, 
     206            lang=language, 
     207            defaults={ 
    208208                "name": old_page.name, 
    209209                "title": old_page.title, 
     
    222222        else: 
    223223            out.write("PageMeta entry '%s' - '%s' exist." % (language, tree_entry.slug)) 
    224          
     224 
    225225        #--------------------------------------------------------------------- 
    226226        # create/get PageContent entry 
    227227 
    228228        content_entry, created = PageContent.objects.get_or_create( 
    229             page = tree_entry, 
    230             lang = language, 
    231             pagemeta = pagemeta_entry, 
    232             defaults = { 
     229            page=tree_entry, 
     230            lang=language, 
     231            pagemeta=pagemeta_entry, 
     232            defaults={ 
    233233                "content": old_page.content, 
    234234                "markup": old_page.markup, 
     
    277277    title = "Update PyLucid v0.8 templates" 
    278278    out = SimpleStringIO() 
    279      
     279 
    280280    def replace(content, out, old, new): 
    281281        out.write("replace %r with %r" % (old, new)) 
     
    285285            content = content.replace(old, new) 
    286286        return content 
    287          
    288      
     287 
     288 
    289289    for template in Template.objects.filter(name__istartswith=settings.SITE_TEMPLATE_PREFIX): 
    290290        out.write("\n______________________________________________________________") 
    291291        out.write("Update Template: '%s'\n" % template.name) 
    292          
     292 
    293293        content = template.content 
    294294 
     
    309309            ) 
    310310        } 
    311         new_head_file_tag += '<!-- ContextMiddleware extrahead -->\n'       
    312          
    313         content = replace(content, out,"{% lucidTag page_style %}", new_head_file_tag) 
     311        new_head_file_tag += '<!-- ContextMiddleware extrahead -->\n' 
     312 
     313        content = replace(content, out, "{% lucidTag page_style %}", new_head_file_tag) 
    314314        # temp in developer version: 
    315         content = replace(content, out,"{% lucidTag head_files %}", new_head_file_tag) 
    316         content = replace(content, out,"<!-- ContextMiddleware head_files -->", new_head_file_tag) 
    317          
    318         content = replace(content, out,"{{ login_link }}", "{% lucidTag auth %}") 
    319          
    320         content = replace(content, out,"{% lucidTag back_links %}", "<!-- ContextMiddleware breadcrumb -->") 
     315        content = replace(content, out, "{% lucidTag head_files %}", new_head_file_tag) 
     316        content = replace(content, out, "<!-- ContextMiddleware head_files -->", new_head_file_tag) 
     317 
     318        content = replace(content, out, "{{ login_link }}", "{% lucidTag auth %}") 
     319 
     320        content = replace(content, out, "{% lucidTag back_links %}", "<!-- ContextMiddleware breadcrumb -->") 
    321321        content = replace(content, out, 
    322322            "{{ PAGE.content }}", 
     
    329329            "{{ page_title }}" 
    330330        ) 
    331         content = replace(content, out,"PAGE.title", "page_title") 
    332         content = replace(content, out,"{{ PAGE.keywords }}", "{{ page_keywords }}") 
    333         content = replace(content, out,"{{ PAGE.description }}", "{{ page_description }}") 
    334          
    335         content = replace(content, out,"{{ PAGE.datetime", "{{ page_createtime") 
    336          
     331        content = replace(content, out, "PAGE.title", "page_title") 
     332        content = replace(content, out, "{{ PAGE.keywords }}", "{{ page_keywords }}") 
     333        content = replace(content, out, "{{ PAGE.description }}", "{{ page_description }}") 
     334        content = replace(content, out, "{{ robots }}", "{{ page_robots }}") 
     335 
     336        content = replace(content, out, "{{ PAGE.datetime", "{{ page_createtime") 
     337 
    337338        for timestring in ("lastupdatetime", "createtime"): 
    338339            # Change time with filter: 
     
    346347                '{{ page_%s|date:_("DATETIME_FORMAT") }}' % timestring, 
    347348            ) 
    348          
    349         content = replace(content, out,"{{ PAGE.", "{{ page_") 
    350          
     349 
     350        content = replace(content, out, "{{ PAGE.", "{{ page_") 
     351 
    351352        if "{% lucidTag language %}" not in content: 
    352353            # Add language plugin after breadcrumb, if not exist 
     
    356357                "<p>{% lucidTag language %}</p>\n" 
    357358            ) 
    358          
     359 
    359360        # TODO: add somthing like: <meta http-equiv="Content-Language" content="en" /> 
    360          
     361 
    361362        template.content = content 
    362363        template.save() 
    363          
    364         out.write("Template updated.")         
    365      
     364 
     365        out.write("Template updated.") 
     366 
    366367    context = { 
    367368        "title": title, 
     
    370371    return render_to_response('pylucid_update/update08result.html', context, 
    371372        context_instance=RequestContext(request)) 
    372      
     373 
    373374 
    374375 
     
    381382    title = "Update PyLucid v0.8 styles" 
    382383    out = SimpleStringIO() 
    383      
     384 
    384385    def update_headfile_colorscheme(design, headfile): 
    385386        out.write("\nExtract colors from: '%s'" % headfile.filepath) 
     
    388389        if colorscheme == None: 
    389390            # This design has no color scheme, yet -> create one 
    390             colorscheme=ColorScheme(name=headfile.filepath) 
     391            colorscheme = ColorScheme(name=headfile.filepath) 
    391392            colorscheme.save() 
    392393            out.write("Add color scheme %r to %r" % (colorscheme.name, design.name)) 
    393394            design.colorscheme = colorscheme 
    394395            design.save() 
    395          
     396 
    396397        out.write("Use color scheme %r" % colorscheme.name) 
    397          
     398 
    398399        content = headfile.content 
    399400        new_content, color_dict = extract_colors(content) 
     
    405406        out.write("updated colors: %r" % updated) 
    406407        out.write("exists colors: %r" % exists) 
    407          
     408 
    408409        colorscheme.save() 
    409          
     410 
    410411        headfile.content = new_content 
    411412        headfile.render = True 
    412413        headfile.save() 
    413          
    414          
     414 
     415 
    415416    def update_all_design_colorscheme(design): 
    416417        headfiles = design.headfiles.all() 
    417418        out.write("\nExisting headfiles: %r" % headfiles) 
    418          
     419 
    419420        for headfile in headfiles: 
    420421            if not headfile.filepath.lower().endswith(".css"): 
     
    422423            else: 
    423424                update_headfile_colorscheme(design, headfile) 
    424      
     425 
    425426    for design in Design.objects.all(): 
    426427        out.write("\n______________________________________________________________") 
    427428        out.write("\nUpdate color scheme for design: '%s'" % design.name) 
    428                  
     429 
    429430        update_all_design_colorscheme(design) 
    430      
    431      
     431 
     432 
    432433#    styles = EditableHtmlHeadFile.objects.filter(filepath__istartswith=settings.SITE_TEMPLATE_PREFIX) 
    433434#    styles = styles.filter(filepath__iendswith=".css") 
     
    443444#        out.write(new_content) 
    444445#        out.write(repr(color_dict)) 
    445      
     446 
    446447#    def replace(content, out, old, new): 
    447448#        out.write("replace %r with %r" % (old, new)) 
     
    469470#            style.save() 
    470471#            out.write("additional styles inserted.")         
    471      
     472 
    472473    context = { 
    473474        "title": title, 
  • branches/0.9/pylucid_project/settings.py

    r2070 r2071  
    3030 
    3131import pylucid_project 
    32 import pylucid_plugins 
     32from pylucid_project.utils import pylucid_plugins 
    3333 
    3434PYLUCID_PROJECT_ROOT = os.path.abspath(os.path.dirname(pylucid_project.__file__)) 
    35 PYLUCID_PLUGINS_ROOT = os.path.abspath(os.path.dirname(pylucid_plugins.__file__)) 
     35#PYLUCID_PLUGINS_ROOT = os.path.abspath(os.path.dirname(pylucid_plugins.__file__)) 
    3636 
    3737#______________________________________________________________________________ 
     
    3939 
    4040_path_list = ( 
    41     PYLUCID_PLUGINS_ROOT, 
     41#    PYLUCID_PLUGINS_ROOT, 
    4242    PYLUCID_PROJECT_ROOT, 
    4343    os.path.join(PYLUCID_PROJECT_ROOT, "apps") 
     
    8585    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    8686 
     87    'pylucid_project.middlewares.PyLucidMiddleware.PyLucidMiddleware', 
    8788    'pylucid_project.middlewares.PageMessages.PageMessagesMiddleware', 
    8889 
     
    9394SLOWER_DEV_SERVER_SLEEP = 0.3 # time.sleep() value (in sec.) 
    9495 
    95 _BASE_PATH = os.path.join(os.path.dirname(__file__)) 
    96  
    97 _plugins = pylucid_plugins.PluginList( 
    98     fs_path=os.path.join(_BASE_PATH, "pylucid_plugins"), 
    99     pkg_prefix="pylucid_project.pylucid_plugins" 
    100 ) 
     96PYLUCID_BASE_PATH = os.path.join(os.path.dirname(__file__)) 
     97 
     98_PYLUCID_PLUGIN_PACKAGES = ( 
     99    (os.path.join(PYLUCID_BASE_PATH, "pylucid_plugins"), "pylucid_project.pylucid_plugins"), 
     100    #(os.path.join(PYLUCID_BASE_PATH, "external_plugins"), "pylucid_project.external_pylucid_plugins"), 
     101) 
     102pylucid_plugins.setup_plugins(_PYLUCID_PLUGIN_PACKAGES) 
    101103 
    102104TEMPLATE_DIRS = ( 
    103     os.path.join(_BASE_PATH, "apps/pylucid/templates/"), 
    104     os.path.join(_BASE_PATH, "apps/pylucid_admin/templates/"), 
    105     os.path.join(_BASE_PATH, "apps/pylucid_update/templates/"), 
    106  
    107     os.path.join(_BASE_PATH, "apps/dbpreferences/templates/"), 
    108  
    109     os.path.join(_BASE_PATH, "django/contrib/admin/templates"), 
     105    os.path.join(PYLUCID_BASE_PATH, "apps/pylucid/templates/"), 
     106    os.path.join(PYLUCID_BASE_PATH, "apps/pylucid_admin/templates/"), 
     107    os.path.join(PYLUCID_BASE_PATH, "apps/pylucid_update/templates/"), 
     108 
     109    os.path.join(PYLUCID_BASE_PATH, "apps/dbpreferences/templates/"), 
     110 
     111    os.path.join(PYLUCID_BASE_PATH, "django/contrib/admin/templates"), 
    110112) 
    111113# Add all templates subdirs from all existing PyLucid plugins 
    112 TEMPLATE_DIRS += _plugins.get_template_dirs() 
     114TEMPLATE_DIRS += pylucid_plugins.PLUGINS.template_dirs 
     115#print "settings.TEMPLATE_DIRS:", TEMPLATE_DIRS 
    113116 
    114117TEMPLATE_LOADERS = ( 
     
    161164) 
    162165# Add all existing PyLucid plugins 
    163 INSTALLED_APPS += _plugins.get_installed_apps() 
    164 #print INSTALLED_APPS 
     166INSTALLED_APPS += pylucid_plugins.PLUGINS.pkg_list 
     167#print "settings.INSTALLED_APPS:", INSTALLED_APPS 
    165168 
    166169#http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEST_RUNNER 
     
    201204#     Example-1: "./media/" (default) 
    202205#     Example-2: "/home/foo/htdocs/media/" 
    203 MEDIA_ROOT = os.path.join(_BASE_PATH, "media") + "/" 
     206MEDIA_ROOT = os.path.join(PYLUCID_BASE_PATH, "media") + "/" 
    204207 
    205208# URL that handles the media served from MEDIA_ROOT.