Changeset 2057

Show
Ignore:
Timestamp:
06/23/09 08:39:15 (9 months ago)
Author:
JensDiemer
Message:

color names can now be renamed: Rename the placeholder in every headfile, too. ;)

Location:
branches/0.9/pylucid_project/apps/pylucid
Files:
2 modified

Legend:

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

    r2055 r2057  
    105105#----------------------------------------------------------------------------- 
    106106 
     107#class ColorAdmin(VersionAdmin): 
     108#    list_display = ("id", "name","value") 
     109#admin.site.register(models.Color, ColorAdmin) 
     110 
    107111class ColorInline(admin.TabularInline): 
    108112    model = models.Color 
  • branches/0.9/pylucid_project/apps/pylucid/models.py

    r2055 r2057  
    490490    value = ColorField(help_text="CSS hex color value.") 
    491491     
     492    def save(self, *args, **kwargs): 
     493        new_name = self.name 
     494        old_name = Color.objects.get(id=self.id).name 
     495        if new_name != old_name: 
     496            # Color name has been changed -> Rename template placeholder in every headfile, too. 
     497            designs = Design.objects.all().filter(colorscheme=self.colorscheme) 
     498            for design in designs: 
     499                headfiles = design.headfiles.all() 
     500                for headfile in headfiles: 
     501                    if headfile.render != True: # File used no color placeholder 
     502                        continue 
     503 
     504                    old_content = headfile.content 
     505                    # FIXME: Use flexibler regexp. for this: 
     506                    new_content = old_content.replace("{{ %s }}" % old_name, "{{ %s }}" % new_name) 
     507                    if old_content == new_content: 
     508                        # content not changed?!? 
     509                        user_message_or_warn( 
     510                            "Color '{{ %s }}' not exist in headfile %r" % (old_name, headfile) 
     511                        ) 
     512                        continue 
     513                     
     514                    if settings.DEBUG: 
     515                        user_message_or_warn( 
     516                            "change color name from '%s' to '%s' in %r" % (old_name, new_name, headfile) 
     517                        ) 
     518                    headfile.content = new_content 
     519                    headfile.save() 
     520 
     521        return super(Color, self).save(*args, **kwargs) 
     522     
    492523    def __unicode__(self): 
    493524        sites = [site.name for site in self.site.all()] 
    494525        return u"Color '%s' (%s, on sites: %r)" % (self.name, self.colorscheme, sites) 
     526     
     527    class Meta: 
     528        unique_together=(("colorscheme", "name"),) 
     529        ordering = ("colorscheme", "name") 
    495530 
    496531#------------------------------------------------------------------------------ 
     
    633668    def save_all_color_cachfiles(self): 
    634669        """ this headfile was changed: resave all cache files in every existing colors""" 
    635         designs = Design.objects.all().filter(colorscheme=colorscheme) 
    636         for design in designs: 
    637             print design 
    638             headfiles = design.headfiles.all() 
    639             for headfile in headfiles: 
    640                 print headfile 
    641                 headfile.save_cache_file(colorscheme) 
     670        warnings.warn("TODO") 
     671#        designs = Design.objects.all().filter(colorscheme=colorscheme) 
     672#        for design in designs: 
     673#            print design 
     674#            headfiles = design.headfiles.all() 
     675#            for headfile in headfiles: 
     676#                print headfile 
     677#                headfile.save_cache_file(colorscheme) 
    642678 
    643679    def get_absolute_url(self, colorscheme): 
     
    678714    def __unicode__(self): 
    679715        sites = [site.name for site in self.site.all()] 
    680         return u"EditableHtmlHeadFile '%s' (on sites: %r)" % (self.filepath, sites) 
     716        return u"'%s' (on sites: %r)" % (self.filepath, sites) 
    681717 
    682718    class Meta: