# Path: cms/colander_types.py
# class DateTimeUS(colander.SchemaType):
# class DateUS(colander.SchemaType):
#     def __init__(self, timezone='UTC'):
#     def serialize(self, node, appstruct):
#     def deserialize(self, node, cstruct):
#     def serialize(self, node, appstruct):
#     def deserialize(self, node, cstruct):
# 
# Path: cms/dateutil.py
# def get_timezone_for_request(request=None, default='UTC'):
#     # FIXME: consider making this a user preference
#     if request:
#         return request.registry.settings.get('default_timezone', default)
#     else:
#         return default
# 
# def today_for_request_tz(request):
#     """ Return "today's date" for the request's timezone.
#     Kinda tricky since at any moment there are always two current dates, depending on your local timezone.
#     On the other hand, there's only one UTC date at any moment.
#     """
#     return convert_from_utc_to_request_tz(datetime.datetime.utcnow(), request).date()
# 
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


from content import Content
from cms import colander_types
from cms.dateutil import get_timezone_for_request, today_for_request_tz, utcnow
import colander, deform
import widgets
    _object_type = "article"

    def get_class_schema(cls, request=None):
        schema = Content.get_class_schema(request)
        #schema.add(colander.SchemaNode(colander_types.DateUS(), name='dateline', default=today_for_request_tz(request)))
        schema.add(colander.SchemaNode(colander_types.DateTimeUS(get_timezone_for_request(request)), name='dateline', default=utcnow()))
        schema.add(colander.SchemaNode(colander.String(), name='body', widget=widgets.get_html_widget()))
        # Single file upload:
        #schema.add(colander.SchemaNode(deform.FileData(), name='attachment', widget=widgets.get_fileupload_widget(request)))

        # Sequence of file uploads:
        schema.add(colander.SchemaNode(colander.Sequence(), colander.SchemaNode(deform.FileData(), widget=widgets.get_fileupload_widget(request)), name='attachments', missing=[], default=[]))
        schema.add(colander.SchemaNode(colander.Boolean(), name='list_attachments', title="List attachments after body?", default=False, missing=False))

        return schema
    get_class_schema = classmethod(get_class_schema)

    def __getitem__(self, name):
        # # Allow traversal to "attachment":
        # if name == 'attachment':
        #     file = self.get_file_for_attribute(name)
        #     if file: return file
        # raise KeyError

        # Allow traversal to one of the "attachments" by filename:
        file = self.get_file_by_filename("attachments", name)
        if file:
            file.__name__ = name
            file.__parent__ = self
            return file

# Path: cms/colander_types.py
# class DateTimeUS(colander.SchemaType):
# class DateUS(colander.SchemaType):
#     def __init__(self, timezone='UTC'):
#     def serialize(self, node, appstruct):
#     def deserialize(self, node, cstruct):
#     def serialize(self, node, appstruct):
#     def deserialize(self, node, cstruct):
# 
# Path: cms/dateutil.py
# def get_timezone_for_request(request=None, default='UTC'):
#     # FIXME: consider making this a user preference
#     if request:
#         return request.registry.settings.get('default_timezone', default)
#     else:
#         return default
# 
# def today_for_request_tz(request):
#     """ Return "today's date" for the request's timezone.
#     Kinda tricky since at any moment there are always two current dates, depending on your local timezone.
#     On the other hand, there's only one UTC date at any moment.
#     """
#     return convert_from_utc_to_request_tz(datetime.datetime.utcnow(), request).date()
# 
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


# Path: cms/resources/article.py
from content import Content
from cms import colander_types
from cms.dateutil import get_timezone_for_request, today_for_request_tz, utcnow
import colander, deform
import widgets

    _object_type = "article"

    def get_class_schema(cls, request=None):
        schema = Content.get_class_schema(request)
        #schema.add(colander.SchemaNode(colander_types.DateUS(), name='dateline', default=today_for_request_tz(request)))
        schema.add(colander.SchemaNode(colander_types.DateTimeUS(get_timezone_for_request(request)), name='dateline', default=utcnow()))
        schema.add(colander.SchemaNode(colander.String(), name='body', widget=widgets.get_html_widget()))
        # Single file upload:
        #schema.add(colander.SchemaNode(deform.FileData(), name='attachment', widget=widgets.get_fileupload_widget(request)))

        # Sequence of file uploads:
        schema.add(colander.SchemaNode(colander.Sequence(), colander.SchemaNode(deform.FileData(), widget=widgets.get_fileupload_widget(request)), name='attachments', missing=[], default=[]))
        schema.add(colander.SchemaNode(colander.Boolean(), name='list_attachments', title="List attachments after body?", default=False, missing=False))

        return schema
    get_class_schema = classmethod(get_class_schema)

    def __getitem__(self, name):
        # # Allow traversal to "attachment":
        # if name == 'attachment':
        #     file = self.get_file_for_attribute(name)
        #     if file: return file
        # raise KeyError

        # Allow traversal to one of the "attachments" by filename:
        file = self.get_file_by_filename("attachments", name)
        if file:
            file.__name__ = name
            file.__parent__ = self
            return file

        raise KeyError