""" open/dulcinea/lib/ui/item.qpy """ from dulcinea.attachable import Attachable from dulcinea.ui.lib.search import highlight_keywords from qp.fill.form import Form from qp.fill.html import href, url_quote from qp.pub.common import get_user, get_request, get_response, redirect from qp.pub.common import header, footer def delete_item_form(item, item_db): """(item : Item, item_db : ItemFolder) """ form = Form() form.add_submit("delete", "Delete") form.add_submit("cancel", "Cancel") if form.get("cancel"): redirect(".") def render:xml(title): header(title=title) '

Delete item "%s"?

' % item.get_title() form.render() footer(title) if not form.is_submitted(): return render("Delete %s" % item.get_title()) item_db.remove(item) redirect("..") def format_action_links:xml(item): '' href('edit', '[Edit]') ' ' href('delete', '[Delete]') if isinstance(item, Attachable): ' ' href('file/', '[Files]') def format_item_title:xml(item, keywords=None): if keywords: title = highlight_keywords(item.get_title(), keywords) querystring = '?keywords=%s' % url_quote(keywords) else: title = item.get_title() querystring = '' href("%s%s" % (item.get_local_url(), querystring), title) if not item.is_approved(): ' ' '(Unapproved)' def sort_by_timestamp(L): # sort_by_timestamp(L:list) # Sort the provided list of objects by timestamp, mutating the list that's # passed in. def get_timestamp(x): return x.get_timestamp() L.sort(key=get_timestamp) def list_dated_items:xml(items, format_html): #(items : [Items]) # # Category the items into regions posted on the same day last_date = None categorized_list = [] sort_by_timestamp(items) for item in items: if item.get_timestamp().date() != last_date: # Different date? If so, create a new sublist categorized_list.append( [] ) last_date = item.get_timestamp().date() categorized_list[-1].append(item) # Now that we've categorized them, display them. for day_list in categorized_list: '

%s

' % day_list[0].get_timestamp().date() "" def list_to_oldest_date:xml(what, item_db, interval, oldest_date, format_html): items = item_db.get_to_oldest_date(oldest_date, include_unapproved=get_user().is_admin()) if oldest_date is not None: "

%s postings for %s.

" % (what.capitalize(), interval) list_dated_items(items, format_html) def display_rss:xml(item_db, format_item_rss, site_preamble): items = item_db.get_recent_items(count=10) get_response().set_content_type(str('text/xml'), str('utf-8')) """ """ site_preamble servername = get_request().get_server() for item in items: format_item_rss(item, servername) ""