# Copyright (C) 2012  Mantas Zimnickas <sirexas@gmail.com>
#
# This file is part of manoseimas.lt project.
#
# manoseimas.lt is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# manoseimas.lt is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with manoseimas.lt.  If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime

from django.core.urlresolvers import reverse
from django.utils.functional import lazy

reverse_lazy = lazy(reverse, str)


def todate(date_str, date_format='%Y-%m-%d'):
    if date_str:
        return datetime.strptime(date_str, date_format).date()
    else:
        return None

@@ -1071,8 +1071,1171 @@
 rn None%0A
+%0A%0Aclass reify(object):%0A    %22%22%22 Use as a class method decorator.  It operates almost exactly like the%0A    Python %60%60@property%60%60 decorator, but it puts the result of the method it%0A    decorates into the instance dict after the first call, effectively%0A    replacing the function it decorates with an instance variable.  It is, in%0A    Python parlance, a non-data descriptor.  An example:%0A%0A    .. code-block:: python%0A%0A       class Foo(object):%0A           @reify%0A           def jammy(self):%0A               print('jammy called')%0A               return 1%0A%0A    And usage of Foo:%0A%0A    %3E%3E%3E f = Foo()%0A    %3E%3E%3E v = f.jammy%0A    'jammy called'%0A    %3E%3E%3E print(v)%0A    1%0A    %3E%3E%3E f.jammy%0A    1%0A    %3E%3E%3E # jammy func not called the second time; it replaced itself with 1%0A%0A    Function taken from Pyramid project%0A    %22%22%22%0A    def __init__(self, wrapped):%0A        self.wrapped = wrapped%0A        try:%0A            self.__doc__ = wrapped.__doc__%0A        except:  # pragma: no cover%0A            pass%0A%0A    def __get__(self, inst, objtype=None):%0A        if inst is None:%0A            return self%0A        val = self.wrapped(inst)%0A        setattr(inst, self.wrapped.__name__, val)%0A        return val%0A

Add reify decorator from Pyramid.