# Path: lingobarter/core/db.py

# 
# Path: lingobarter/core/models/custom_values.py
# class HasCustomValue(object):
#     values = db.ListField(db.EmbeddedDocumentField(CustomValue))
# 
#     def get_values_tuple(self):
#         return [(value.name, value.value, value.formatter)
#                 for value in self.values]
# 
#     def get_value(self, name, default=None):
#         try:
#             return self.values.get(name=name).value
#         except:
#             return default
# 
#     def add_value(self, name, value, formatter='text'):
#         """
#         Another implementation
#         data = {"name": name, "rawvalue": value, "formatter": formatter}
#         self.values.update(data, name=name) or self.values.create(**data)
#         """
#         custom_value = CustomValue(
#             name=name,
#             value=value,
#             formatter=formatter
#         )
#         self.values.append(custom_value)
# 
#     def clean(self):
#         current_names = [value.name for value in self.values]
#         for name in current_names:
#             if current_names.count(name) > 1:
#                 raise Exception(lazy_gettext("%(name)s already exists",
#                                              name=name))
#         super(HasCustomValue, self).clean()


from datetime import datetime
from flask import url_for
from bson.objectid import ObjectId
from lingobarter.core.db import db
from lingobarter.core.models.custom_values import HasCustomValue
            ("image", "image")
        ),
        default='text', required=True)
    voice_file_path = db.StringField()
    text_content = db.StringField()
    image_file_path = db.StringField()
    undelivered = db.ListField(db.ObjectIdField(), default=[])
    timestamp = db.DateTimeField(default=datetime.now())

    def get_file_url(self):
        if self.type == 'text':
            return None
        elif self.type == 'voice':
            file_path = self.voice_file_path
        else:
            file_path = self.image_file_path
        return url_for(
            'lingobarter.core.media', filename=file_path
        )

    def __unicode__(self):
        return u"{0} - {1} - {2} - {3}".format(self.from_id, self.to_chat, self.type, self.timestamp)


class PartnerRequest(db.DynamicDocument, HasCustomValue):
    from_id = db.ObjectIdField(required=True)
    to_id = db.ObjectIdField(required=True)
    # todo: default time->now
    timestamp = db.DateTimeField(default=datetime.now())
    status = db.StringField(

# Path: lingobarter/core/db.py

# 
# Path: lingobarter/core/models/custom_values.py
# class HasCustomValue(object):
#     values = db.ListField(db.EmbeddedDocumentField(CustomValue))
# 
#     def get_values_tuple(self):
#         return [(value.name, value.value, value.formatter)
#                 for value in self.values]
# 
#     def get_value(self, name, default=None):
#         try:
#             return self.values.get(name=name).value
#         except:
#             return default
# 
#     def add_value(self, name, value, formatter='text'):
#         """
#         Another implementation
#         data = {"name": name, "rawvalue": value, "formatter": formatter}
#         self.values.update(data, name=name) or self.values.create(**data)
#         """
#         custom_value = CustomValue(
#             name=name,
#             value=value,
#             formatter=formatter
#         )
#         self.values.append(custom_value)
# 
#     def clean(self):
#         current_names = [value.name for value in self.values]
#         for name in current_names:
#             if current_names.count(name) > 1:
#                 raise Exception(lazy_gettext("%(name)s already exists",
#                                              name=name))
#         super(HasCustomValue, self).clean()


# Path: lingobarter/modules/barter/models.py
from datetime import datetime
from flask import url_for
from bson.objectid import ObjectId
from lingobarter.core.db import db
from lingobarter.core.models.custom_values import HasCustomValue

            ("image", "image")
        ),
        default='text', required=True)
    voice_file_path = db.StringField()
    text_content = db.StringField()
    image_file_path = db.StringField()
    undelivered = db.ListField(db.ObjectIdField(), default=[])
    timestamp = db.DateTimeField(default=datetime.now())

    def get_file_url(self):
        if self.type == 'text':
            return None
        elif self.type == 'voice':
            file_path = self.voice_file_path
        else:
            file_path = self.image_file_path
        return url_for(
            'lingobarter.core.media', filename=file_path
        )

    def __unicode__(self):
        return u"{0} - {1} - {2} - {3}".format(self.from_id, self.to_chat, self.type, self.timestamp)


class PartnerRequest(db.DynamicDocument, HasCustomValue):
    from_id = db.ObjectIdField(required=True)
    to_id = db.ObjectIdField(required=True)
    # todo: default time->now
    timestamp = db.DateTimeField(default=datetime.now())
    status = db.StringField(

        choices=(