Esempio n. 1
0
    def http_store_item(self, request):
        data = json.loads(request.POST["json"])

        current_query = data.pop("current_query", None)
        deleting = data["contents"] is None

        # if view ordering is present for current query,
        # make sure this entry shows up last
        if not deleting:
            # if we're not deleting
            from synoptic.datamodel import ViewOrderingHandler
            from synoptic.query import parse_query
            voh = ViewOrderingHandler(
                    request.dbsession, request.datamodel,
                    parse_query(current_query))
            if voh.has_ordering():
                voh.load()
                if data["id"] in voh:
                    # we already have a spot in the ordering, don't bother
                    voh = None
            else:
                voh = None
        else:
            voh = None

        if not deleting:
            set_with_parsed_datetime(data, "start_date",
                    use_utc=data["all_day"])
            set_with_parsed_datetime(data, "end_date", "start_date",
                    use_utc=data["all_day"])
            set_with_parsed_datetime(data, "hide_until", "start_date")
            set_with_parsed_datetime(data, "highlight_at", "start_date")

        if not deleting:
            from synoptic.datamodel import is_valid_tag
            for tag in data["tags"]:
                if not is_valid_tag(tag):
                    raise RuntimeError("invalid tag")

        itemversion = store_itemversion(request.dbsession,
                **data)

        request.dbsession.commit()  # fills in the item_id

        if voh is not None:
            voh.insert(len(voh), itemversion.item_id)
            voh.save()

        # send response
        return request.respond(
                json.dumps(self.item_to_json(itemversion)),
                mimetype="text/plain")
Esempio n. 2
0
    def http_reorder_item(self, request):
        data = json.loads(request.POST["json"])

        from synoptic.query import parse_query
        from synoptic.datamodel import ViewOrderingHandler

        if data["new_order"]:
            voh = ViewOrderingHandler(
                    request.dbsession, request.datamodel,
                    parse_query(data["current_search"]))
            voh.load()
            voh.set_order([int(x) for x in data["new_order"].split(",")])
            voh.save()

        return request.respond("", mimetype="text/plain")