def insert(name, redirect_url): acc = db.accounts.find_one({'email': request.authorization.username}) _id = str(getrandbits(32)) retry_count = 1 short_id_length = conf['SHORT_ID_MIN_LENGTH'] while True: short_id = slug(short_id_length) if not db.items.find_one({'short_id': short_id}): break else: retry_count += 1 if retry_count > 3: short_id_length += 1 retry_count = 1 x = { 'account': request.authorization.username, 'name': name, '_id': _id, 'short_id': slug(short_id_length), 'redirect_url': redirect_url, 'item_type': 'bookmark', 'view_counter': 0, 'private': request.form.get('acl', acc['private_items']) if conf['ALLOW_PRIVATE_BOOKMARKS'] else False, 'source': request.headers.get('User-Agent', 'Regenschirm++/1.0').split(' ', 1)[0], 'created_at': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()), 'updated_at': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()), } item = Item(x, conf, urlscheme(request)) db.items.insert(x) items = acc['items'] items.append(_id) db.accounts.update({'_id': acc['_id']}, {'$set': { 'items': items }}, upsert=False) return item
def upload_file(self, conf, account, obj, useragent, privacy): if obj is None: return None # XXX what's this? if isinstance(privacy, (str, unicode)): privacy = True if privacy == 'private' else False timestamp = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) if obj.filename.find(u'\x00') == len(obj.filename)-1: filename = obj.filename[:-1] else: filename = obj.filename _id = str(getrandbits(32)) retry_count = 3 short_id_length = conf['SHORT_ID_MIN_LENGTH'] while True: try: self.put(obj, _id=_id ,filename=filename, created_at=timestamp, content_type=obj.mimetype, account=account, view_counter=0, short_id=slug(short_id_length), updated_at=timestamp, source=useragent, private=privacy) break except DuplicateKeyError: retry_count += 1 if retry_count > 3: short_id_length += 1 retry_count = 1 return _id
def insert(name, redirect_url): acc = db.accounts.find_one({'email': request.authorization.username}) _id = str(getrandbits(32)) retry_count = 1 short_id_length = conf['SHORT_ID_MIN_LENGTH'] while True: short_id = slug(short_id_length) if not db.items.find_one({'short_id': short_id}): break else: retry_count += 1 if retry_count > 3: short_id_length += 1 retry_count = 1 x = { 'account': request.authorization.username, 'name': name, '_id': _id, 'short_id': slug(short_id_length), 'redirect_url': redirect_url, 'item_type': 'bookmark', 'view_counter': 0, 'private': request.form.get('acl', acc['private_items']) if conf['ALLOW_PRIVATE_BOOKMARKS'] else False, 'source': request.headers.get('User-Agent', 'Regenschirm++/1.0').split(' ', 1)[0], 'created_at': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()), 'updated_at': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()), } item = Item(x, conf, urlscheme(request)) db.items.insert(x) items = acc['items'] items.append(_id) db.accounts.update({'_id': acc['_id']}, {'$set': {'items': items}}, upsert=False) return item
def upload_file(self, conf, account, obj, useragent, privacy): if obj is None: return None # XXX what's this? if isinstance(privacy, (str, unicode)): privacy = True if privacy == 'private' else False timestamp = strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()) if obj.filename.find(u'\x00') == len(obj.filename) - 1: filename = obj.filename[:-1] else: filename = obj.filename _id = str(getrandbits(32)) retry_count = 3 short_id_length = conf['SHORT_ID_MIN_LENGTH'] while True: try: self.put(obj, _id=_id, filename=filename, created_at=timestamp, content_type=obj.mimetype, account=account, view_counter=0, short_id=slug(short_id_length), updated_at=timestamp, source=useragent, private=privacy) break except DuplicateKeyError: retry_count += 1 if retry_count > 3: short_id_length += 1 retry_count = 1 return _id