# Path: app.py



import os
import sys
from werkzeug.routing import BaseConverter, ValidationError
from itsdangerous import base64_encode, base64_decode
from bson.objectid import ObjectId
from bson.errors import InvalidId
from app import app
# -*- coding: utf-8 -*-
"""
    database.support_objectid
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Support PyMongo ObjectIDs in URLs
    http://flask.pocoo.org/snippets/106/
"""

sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))




class ObjectIDConverter(BaseConverter):
    def to_python(self, value):
        try:
            return ObjectId(base64_decode(value))
        except (InvalidId, ValueError, TypeError):
            raise ValidationError()
    def to_url(self, value):
        return base64_encode(value.binary)



# Path: app.py



# Path: database/support_objectid.py
import os
import sys
from werkzeug.routing import BaseConverter, ValidationError
from itsdangerous import base64_encode, base64_decode
from bson.objectid import ObjectId
from bson.errors import InvalidId
from app import app

# -*- coding: utf-8 -*-
"""
    database.support_objectid
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Support PyMongo ObjectIDs in URLs
    http://flask.pocoo.org/snippets/106/
"""

sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))




class ObjectIDConverter(BaseConverter):
    def to_python(self, value):
        try:
            return ObjectId(base64_decode(value))
        except (InvalidId, ValueError, TypeError):
            raise ValidationError()
    def to_url(self, value):
        return base64_encode(value.binary)



app.url_map.converters['objectid'] = ObjectIDConverter