Ejemplo n.º 1
0
def _delete_membership(document: Document, id: str, membership_id: str):
    if not bson.ObjectId.is_valid(id):
        flask.abort(400)

    document: Document = document.objects(id=id).first()
    if not document:
        flask.abort(404)
    document.update(pull__memberships___id=membership_id)
    document.reload()

    return flask.jsonify(document.jsonify())
Ejemplo n.º 2
0
 def delete_metadata(cls, obj: Document, keys: Sequence[str],
                     **more_updates) -> int:
     with TimingContext("mongo", "delete_metadata"):
         return obj.update(
             **{
                 f"unset__metadata__{ParameterKeyEscaper.escape(key)}": 1
                 for key in set(keys)
             },
             **more_updates,
         )
Ejemplo n.º 3
0
    def edit_metadata(
        cls,
        obj: Document,
        items: Sequence[MetadataItem],
        replace_metadata: bool,
        **more_updates,
    ) -> int:
        with TimingContext("mongo", "edit_metadata"):
            update_cmds = dict()
            metadata = cls.metadata_from_api(items)
            if replace_metadata:
                update_cmds["set__metadata"] = metadata
            else:
                for key, value in metadata.items():
                    update_cmds[
                        f"set__metadata__{mongoengine_safe(key)}"] = value

            return obj.update(**update_cmds, **more_updates)
Ejemplo n.º 4
0
def update_by_document(done_trade: mongoengine.Document):
    dic = filter_dict_by_id(done_trade.to_mongo().to_dict())
    done_trade.update(**dic)
Ejemplo n.º 5
0
def update_by_fields_dict(doc: mongoengine.Document, dic: dict):
    doc.update(**dic)
Ejemplo n.º 6
0
def update_by_field(doc: mongoengine.Document, field_name: str, value):
    doc.update(**{field_name: value})