Changeset 2071
- Timestamp:
- 07/03/09 09:34:57 (9 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 1 added
- 5 modified
-
apps/pylucid/models.py (modified) (3 diffs)
-
apps/pylucid/system/pylucid_objects.py (modified) (1 diff)
-
apps/pylucid/views.py (modified) (6 diffs)
-
apps/pylucid_update/views.py (modified) (25 diffs)
-
middlewares/PyLucidMiddleware.py (added)
-
settings.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/apps/pylucid/models.py
r2069 r2071 156 156 157 157 158 159 158 class PageTree(UpdateInfoBaseModel): 160 159 """ … … 291 290 description = models.CharField(blank=True, max_length=255, help_text="For html header") 292 291 292 robots = models.CharField(max_length=255, default="index,follow", 293 help_text="for html 'robots' meta content." 294 ) 295 293 296 permitViewGroup = models.ForeignKey(Group, related_name="%(class)s_permitViewGroup", 294 297 help_text="Limit viewable to a group?", … … 331 334 app_label = models.CharField(max_length=256, choices=APP_LABEL_CHOICES, 332 335 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" 333 339 ) 334 340 -
branches/0.9/pylucid_project/apps/pylucid/system/pylucid_objects.py
r2037 r2071 19 19 """ 20 20 21 from django.conf import settings 22 21 23 from pylucid.models import Language 22 24 from pylucid.system import extrahead 23 25 from pylucid.preference_forms import SystemPreferencesForm 24 26 27 25 28 class PyLucidRequestObjects(object): 26 29 """ PyLucid request objects """ 27 def __init__(self ):30 def __init__(self, request): 28 31 self.system_preferences = SystemPreferencesForm().get_preferences() 29 32 default_lang_code = self.system_preferences["lang_code"] 30 33 self.default_lang_code = default_lang_code 31 34 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 33 48 # Storing extra html head code from plugins, used in: 34 49 # pylucid.defaulttags.extraheadBlock - redirect {% extrahead %} block tag content 35 50 # pylucid_plugin.extrahead.context_middleware - insert the data into the global page 36 51 self.extrahead = extrahead.ExtraHead() 37 52 38 53 # objects witch will be set later: 39 54 #self.pagetree - The current PageTree model instance 40 55 #self.pagemeta - The current PageMeta model instance 41 56 #self.pagecontent - PageContent instance, but only if the current page is not a PagePlugin! 42 #self.lang_entry - The current language instance43 57 #self.page_template - The globale page template as a string 44 58 #self.context - The globale context -
branches/0.9/pylucid_project/apps/pylucid/views.py
r2065 r2071 97 97 "page_keywords": pagemeta.keywords, 98 98 "page_description": pagemeta.description, 99 "page_robots": pagemeta.robots, 99 100 "page_language": pagemeta.lang.code, 100 101 }) … … 207 208 208 209 209 def _add_pylucid_request_objects(request):210 """ Add PyLucid objects to the request object """211 request.PYLUCID = pylucid_objects.PyLucidRequestObjects()212 213 214 210 def _prepage_request(request, lang_entry): 215 211 """ … … 233 229 def root_page(request): 234 230 """ render the first root page in system default language """ 235 _add_pylucid_request_objects(request)236 237 231 # activate language via auto detection 238 232 i18n.activate_auto_language(request) … … 243 237 def lang_root_page(request, url_lang_code): 244 238 """ url with lang code but no page slug """ 245 _add_pylucid_request_objects(request)246 247 239 try: 248 240 lang_entry = Language.objects.get(code=url_lang_code) … … 283 275 def resolve_url(request, url_lang_code, url_path): 284 276 """ url with lang_code and sub page path """ 285 _add_pylucid_request_objects(request)286 287 277 try: 288 278 lang_entry = Language.objects.get(code=url_lang_code) … … 305 295 We redirect to a url with language code. 306 296 """ 307 _add_pylucid_request_objects(request)308 309 297 # redirect to a url with the default language code. 310 298 return _i18n_redirect(request, url_path) -
branches/0.9/pylucid_project/apps/pylucid_update/views.py
r2056 r2071 52 52 out.write("\n______________________________________________________________") 53 53 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(): 55 55 user = old_entry.user 56 56 sha_login_checksum = old_entry.sha_checksum 57 57 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) 60 60 #userprofile.site.add(site) 61 61 if created: … … 63 63 else: 64 64 out.write("UserProfile for user '%s' exist." % user.username) 65 65 66 66 if not userprofile.sha_login_checksum: 67 67 # Add old sha login data, only if not exist. … … 77 77 new_template_name = settings.SITE_TEMPLATE_PREFIX + template.name + ".html" 78 78 new_template, created = Template.objects.get_or_create( 79 name =new_template_name,80 defaults ={79 name=new_template_name, 80 defaults={ 81 81 "content": template.content, 82 82 "creation_date": template.createtime, … … 97 97 for style in Style08.objects.all(): 98 98 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={ 101 101 "description": style.description, 102 102 "content": style.content, … … 124 124 #--------------------------------------------------------------------- 125 125 # create/get Design entry 126 126 127 127 design_key = "%s %s" % (old_page.template.name, old_page.style.name) 128 128 if design_key not in designs: … … 133 133 else: 134 134 new_design_name = "%s + %s" % (old_page.template.name, style_name) 135 135 136 136 design, created = Design.objects.get_or_create( 137 name =new_design_name,138 defaults ={137 name=new_design_name, 138 defaults={ 139 139 "template": templates[old_page.template.name], 140 140 } … … 149 149 assert isinstance(css_file, EditableHtmlHeadFile) 150 150 design.headfiles.add(css_file) 151 151 152 152 colorscheme, created = ColorScheme.objects.get_or_create(name=style_name) 153 153 if created: … … 156 156 else: 157 157 out.write("Use color scheme: %s" % colorscheme.name) 158 158 159 159 design.colorscheme = colorscheme 160 160 design.save() … … 163 163 design = designs[design_key] 164 164 out.write("Use existing Design: %r" % design) 165 165 166 166 #--------------------------------------------------------------------- 167 167 # create/get PageTree entry … … 173 173 174 174 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={ 179 179 "position": old_page.position, 180 180 … … 198 198 199 199 page_dict[old_page.id] = tree_entry 200 200 201 201 #--------------------------------------------------------------------- 202 202 # create/get PageMeta entry 203 203 204 204 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={ 208 208 "name": old_page.name, 209 209 "title": old_page.title, … … 222 222 else: 223 223 out.write("PageMeta entry '%s' - '%s' exist." % (language, tree_entry.slug)) 224 224 225 225 #--------------------------------------------------------------------- 226 226 # create/get PageContent entry 227 227 228 228 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={ 233 233 "content": old_page.content, 234 234 "markup": old_page.markup, … … 277 277 title = "Update PyLucid v0.8 templates" 278 278 out = SimpleStringIO() 279 279 280 280 def replace(content, out, old, new): 281 281 out.write("replace %r with %r" % (old, new)) … … 285 285 content = content.replace(old, new) 286 286 return content 287 288 287 288 289 289 for template in Template.objects.filter(name__istartswith=settings.SITE_TEMPLATE_PREFIX): 290 290 out.write("\n______________________________________________________________") 291 291 out.write("Update Template: '%s'\n" % template.name) 292 292 293 293 content = template.content 294 294 … … 309 309 ) 310 310 } 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) 314 314 # 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 -->") 321 321 content = replace(content, out, 322 322 "{{ PAGE.content }}", … … 329 329 "{{ page_title }}" 330 330 ) 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 337 338 for timestring in ("lastupdatetime", "createtime"): 338 339 # Change time with filter: … … 346 347 '{{ page_%s|date:_("DATETIME_FORMAT") }}' % timestring, 347 348 ) 348 349 content = replace(content, out, "{{ PAGE.", "{{ page_")350 349 350 content = replace(content, out, "{{ PAGE.", "{{ page_") 351 351 352 if "{% lucidTag language %}" not in content: 352 353 # Add language plugin after breadcrumb, if not exist … … 356 357 "<p>{% lucidTag language %}</p>\n" 357 358 ) 358 359 359 360 # TODO: add somthing like: <meta http-equiv="Content-Language" content="en" /> 360 361 361 362 template.content = content 362 363 template.save() 363 364 out.write("Template updated.") 365 364 365 out.write("Template updated.") 366 366 367 context = { 367 368 "title": title, … … 370 371 return render_to_response('pylucid_update/update08result.html', context, 371 372 context_instance=RequestContext(request)) 372 373 373 374 374 375 … … 381 382 title = "Update PyLucid v0.8 styles" 382 383 out = SimpleStringIO() 383 384 384 385 def update_headfile_colorscheme(design, headfile): 385 386 out.write("\nExtract colors from: '%s'" % headfile.filepath) … … 388 389 if colorscheme == None: 389 390 # This design has no color scheme, yet -> create one 390 colorscheme =ColorScheme(name=headfile.filepath)391 colorscheme = ColorScheme(name=headfile.filepath) 391 392 colorscheme.save() 392 393 out.write("Add color scheme %r to %r" % (colorscheme.name, design.name)) 393 394 design.colorscheme = colorscheme 394 395 design.save() 395 396 396 397 out.write("Use color scheme %r" % colorscheme.name) 397 398 398 399 content = headfile.content 399 400 new_content, color_dict = extract_colors(content) … … 405 406 out.write("updated colors: %r" % updated) 406 407 out.write("exists colors: %r" % exists) 407 408 408 409 colorscheme.save() 409 410 410 411 headfile.content = new_content 411 412 headfile.render = True 412 413 headfile.save() 413 414 414 415 415 416 def update_all_design_colorscheme(design): 416 417 headfiles = design.headfiles.all() 417 418 out.write("\nExisting headfiles: %r" % headfiles) 418 419 419 420 for headfile in headfiles: 420 421 if not headfile.filepath.lower().endswith(".css"): … … 422 423 else: 423 424 update_headfile_colorscheme(design, headfile) 424 425 425 426 for design in Design.objects.all(): 426 427 out.write("\n______________________________________________________________") 427 428 out.write("\nUpdate color scheme for design: '%s'" % design.name) 428 429 429 430 update_all_design_colorscheme(design) 430 431 431 432 432 433 # styles = EditableHtmlHeadFile.objects.filter(filepath__istartswith=settings.SITE_TEMPLATE_PREFIX) 433 434 # styles = styles.filter(filepath__iendswith=".css") … … 443 444 # out.write(new_content) 444 445 # out.write(repr(color_dict)) 445 446 446 447 # def replace(content, out, old, new): 447 448 # out.write("replace %r with %r" % (old, new)) … … 469 470 # style.save() 470 471 # out.write("additional styles inserted.") 471 472 472 473 context = { 473 474 "title": title, -
branches/0.9/pylucid_project/settings.py
r2070 r2071 30 30 31 31 import pylucid_project 32 import pylucid_plugins32 from pylucid_project.utils import pylucid_plugins 33 33 34 34 PYLUCID_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__)) 36 36 37 37 #______________________________________________________________________________ … … 39 39 40 40 _path_list = ( 41 PYLUCID_PLUGINS_ROOT,41 # PYLUCID_PLUGINS_ROOT, 42 42 PYLUCID_PROJECT_ROOT, 43 43 os.path.join(PYLUCID_PROJECT_ROOT, "apps") … … 85 85 'django.contrib.auth.middleware.AuthenticationMiddleware', 86 86 87 'pylucid_project.middlewares.PyLucidMiddleware.PyLucidMiddleware', 87 88 'pylucid_project.middlewares.PageMessages.PageMessagesMiddleware', 88 89 … … 93 94 SLOWER_DEV_SERVER_SLEEP = 0.3 # time.sleep() value (in sec.) 94 95 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 ) 96 PYLUCID_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 ) 102 pylucid_plugins.setup_plugins(_PYLUCID_PLUGIN_PACKAGES) 101 103 102 104 TEMPLATE_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"), 110 112 ) 111 113 # Add all templates subdirs from all existing PyLucid plugins 112 TEMPLATE_DIRS += _plugins.get_template_dirs() 114 TEMPLATE_DIRS += pylucid_plugins.PLUGINS.template_dirs 115 #print "settings.TEMPLATE_DIRS:", TEMPLATE_DIRS 113 116 114 117 TEMPLATE_LOADERS = ( … … 161 164 ) 162 165 # Add all existing PyLucid plugins 163 INSTALLED_APPS += _plugins.get_installed_apps()164 #print INSTALLED_APPS166 INSTALLED_APPS += pylucid_plugins.PLUGINS.pkg_list 167 #print "settings.INSTALLED_APPS:", INSTALLED_APPS 165 168 166 169 #http://docs.djangoproject.com/en/dev/ref/settings/#setting-TEST_RUNNER … … 201 204 # Example-1: "./media/" (default) 202 205 # Example-2: "/home/foo/htdocs/media/" 203 MEDIA_ROOT = os.path.join( _BASE_PATH, "media") + "/"206 MEDIA_ROOT = os.path.join(PYLUCID_BASE_PATH, "media") + "/" 204 207 205 208 # URL that handles the media served from MEDIA_ROOT.