Example #1
0
    def create(self, **params):
        context = {}

        if cherrypy.request.method == "POST":
            # FIXME - check csrf token
            title = params.get('newcoll_title', u'').strip()
            parents = coll_parents_from_request()
            if getparam('create'):
                if title:
                    id = create_collection(title, parents)
                    gonext()
                    redirect(url("colls-list", id=id))
                else:
                    context['error'] = "You must set a title for the collection"
        else:
            parents = []

        allowable_parents = set(
            c.id for c in Collection.objects
        )

        context.update(dict(
            parents = tuple(enumerate(parents)),
            allowable_parents = sorted(allowable_parents),
            collections = Collection.objects,
        ))

        return render("coll-new.html", context)
Example #2
0
    def _check_delete(self, id, page):
        params = cherrypy.request.params
        if params.get('delete', '') != '':
            tmpl = get_or_404(Template, id)
            context = dict(tmpl=tmpl, page=page)
            return render("tmpl-delete-confirm.html", context)

        if cherrypy.request.method == "POST":
            if params.get('delete_conf', '') != '':
                try:
                    Template.objects.remove(id)
                    Template.objects.flush()
                except KeyError:
                    raise cherrypy.HTTPError(404)
                gonext()
                redirect(url("tmpls-list"))
Example #3
0
    def delete(self, id, **params):
        coll = get_or_404(Collection, id)
        if cherrypy.request.method == "POST":
            # FIXME - check csrf token
            if id:
                if params.get('delete_conf', '') == '':
                    redirect(url("colls-list"))

                coll = get_or_404(Collection, id)

                # Remove the collection's parents
                coll.set_parents(())
                Collection.objects.set(coll)

                # Remove the collection from its childrens parent lists.
                child_colls = coll.children
                for child in child_colls:
                    cparents = set(child.parents)
                    cparents.remove(id)
                    child.set_parents(cparents)
                    Collection.objects.set(child)

                # Iterate through the records in the collection, and remove the
                # collection from them.
                SearchCollection.checkpoint().wait()
                for record in SearchCollection.doc_type('record') \
                   .field.coll.is_in(id)[:]:
                    try:
                        record = record.object
                    except KeyError:
                        # Record is already gone - can't update it.
                        # (This shouldn't happen, but do this check for
                        # robustness.)
                        continue
                    record.collections = filter(lambda x: x != id, record.collections)
                    Record.objects.set(record)

                Collection.objects.remove(id)
                Record.objects.flush()
                Collection.objects.flush()
                gonext()
                redirect(url("colls-list", id=coll.id))
        elif cherrypy.request.method == "GET":
            context = dict(coll=coll)
            return render("coll-delete-confirm.html", context)

        raise cherrypy.HTTPError(404)
Example #4
0
    def _check_delete(self, id, page):
        params = cherrypy.request.params
        if params.get('delete', '') != '':
            record = get_or_404(Record, id)
            context = dict(record=record, page=page)
            return render("record-delete-confirm.html", context)

        if cherrypy.request.method == "POST":
            if params.get('delete_conf', '') != '':
                record = get_or_404(Record, id)
                #print "Old collections", record.collections
                record.collections = ()
                # Set the record, to remove the collections 
                Record.objects.set(record)
                Record.objects.remove(id)
                Record.objects.flush()
                Collection.objects.flush()
                gonext()
                redirect(url("search", act='search'))
Example #5
0
        record = validator.validate()
    except ValidationError, e:
        context['error'] = e.errormsg
        ok = False
        orig_record = get_or_404(Record, id)
        record = dict(inner_xml=params.get('inner_xml', None),
                      collections=validator.collections,
                      fieldnums=orig_record.fieldnums,
                      walkfields=orig_record.walkfields,
                      id=id,
                     )

    if ok and params.get('save', '') != '':
        Record.objects.set(record)
        Record.objects.flush()
        gonext()
        tmplid = params.get('tmplid', '')
        redirect(url("record-view", id=record.id, tmplid=tmplid))

    context['record'] = record

    return context

def tmpl_from_request(id, params):
    context = {}

    params, remcoll = handle_create_collection(params)
    validator = RecordValidator(params, remcoll)
    if validator.invalid_collections:
        return dict(invalid_collections=validator.invalid_collections)