예제 #1
0
 def list(self, **params):
     coll = get_lockto_coll()
     if coll is not None:
         redirect(url("coll-view", id=coll.id))
     groups = [CollGroup(coll.id, coll.title, [coll.id])
               for coll in Collection.objects if not coll.parents]
     groupid = getparam('groupid', '')
     filtered_groups = filter(lambda group: group.id == groupid, groups)
     if len(filtered_groups) > 0:
         currgroup = filtered_groups[0]
     elif len(groups) > 0:
         currgroup = groups[0]
     else:
         currgroup = None
     context = dict(groups=groups, currgroup=currgroup)
     return render("colls-list.html", context)
예제 #2
0
    def _get_export_records(self, stash, record_id, issearch, coll, incsubs):
        """Returns a search queryset, and a description of the export."""

        # record_id is set to export a single record.
        if record_id is not None:
            search = SearchCollection.doc_type('record').field.id == record_id
            return search, "record with id %s" % record_id, None

        # if issearch is set, export the search results.
        if issearch is not None:
            params = SearchParams(stash)
            search_obj = Search(params)
            if not search_obj.validate():
                redirect(url("search", **stash))
            desc = "%d records found by search.\n" % search_obj.match_count
            return search_obj.query, desc + search_obj.query_desc, None

        # FIXME - allow selected records here.

        # If we've got no collection set, but have a lock, set the collection
        # to the locked one.
        lockedto = get_lockto_coll()
        if lockedto is not None and coll is None:
            coll = lockedto.id

        # coll is set to export a whole collection.
        if coll is not None:
            coll_obj = get_or_404(Collection, coll)
            search = coll_obj.items_from_search(incsubs=incsubs)

            desc = "all %d records from collection %s" % (
                len(search),
                coll_obj.title
            )
            if incsubs:
                desc += " (including subcollections)"
            return search, desc, coll_obj

        # If none of the above are set, export everything.
        return SearchCollection.doc_type('record').all()[:], "all records", None