Ejemplo n.º 1
0
    def __init__(self, root_collection, **kwargs):
        """Write a file to GridFS

        Application developers should generally not need to
        instantiate this class directly - instead see the methods
        provided by :class:`~gridfs.GridFS`.

        Raises :class:`TypeError` if `root_collection` is not an
        instance of :class:`~txmongo._pymongo.collection.Collection`.

        Any of the file level options specified in the `GridFS Spec
        <http://dochub.mongodb.org/core/gridfsspec>`_ may be passed as
        keyword arguments. Any additional keyword arguments will be
        set as additional fields on the file document. Valid keyword
        arguments include:

          - ``"_id"``: unique ID for this file (default:
            :class:`~pymongo.objectid.ObjectId`)

          - ``"filename"``: human name for the file

          - ``"contentType"`` or ``"content_type"``: valid mime-type
            for the file

          - ``"chunkSize"`` or ``"chunk_size"``: size of each of the
            chunks, in bytes (default: 256 kb)

        :Parameters:
          - `root_collection`: root collection to write to
          - `**kwargs` (optional): file level options (see above)
        """
        if not isinstance(root_collection, Collection):
            raise TypeError(
                "root_collection must be an instance of Collection")

        # Handle alternative naming
        if "content_type" in kwargs:
            kwargs["contentType"] = kwargs.pop("content_type")
        if "chunk_size" in kwargs:
            kwargs["chunkSize"] = kwargs.pop("chunk_size")

        # Defaults
        _id = kwargs.get("_id", ObjectId())
        if not isinstance(_id, ObjectId):
            _id = ObjectId(_id)
        kwargs["_id"] = _id
        kwargs["chunkSize"] = kwargs.get("chunkSize", DEFAULT_CHUNK_SIZE)

        object.__setattr__(self, "_coll", root_collection)
        object.__setattr__(self, "_chunks", root_collection.chunks)
        object.__setattr__(self, "_file", kwargs)
        object.__setattr__(self, "_buffer", StringIO())
        object.__setattr__(self, "_position", 0)
        object.__setattr__(self, "_chunk_number", 0)
        object.__setattr__(self, "_closed", False)
Ejemplo n.º 2
0
def guardavendedor(atributos,accion):
	atributos["valor"]="1"
	atributos["stock"]=ObjectId(atributos["stock"])


	db=DBModule("venedoresinfo")
	db.saveEntity(atributos).addCallback(lambda ign: accion(db.getResult()))
Ejemplo n.º 3
0
 def render_POST(self, request):
     def finish(_):
         request.redirect('/admin')
         request.finish()
     _id = ObjectId(self.post_id)
     d = _db.posts.remove({'_id': _id})
     d.addCallback(finish)
     return NOT_DONE_YET
Ejemplo n.º 4
0
 def render_GET(self, request):
     def handle_post(post):
         context = {'post': post}
         request.write(render_response('singlepost.html', context))
         request.finish()
     _id = ObjectId(self.post_id)
     deferred = _db.posts.find_one(_id)
     deferred.addCallback(handle_post)
     return NOT_DONE_YET
Ejemplo n.º 5
0
 def insert(self, docs, safe=False):
     if isinstance(docs, types.DictType):
         ids = docs.get('_id', ObjectId())
         docs["_id"] = ids
         docs = [docs]
     elif isinstance(docs, types.ListType):
         ids = []
         for doc in docs:
             if isinstance(doc, types.DictType):
                 id = doc.get('_id', ObjectId())
                 ids.append(id)
                 doc["_id"] = id
             else:
                 raise TypeError("insert takes a document or a list of documents")
     else:
         raise TypeError("insert takes a document or a list of documents")
     proto = self._database._connection
     proto.OP_INSERT(str(self), docs)
     return self.__safe_operation(proto, safe, ids)
