~widelands-dev/widelands-website/responsive_website

« back to all changes in this revision

Viewing changes to djangoratings/__init__.py

  • Committer: franku
  • Date: 2016-05-18 19:31:46 UTC
  • mto: This revision was merged to the branch mainline in revision 409.
  • Revision ID: somal@arcor.de-20160518193146-w5dmezymi3wlnhvl
added djangoratings and adjust it to django 1.8; updated update_problems.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os.path
 
2
import warnings
 
3
 
 
4
__version__ = (0, 3, 7)
 
5
 
 
6
def _get_git_revision(path):
 
7
    revision_file = os.path.join(path, 'refs', 'heads', 'master')
 
8
    if not os.path.exists(revision_file):
 
9
        return None
 
10
    fh = open(revision_file, 'r')
 
11
    try:
 
12
        return fh.read()
 
13
    finally:
 
14
        fh.close()
 
15
 
 
16
def get_revision():
 
17
    """
 
18
    :returns: Revision number of this branch/checkout, if available. None if
 
19
        no revision number can be determined.
 
20
    """
 
21
    package_dir = os.path.dirname(__file__)
 
22
    checkout_dir = os.path.normpath(os.path.join(package_dir, '..'))
 
23
    path = os.path.join(checkout_dir, '.git')
 
24
    if os.path.exists(path):
 
25
        return _get_git_revision(path)
 
26
    return None
 
27
 
 
28
__build__ = get_revision()
 
29
 
 
30
def lazy_object(location):
 
31
    def inner(*args, **kwargs):
 
32
        parts = location.rsplit('.', 1)
 
33
        warnings.warn('`djangoratings.%s` is deprecated. Please use `%s` instead.' % (parts[1], location), DeprecationWarning)
 
34
        try:
 
35
            imp = __import__(parts[0], globals(), locals(), [parts[1]], -1)
 
36
        except:
 
37
            imp = __import__(parts[0], globals(), locals(), [parts[1]])
 
38
        func = getattr(imp, parts[1])
 
39
        if callable(func):
 
40
            return func(*args, **kwargs)
 
41
        return func
 
42
    return inner
 
43
 
 
44
RatingField = lazy_object('djangoratings.fields.RatingField')
 
45
AnonymousRatingField = lazy_object('djangoratings.fields.AnonymousRatingField')
 
46
Rating = lazy_object('djangoratings.fields.Rating')
 
 
b'\\ No newline at end of file'