Changeset 1126

Show
Ignore:
Timestamp:
06/29/07 08:51:21 (17 months ago)
Author:
JensDiemer
Message:

new: sequencing pages reimplemented ;)

Location:
branches/0.8(django)/PyLucid
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/0.8(django)/PyLucid/models.py

    r1123 r1126  
    3939    position = models.IntegerField( 
    4040        default = 0, 
    41         help_text = "ordering (number between -10 and 10)" 
     41        help_text = "ordering weight for sorting the pages in the menu." 
    4242    ) 
    4343 
  • branches/0.8(django)/PyLucid/plugins_internal/page_admin/internal_pages/sequencing.html

    r1073 r1126  
    1 <h2>Sequencing pages</h2> 
     1<h2>{% trans 'Sequencing pages' %}</h2> 
    22 
    33<p> 
    4   Here you can change the page position by setting the weights.<br /> 
    5   (ascending order) 
     4  {% trans 'Here you can change the page position by setting the weights.' %}<br /> 
     5  ({% trans 'ascending order' %}) 
    66</p> 
    77 
    8 <form method="post" action="{{ url }}" id="sequencing"> 
    9   <table id="sequencing"> 
     8<p> 
     9{% trans 'Switch to a other page level:' %} 
     10{% if has_parents and not use_parent %}<a href="{{ base_url }}parents/">{% endif %} 
     11    &#xAB; {% trans 'parent' %} 
     12{% if has_parents and not use_parent %}</a>{% endif %} 
     13 | 
     14{% if not use_current %}<a href="{{ base_url }}">{% endif %} 
     15    {% trans 'current' %} 
     16{% if not use_current %}</a>{% endif %} 
     17 | 
     18{% if has_childs and not use_child %}<a href="{{ base_url }}childs/">{% endif %} 
     19    {% trans 'child' %} &#xBB; 
     20{% if has_childs and not use_child %}</a>{% endif %} 
     21</p> 
     22 
     23<form method="post" action="." id="sequencing"> 
     24  <table> 
    1025  {% for page in sequencing_data %} 
    11   <tr> 
    12     <td class="name">{{ page.name|escapexml }}</td> 
    13     <td>weight: <strong>{{ page.position }}</strong></td> 
     26  <tr title="{{ page.title }}"> 
     27    <td class="name">{{ page.name|escape }}</td> 
     28    <td>current weight: <strong>{{ page.position }}</strong></td> 
    1429    <td> 
    15       <select name="page_id_{{ page.id }}"> 
     30      <select name="{{ page.id }}"> 
    1631        {% for weight in weights %} 
    17           <option value="{{ weight }}" {% if weight equals page.position %}selected="selected"{% endif %}> 
     32          <option value="{{ weight }}" {% ifequal weight page.position %}selected="selected"{% endifequal %}> 
    1833             {{ weight }} 
    1934          </option> 
  • branches/0.8(django)/PyLucid/plugins_internal/page_admin/page_admin.py

    r1123 r1126  
    436436        return HttpResponse(html) 
    437437 
     438    #___________________________________________________________________________ 
     439 
     440    def _save_sequencing(self, page_data): 
     441        """ 
     442        Save the new position weight for every pages, if changed. 
     443        """ 
     444        no_changes = True 
     445        for page in page_data: 
     446            try: 
     447                page_id = str(page.id) 
     448                #page_id = "Not exists test" 
     449                weight = self.request.POST[page_id] 
     450                #weight = "Not a number test" 
     451                weight = int(weight) 
     452            except (KeyError, ValueError), msg: 
     453                self.page_msg.red(_("Error: Wrong POST data!")) 
     454                if settings.DEBUG: 
     455                    self.page_msg.red("Debug: %s" % msg) 
     456                # abort! 
     457                return 
     458 
     459            if page.position == weight: 
     460                # No change needed for this page 
     461                continue 
     462 
     463            # Set new position weight and save: 
     464            page.position = weight 
     465            page.save() 
     466 
     467            no_changes = False 
     468            self.page_msg.green( 
     469                _("Set position weight %s for page '%s', ok.") % ( 
     470                    weight, page.name 
     471                ) 
     472            ) 
     473 
     474        if no_changes: 
     475            # Give feedback for the user, if nothing to do... 
     476            self.page_msg.green(_("Nothing to change ;)")) 
     477 
     478 
     479    def _get_sequence_data(self, url_args): 
     480        """ 
     481        returned the pages and the "use"-mode. 
     482        Based on the url, the pages are from the "parent", "current", "child" 
     483        level. 
     484        """ 
     485        # Start with "current" level. Only if the url starts with "parent" or 
     486        # "child" change the level. 
     487        use = "current" 
     488        if url_args != None: 
     489            if url_args.startswith("parent"): 
     490                use = "parent" 
     491                parent_page = Page.objects.get( 
     492                    id=self.current_page.parent.id 
     493                ) 
     494                parent_filter = parent_page.parent 
     495            elif url_args.startswith("child"): 
     496                use = "child" 
     497                parent_filter = self.current_page.id 
     498 
     499        if use == "current": 
     500            # "url_args == None" or the url is not well-formed: It doesn't 
     501            # starts with "parent" or "child" 
     502            parent_filter = self.current_page.parent 
     503 
     504        # Change a "parent__exact=None" query to "parent__isnull=True" 
     505        # see: http://www.djangoproject.com/documentation/db-api/#isnull 
     506        if parent_filter == None: 
     507            filter_kwargs = {"parent__isnull": True} 
     508        else: 
     509            filter_kwargs = {"parent": parent_filter} 
     510 
     511        page_data = Page.objects.filter(**filter_kwargs) 
     512 
     513        return use, page_data 
     514 
     515 
     516    def sequencing(self, url_args=None): 
     517        """ 
     518        Set the position weight of the cms page to change the correct order. 
     519        TODO: Save the weight range in the preferences 
     520        """ 
     521        use, page_data = self._get_sequence_data(url_args) 
     522 
     523        if self.request.method == 'POST': 
     524            # Save new position weight 
     525            self._save_sequencing(page_data) 
     526 
     527        # Order the pages *after* a sended POST data processed. 
     528        page_data = page_data.order_by("position") 
     529 
     530        childs = Page.objects.filter(parent=self.current_page.id).count() 
     531        has_childs = childs != 0 
     532 
     533        parents = Page.objects.filter(parent=self.current_page.parent).count() 
     534        has_parents = parents != 0 
     535 
     536#        self.page_msg("url_args:", url_args) 
     537#        self.page_msg("use:", use) 
     538#        self.page_msg("filter_kwargs:", filter_kwargs) 
     539#        self.page_msg("has_childs:", has_childs, " - has_parents:", has_parents) 
     540 
     541        context = { 
     542            "sequencing_data": page_data, 
     543            "weights": range(-10, 10), 
     544 
     545            "base_url": self.URLs.methodLink("sequencing"), 
     546 
     547            "has_childs": has_childs, 
     548            "has_parents": has_parents, 
     549        } 
     550        context["use_%s" % use] = True 
     551 
     552        self._render_template("sequencing", context)#, debug=True) 
     553 
    438554 
    439555class DeletePageError(Exception): 
  • branches/0.8(django)/PyLucid/plugins_internal/page_admin/page_admin_cfg.py

    r1103 r1126  
    77__url__                 = "http://www.PyLucid.org" 
    88__description__         = "edit a CMS page" 
    9 __long_description__    = """Edit a normal CMS pages""" 
     9__long_description__    = """ 
     10-Edit/delete existing pages. 
     11-Create new pages. 
     12-Setup the page order in the menu. 
     13""" 
    1014__can_deinstall__ = False 
    1115 
     
    2832    "new_page"          : global_rights, 
    2933    "delete_page"       : global_rights, 
    30     "preview"           : global_rights, 
    31     "save"              : global_rights, 
    32     "encode_from_db"    : global_rights, 
    3334    "tinyTextile_help" : { 
    3435        "must_login"    : False, 
     
    6364        }, 
    6465    }, 
    65     "save_positions" : global_rights, 
    6666    "tag_list": { 
    6767        "must_login"    : True,