Ejemplo n.º 6
0
def obtenerlotes(stock, accion, param, skip, limit):
    db = DBModule("bodegasinfo")
    db.getEntities(param={
        "_id": ObjectId(stock)
    },
                   args={
                       "productos": True,
                       "_id": False
                   },
                   skip=skip,
                   limit=limit).addCallback(lambda ign: ver(db.getResult()))
Ejemplo n.º 7
0
 def render_POST(self, request):
     def finish(_):
         request.redirect('/admin')
         request.finish()
     data = {'author': cgi.escape(request.args['author'][0]),
             'text': cgi.escape(request.args['text'][0]),
             'tags': cgi.escape(request.args['tags'][0]), }
     d = _db.posts.update(
         {'_id': ObjectId(cgi.escape(request.args['id'][0]))},
         {'$set': data})
     d.addCallback(finish)
     return NOT_DONE_YET
Ejemplo n.º 8
0
    def render_GET(self, request):
        session = request.getSession()
        if session.uid not in sessions:
            request.redirect('/login')
            return ''

        def handle_post(post):
            context = {'post': post}
            request.write(render_response('create.html', context))
            request.finish()
        d = _db.posts.find_one(ObjectId(self.post_id))
        d.addCallback(handle_post)
        return NOT_DONE_YET
Ejemplo n.º 9
0
def _get_oid(data):
    return (ObjectId(data[:12]), data[12:])
Ejemplo n.º 10
0
from txmongo._pymongo.objectid import ObjectId
import pymongo

if __name__ == '__main__':
	conection= pymongo.Connection('0.0.0.0',27017)
	db=conection["Mejorcita"]
	bodegasinfo= db["bodegasinfo"]
	for i in range(24):
		x={"_id":ObjectId(),"name":"Bodega"+str(i+1),"status":1,"address": {"district":"Colonia","street":"Calle","intNum": None, "extNum": 100} ,"phone":str(9789560+i),"businessName":"Negocio"+str(i+1),"manager":{"_id":ObjectId(),"status":"Valido","username":"******"+str(i+1),"password":"******","curp":"89687800"+str(i),"phone":"9781200","email":"manager"+str(i+1)+"@gmail.com","type":"mamanger"},"geoposition":{"latitude":"22.8818","longitude":"-102.2913"},"maxSale":"1500","minSale":"0","products":{"_id":ObjectId(),"2013/01/01": "1500","2013/01/02": "1200"}}
		#x={"_id":str(ObjectId()),"name":"Punto"+str(1+1) ,"status":"Valido","phone":str(9789560+i),"email":"punto"+str(i+1)+"@gmail.com","joinDate":"15enero2010","fridge":{"serial":"4747464"+str(i),"temperature":"-5","status":"Valido"},"representative":{"name":"representante"+str(i+1),"phone":str(9789560+i),"email":"representante"+str(i+1)+"@gmail.com"},"stock":{"name":"Bodega"+str(i+1)}}
		#x={"_id":str(ObjectId()),"status":"Valido","name":"Vendedor"+str(i+1),"curp":"89687800"+str(i),"email":"vendedor"+str(i+1)+"@gmail.com","device":"74748848"+str(i),"phone":str(9789560+i),"stock":{"name":"Bodega"+str(i+1)}}
		#x={"_id":str(ObjectId()),"date":"15enero2011","time":"11:59pm","observations":"observacion","amount":"4","products":"1500","geoposition":{"latitude":"22.8818","longitude":"-102.2913"},"seller":{"name":"Vendedor"+str(i+1)},"salepoint":{"fridge":{"serial":"4747464"+str(i),"temperature":"-5","status":"Valido"}}}
		#x={"_id":str(ObjectId()),"status":"Valido","name":"carne1","salePrice":"150","registrationDate":"15enero2011","count":"1500"}
		bodegasinfo.insert(x)
		x={}

Ejemplo n.º 11
0
 def object_hook(self, dct):
     if "$oid" in dct:
         return ObjectId(str(dct["$oid"]))
     return dct