sorting links
This commit is contained in:
parent
c1b8f5f361
commit
772d32876d
|
@ -86,6 +86,21 @@ class LinksDirectory(Directory):
|
|||
except:
|
||||
links = []
|
||||
|
||||
for l in links:
|
||||
if not hasattr(l, str('position')):
|
||||
l.position = None
|
||||
|
||||
def cmp_position(x, y):
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
links.sort(cmp_position)
|
||||
|
||||
|
||||
'<ul class="biglist" id="links-list">'
|
||||
for l in links:
|
||||
link_id = l.id
|
||||
|
@ -117,7 +132,13 @@ Sortable.create('links-list', {dropOnEmpty:true,constraint:false,
|
|||
def update_order(self):
|
||||
request = get_request()
|
||||
new_order = request.form['links-list[]']
|
||||
print new_order
|
||||
links = FormDef.get_by_urlname('liens').data_class().select()
|
||||
dict = {}
|
||||
for l in links:
|
||||
dict[str(l.id)] = l
|
||||
for i, o in enumerate(new_order):
|
||||
dict[o].position = i + 1
|
||||
dict[o].store()
|
||||
return 'ok'
|
||||
|
||||
|
||||
|
|
|
@ -209,18 +209,31 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
try:
|
||||
links = FormDef.get_by_urlname('liens').data_class().select()
|
||||
except KeyError:
|
||||
links = None
|
||||
return
|
||||
|
||||
if links:
|
||||
'<div id="links">'
|
||||
'<h3>%s</h3>' % _('Useful links')
|
||||
'<ul>'
|
||||
for link in links:
|
||||
url = link.get_field_value('URL')
|
||||
name = link.get_field_value('Titre')
|
||||
'<li><a href="%s">%s</a></li>' % (url, name)
|
||||
'</ul>'
|
||||
'</div>'
|
||||
for l in links:
|
||||
if not hasattr(l, str('position')):
|
||||
l.position = None
|
||||
|
||||
def cmp_position(x, y):
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
links.sort(cmp_position)
|
||||
|
||||
'<div id="links">'
|
||||
'<h3>%s</h3>' % _('Useful links')
|
||||
'<ul>'
|
||||
for link in links:
|
||||
url = link.get_field_value('URL')
|
||||
name = link.get_field_value('Titre')
|
||||
'<li><a href="%s">%s</a></li>' % (url, name)
|
||||
'</ul>'
|
||||
'</div>'
|
||||
|
||||
|
||||
def announces [html] (self):
|
||||
|
|
Reference in New Issue