Changeset 2052
- Timestamp:
- 06/19/09 15:57:40 (9 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 2 added
- 9 modified
-
apps/pylucid/admin.py (modified) (2 diffs)
-
apps/pylucid/fields.py (added)
-
apps/pylucid/models.py (modified) (14 diffs)
-
apps/pylucid/system/auto_model_info.py (modified) (2 diffs)
-
apps/pylucid/system/css_color_utils.py (added)
-
apps/pylucid_update/forms.py (modified) (2 diffs)
-
apps/pylucid_update/templates/pylucid_update/menu.html (modified) (1 diff)
-
apps/pylucid_update/templates/pylucid_update/update08.html (modified) (1 diff)
-
apps/pylucid_update/urls.py (modified) (1 diff)
-
apps/pylucid_update/views.py (modified) (12 diffs)
-
pylucid_plugins/page_admin/templates/page_admin/edit_page_form.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/apps/pylucid/admin.py
r2040 r2052 103 103 admin.site.register(models.PluginPage, PluginPageAdmin) 104 104 105 #----------------------------------------------------------------------------- 106 107 class ColorInline(admin.TabularInline): 108 model = models.Color 109 110 class ColorSchemeAdmin(VersionAdmin): 111 list_display = ("name",) 112 list_display_links = ("name",) 113 search_fields = ("name",) 114 inlines = [ 115 ColorInline, 116 ] 117 118 admin.site.register(models.ColorScheme, ColorSchemeAdmin) 119 120 105 121 106 122 class DesignAdmin(VersionAdmin): 107 list_display = ("name", "template", " lastupdatetime", "lastupdateby")123 list_display = ("name", "template", "colorscheme", "lastupdatetime", "lastupdateby") 108 124 list_display_links = ("name",) 109 list_filter = ("site", "template", "c reateby", "lastupdateby")110 search_fields = ("name", "template" )125 list_filter = ("site", "template", "colorscheme", "createby", "lastupdateby") 126 search_fields = ("name", "template", "colorscheme") 111 127 112 128 admin.site.register(models.Design, DesignAdmin) … … 120 136 admin.site.register(models.EditableHtmlHeadFile, EditableHtmlHeadFileAdmin) 121 137 138 #----------------------------------------------------------------------------- 122 139 123 140 class UserProfileAdmin(VersionAdmin): -
branches/0.9/pylucid_project/apps/pylucid/models.py
r2048 r2052 29 29 from django.db import models 30 30 from django.conf import settings 31 from django.core import exceptions 31 32 from django.db.models import signals 32 33 from django.core.urlresolvers import reverse … … 41 42 from pylucid_project.utils import crypt 42 43 43 from pylucid.system.auto_model_info import UpdateInfoBaseModel 44 from pylucid.system.auto_model_info import UpdateInfoBaseModel,AutoSiteM2M 45 from pylucid.shortcuts import user_message_or_warn 46 from pylucid.fields import ColorField 44 47 from pylucid.system import headfile 45 from pylucid.shortcuts import user_message_or_warn46 48 47 49 … … 433 435 ordering = ("page", "lang") 434 436 437 #------------------------------------------------------------------------------ 438 439 class ColorScheme(AutoSiteM2M, UpdateInfoBaseModel): 440 """ 441 inherited attributes from AutoSiteM2M: 442 site -> ManyToManyField to Site 443 on_site -> sites.managers.CurrentSiteManager instance 444 """ 445 name = models.CharField(max_length=255, help_text="The name of this color scheme.") 446 447 def update(self, colors): 448 assert isinstance(colors, dict) 449 new = [] 450 updated = [] 451 exists = [] 452 for name, value in colors.iteritems(): 453 color, created = Color.objects.get_or_create( 454 colorscheme=self, name=name, 455 defaults={"colorscheme":self, "name":name, "value":value} 456 ) 457 if created: 458 new.append(color) 459 elif color.value != value: 460 color.value = value 461 updated.append(color) 462 color.save() 463 else: 464 exists.append(color) 465 return new, updated, exists 466 467 def __unicode__(self): 468 sites = [site.name for site in self.site.all()] 469 return u"ColorScheme '%s' (on sites: %r)" % (self.name, sites) 470 471 472 class Color(AutoSiteM2M, UpdateInfoBaseModel): 473 """ 474 inherited attributes from AutoSiteM2M: 475 site -> ManyToManyField to Site 476 on_site -> sites.managers.CurrentSiteManager instance 477 """ 478 colorscheme = models.ForeignKey(ColorScheme) 479 name = models.CharField(max_length=128, 480 help_text="Name if this color (e.g. main_color, head_background)" 481 ) 482 value = ColorField(help_text="CSS hex color value.") 483 484 def __unicode__(self): 485 sites = [site.name for site in self.site.all()] 486 return u"Color '%s' (%s, on sites: %r)" % (self.name, self.colorscheme, sites) 435 487 436 488 #------------------------------------------------------------------------------ … … 439 491 pass 440 492 441 class Design( UpdateInfoBaseModel):493 class Design(AutoSiteM2M, UpdateInfoBaseModel): 442 494 """ 443 495 Page design: template + CSS/JS files 496 497 inherited attributes from AutoSiteM2M: 498 site -> ManyToManyField to Site 499 on_site -> sites.managers.CurrentSiteManager instance 444 500 445 501 inherited attributes from UpdateInfoBaseModel: … … 451 507 objects = DesignManager() 452 508 453 site = models.ManyToManyField(Site, default=[settings.SITE_ID])454 on_site = CurrentSiteManager()455 456 509 name = models.CharField(unique=True, max_length=150, help_text="Name of this design combination",) 457 510 template = models.CharField(max_length=128, help_text="filename of the used template for this page") … … 459 512 help_text="Static files (stylesheet/javascript) for this page, included in html head via link tag" 460 513 ) 514 colorscheme = models.ForeignKey(ColorScheme, null=True, blank=True) 461 515 462 516 def save(self, *args, **kwargs): … … 467 521 468 522 def __unicode__(self): 469 return u"Page design '%s'" % self.name 523 sites = [site.name for site in self.site.all()] 524 return u"Page design '%s' (on sites: %r)" % (self.name, sites) 470 525 471 526 class Meta: … … 484 539 485 540 486 class EditableHtmlHeadFile( UpdateInfoBaseModel):541 class EditableHtmlHeadFile(AutoSiteM2M, UpdateInfoBaseModel): 487 542 """ 488 543 Storage for editable static text files, e.g.: stylesheet / javascript. 544 545 inherited attributes from AutoSiteM2M: 546 site -> ManyToManyField to Site 547 on_site -> sites.managers.CurrentSiteManager instance 489 548 490 549 inherited attributes from UpdateInfoBaseModel: … … 496 555 objects = EditableHtmlHeadFileManager() 497 556 498 site = models.ManyToManyField(Site, default=[settings.SITE_ID])499 on_site = CurrentSiteManager()500 501 557 filepath = models.CharField(max_length=256) 502 558 mimetype = models.CharField(max_length=64) 503 559 html_attributes = models.CharField(max_length=256, null=False, blank=True, 560 # TODO: Use this! 504 561 help_text='Additional html tag attributes (CSS example: media="screen")' 562 ) 563 render = models.BooleanField(default = False, 564 help_text="Are there CSS ColorScheme entries in the content?" 505 565 ) 506 566 description = models.TextField(null=True, blank=True) … … 588 648 589 649 def __unicode__(self): 590 return u"EditableHtmlHeadFile '%s'" % self.filepath 650 sites = [site.name for site in self.site.all()] 651 return u"EditableHtmlHeadFile '%s' (on sites: %r)" % (self.filepath, sites) 591 652 592 653 class Meta: … … 597 658 598 659 599 class UserProfile( UpdateInfoBaseModel):660 class UserProfile(AutoSiteM2M, UpdateInfoBaseModel): 600 661 """ 601 662 Stores additional information about PyLucid users … … 603 664 604 665 Created via post_save signal, if a new user created. 666 667 inherited attributes from AutoSiteM2M: 668 site -> ManyToManyField to Site 669 on_site -> sites.managers.CurrentSiteManager instance 605 670 """ 606 671 user = models.ForeignKey(User, unique=True, related_name="%(class)s_user") … … 613 678 ) 614 679 615 site = models.ManyToManyField(Site, 616 help_text="User can access only these sites." 617 ) 680 # TODO: Overwrite help_text: 681 # site = models.ManyToManyField(Site, 682 # help_text="User can access only these sites." 683 # ) 618 684 619 685 def set_sha_login_password(self, raw_password): … … 650 716 if created: 651 717 user_message_or_warn("UserProfile entry for user '%s' created." % user) 652 653 if not user.is_superuser: # Info: superuser can automaticly access all sites654 site = Site.objects.get_current()655 userprofile.site.add(site)656 user_message_or_warn("Add site '%s' to '%s' UserProfile." % (site.name, user))718 # 719 # if not user.is_superuser: # Info: superuser can automaticly access all sites 720 # site = Site.objects.get_current() 721 # userprofile.site.add(site) 722 # user_message_or_warn("Add site '%s' to '%s' UserProfile." % (site.name, user)) 657 723 658 724 signals.post_save.connect(create_user_profile, sender=User) -
branches/0.9/pylucid_project/apps/pylucid/system/auto_model_info.py
r2040 r2052 22 22 23 23 from django.db import models 24 from django.conf import settings 24 25 from django.contrib import admin 25 26 from django.http import HttpRequest 26 27 from django.contrib.auth.models import User 28 from django.contrib.sites.models import Site 27 29 from django.db import transaction, IntegrityError 30 from pylucid.shortcuts import user_message_or_warn 31 from django.contrib.sites.managers import CurrentSiteManager 28 32 29 33 from django_tools.middlewares import ThreadLocal 34 35 36 class AutoSiteM2M(models.Model): 37 """ 38 Add site and on_site to model, and add at least the current site in save method. 39 """ 40 site = models.ManyToManyField(Site) 41 on_site = CurrentSiteManager() 42 43 def save(self, *args, **kwargs): 44 """ Automatic current site, if not exist. """ 45 if self.pk==None: 46 # instance needs to have a primary key value before a many-to-many relationship can be used. 47 super(AutoSiteM2M, self).save(*args, **kwargs) 48 49 if self.site.count()==0: 50 site = Site.objects.get_current() 51 if settings.DEBUG: 52 user_message_or_warn("Automatic add site '%s' to %r" % (site.name, self)) 53 self.site.add(site) 54 55 super(AutoSiteM2M, self).save(*args, **kwargs) 56 57 class Meta: 58 abstract = True 30 59 31 60 … … 35 64 The createby and lastupdateby ForeignKey would be automaticly updated. This needs the 36 65 request object as the first argument in the save method. 37 38 Important: Every own objects manager should be inherit from UpdateInfoBaseModelManager!39 """66 """ 67 objects = models.Manager() 68 40 69 createtime = models.DateTimeField(auto_now_add=True, help_text="Create time",) 41 70 lastupdatetime = models.DateTimeField(auto_now=True, help_text="Time of the last change.",) -
branches/0.9/pylucid_project/apps/pylucid_update/forms.py
r1875 r2052 2 2 3 3 from django import forms 4 from django.contrib.sites.models import Site5 4 from django.utils.translation import ugettext as _ 6 5 … … 8 7 9 8 class UpdateForm(forms.Form): 10 site = forms.ModelChoiceField(11 queryset=Site.objects.all(),12 help_text=_("Select the site for the existing pages."),13 )14 9 language = forms.ModelChoiceField( 15 10 queryset=Language.objects.all(), -
branches/0.9/pylucid_project/apps/pylucid_update/templates/pylucid_update/menu.html
r1931 r2052 4 4 {% block content %} 5 5 <!-- view_content block --> 6 <p>Update on site: <strong>{{ site }}</strong></p> 6 7 Please select: 7 8 <ol> -
branches/0.9/pylucid_project/apps/pylucid_update/templates/pylucid_update/update08.html
r1931 r2052 6 6 <fieldset><legend>update</legend> 7 7 <p>TODO: Insert info text here ;)</p> 8 <p>Update on site: <strong>{{ site }}</strong></p> 8 9 Please select: 9 10 <form method="post" action="{{ url }}"> -
branches/0.9/pylucid_project/apps/pylucid_update/urls.py
r2045 r2052 2 2 3 3 """ 4 Generate dynamicly urls based on the database tree4 urls for update section 5 5 """ 6 6 -
branches/0.9/pylucid_project/apps/pylucid_update/views.py
r2050 r2052 15 15 """ 16 16 17 import re 17 18 import posixpath 18 19 … … 20 21 from django.template import RequestContext 21 22 from django.core.urlresolvers import reverse 23 from django.contrib.sites.models import Site 22 24 from django.shortcuts import render_to_response 23 25 from django.template.loader import find_template_source … … 26 28 27 29 from pylucid_project.utils.SimpleStringIO import SimpleStringIO 28 from pylucid _project.apps.pylucid.models import PageTree, PageMeta, PageContent, Design, \29 EditableHtmlHeadFile,UserProfile30 from pylucid.models import PageTree, PageMeta, PageContent, ColorScheme, Design, EditableHtmlHeadFile, \ 31 UserProfile 30 32 from pylucid_project.apps.pylucid_update.models import Page08, Template08, Style08, JS_LoginData08 33 from pylucid.system.css_color_utils import filter_content, extract_colors 31 34 from pylucid_project.apps.pylucid_update.forms import UpdateForm 32 35 from pylucid.fields import CSS_VALUE_RE 33 36 34 37 … … 37 40 context = { 38 41 "title": "menu", 42 "site": Site.objects.get_current() 39 43 } 40 44 return render_to_response('pylucid_update/menu.html', context, context_instance=RequestContext(request)) 41 45 42 46 43 def _do_update(request, site,language):47 def _do_update(request, language): 44 48 out = SimpleStringIO() 49 site = Site.objects.get_current() 45 50 out.write("Starting update and move v0.8 data into v0.9 (on site: %s)" % site) 46 51 … … 53 58 54 59 userprofile, created = UserProfile.objects.get_or_create(user = user) 55 userprofile.site.add(site)60 #userprofile.site.add(site) 56 61 if created: 57 62 out.write("UserProfile for user '%s' created." % user.username) … … 100 105 } 101 106 ) 102 new_staticfile.site.add(site)103 107 cssfiles[style.name] = new_staticfile 104 108 if created: … … 123 127 design_key = "%s %s" % (old_page.template.name, old_page.style.name) 124 128 if design_key not in designs: 129 style_name = old_page.style.name 125 130 # The template/style combination was not created, yet. 126 if old_page.template.name == old_page.style.name:131 if old_page.template.name == style_name: 127 132 new_design_name = old_page.template.name 128 133 else: 129 new_design_name = "%s + %s" % (old_page.template.name, old_page.style.name)134 new_design_name = "%s + %s" % (old_page.template.name, style_name) 130 135 131 136 design, created = Design.objects.get_or_create( … … 135 140 } 136 141 ) 137 design.site.add(site)138 142 if created: 139 # Add old page css file140 design.headfiles.add(cssfiles[old_page.style.name])141 143 out.write("New design created: %s" % new_design_name) 142 144 else: 145 out.write("Use existing Design: %r" % design) 146 147 # Add old page css file 148 css_file = cssfiles[style_name] # EditableHtmlHeadFile instance 149 assert isinstance(css_file, EditableHtmlHeadFile) 150 design.headfiles.add(css_file) 151 152 colorscheme, created = ColorScheme.objects.get_or_create(name=style_name) 153 if created: 154 out.write("Use new color scheme: %s" % colorscheme.name) 155 out.write("Colors can be extracted later.") 156 else: 157 out.write("Use color scheme: %s" % colorscheme.name) 158 159 design.colorscheme = colorscheme 160 design.save() 143 161 designs[design_key] = design 144 162 else: 145 163 design = designs[design_key] 164 out.write("Use existing Design: %r" % design) 146 165 147 166 #--------------------------------------------------------------------- … … 240 259 form = UpdateForm(request.POST) 241 260 if form.is_valid(): 242 site = form.cleaned_data["site"]243 261 language = form.cleaned_data["language"] 244 245 return _do_update(request, site, language) 262 return _do_update(request, language) 246 263 else: 247 264 form = UpdateForm() … … 250 267 "title": "update data from PyLucid v0.8 to v0.9", 251 268 "url": reverse("PyLucidUpdate-update08"), 269 "site": Site.objects.get_current(), 252 270 "form": form, 253 271 } … … 355 373 356 374 375 357 376 def update08styles(request): 358 377 """ … … 363 382 out = SimpleStringIO() 364 383 365 def replace(content, out, old, new): 366 out.write("replace %r with %r" % (old, new)) 367 if not old in content: 368 out.write("String not found. Updated already?") 369 else: 370 content = content.replace(old, new) 371 return content 372 373 # Get the file content via django template loader: 374 additional_styles, origin = find_template_source("pylucid_update/additional_styles.css") 375 376 styles = EditableHtmlHeadFile.objects.filter(filepath__istartswith=settings.SITE_TEMPLATE_PREFIX) 377 styles = styles.filter(filepath__iendswith=".css") 378 for style in styles: 384 def update_headfile_colorscheme(design, headfile): 385 out.write("\nExtract colors from: '%s'" % headfile.filepath) 386 387 colorscheme = design.colorscheme 388 if colorscheme == None: 389 # This design has no color scheme, yet -> create one 390 colorscheme=ColorScheme(name=headfile.filepath) 391 # colorscheme.site.add(site = Site.objects.get_current()) # FIXME ?!? 392 colorscheme.save() 393 out.write("Add color scheme %r to %r" % (colorscheme.name, design.name)) 394 design.colorscheme = colorscheme 395 design.save() 396 397 out.write("Use color scheme %r" % colorscheme.name) 398 399 content = headfile.content 400 new_content, color_dict = extract_colors(content) 401 out.write(repr(new_content)) 402 out.write(repr(color_dict)) 403 404 created, updated, exists = colorscheme.update(color_dict) 405 out.write("created colors: %r" % created) 406 out.write("updated colors: %r" % updated) 407 out.write("exists colors: %r" % exists) 408 409 colorscheme.save() 410 411 headfile.content = new_content 412 headfile.save() 413 414 415 def update_all_design_colorscheme(design): 416 headfiles = design.headfiles.all() 417 out.write("\nExisting headfiles: %r" % headfiles) 418 419 for headfile in headfiles: 420 if not headfile.filepath.lower().endswith(".css"): 421 out.write("Skip headfile: %r" % headfile) 422 else: 423 update_headfile_colorscheme(design, headfile) 424 425 for design in Design.objects.all(): 379 426 out.write("\n______________________________________________________________") 380 out.write("\nUpdate Style: '%s'" % style.filepath) 381 382 content = style.content 383 if additional_styles in content: 384 out.write("additional styles allready inserted.") 385 else: 386 content = additional_styles + content 387 style.content = content 388 style.save() 389 out.write("additional styles inserted.") 427 out.write("\nUpdate color scheme for design: '%s'" % design.name) 428 429 update_all_design_colorscheme(design) 430 431 432 # styles = EditableHtmlHeadFile.objects.filter(filepath__istartswith=settings.SITE_TEMPLATE_PREFIX) 433 # styles = styles.filter(filepath__iendswith=".css") 434 # for style in styles: 435 # out.write("\n______________________________________________________________") 436 # out.write("\nUpdate Style: '%s'" % style.filepath) 437 # 438 # content = style.content 439 # filtered_content = filter_content(content) # Skip all pygments styles 440 # out.write(filtered_content) 441 # 442 # new_content, color_dict = extract_colors(content) 443 # out.write(new_content) 444 # out.write(repr(color_dict)) 445 446 # def replace(content, out, old, new): 447 # out.write("replace %r with %r" % (old, new)) 448 # if not old in content: 449 # out.write("String not found. Updated already?") 450 # else: 451 # content = content.replace(old, new) 452 # return content 453 # 454 # # Get the file content via django template loader: 455 # additional_styles, origin = find_template_source("pylucid_update/additional_styles.css") 456 # 457 # styles = EditableHtmlHeadFile.objects.filter(filepath__istartswith=settings.SITE_TEMPLATE_PREFIX) 458 # styles = styles.filter(filepath__iendswith=".css") 459 # for style in styles: 460 # out.write("\n______________________________________________________________") 461 # out.write("\nUpdate Style: '%s'" % style.filepath) 462 # 463 # content = style.content 464 # if additional_styles in content: 465 # out.write("additional styles allready inserted.") 466 # else: 467 # content = additional_styles + content 468 # style.content = content 469 # style.save() 470 # out.write("additional styles inserted.") 390 471 391 472 context = { -
branches/0.9/pylucid_project/pylucid_plugins/page_admin/templates/page_admin/edit_page_form.html
r2037 r2052 9 9 $("#preview_fieldset").hide(); 10 10 11 // from media/PyLucid/pylucid_js_tools.js 11 12 pylucid_ajax_form_view('#edit_page_form'); 12 13