Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Converted django/models/__init__.py to use unix newlines, not DOS

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1401 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 827ebe53686d4fce3b37241969b717df2e864f3d 1 parent d922825
Adrian Holovaty authored November 24, 2005

Showing 1 changed file with 92 additions and 92 deletions. Show diff stats Hide diff stats

  1. 184  django/models/__init__.py
184  django/models/__init__.py
... ...
@@ -1,92 +1,92 @@
1  
-from django.core import meta
2  
-from django.utils.functional import curry
3  
-
4  
-__all__ = ['auth', 'core']
5  
-
6  
-# Alter this package's __path__ variable so that calling code can import models
7  
-# from "django.models" even though the model code doesn't physically live
8  
-# within django.models.
9  
-for mod in meta.get_installed_models():
10  
-    __path__.extend(mod.__path__)
11  
-
12  
-# First, import all models so the metaclasses run.
13  
-modules = meta.get_installed_model_modules(__all__)
14  
-
15  
-# Now, create the extra methods that we couldn't create earlier because
16  
-# relationships hadn't been known until now.
17  
-for mod in modules:
18  
-    for klass in mod._MODELS:
19  
-
20  
-        # Add "get_thingie", "get_thingie_count" and "get_thingie_list" methods
21  
-        # for all related objects.
22  
-        for rel_obj, rel_field in klass._meta.get_all_related_objects():
23  
-            # Determine whether this related object is in another app.
24  
-            # If it's in another app, the method names will have the app
25  
-            # label prepended, and the add_BLAH() method will not be
26  
-            # generated.
27  
-            rel_mod = rel_obj.get_model_module()
28  
-            rel_obj_name = klass._meta.get_rel_object_method_name(rel_obj, rel_field)
29  
-            if isinstance(rel_field.rel, meta.OneToOne):
30  
-                # Add "get_thingie" methods for one-to-one related objects.
31  
-                # EXAMPLE: Place.get_restaurants_restaurant()
32  
-                func = curry(meta.method_get_related, 'get_object', rel_mod, rel_field)
33  
-                func.__doc__ = "Returns the associated `%s.%s` object." % (rel_obj.app_label, rel_obj.module_name)
34  
-                setattr(klass, 'get_%s' % rel_obj_name, func)
35  
-            elif isinstance(rel_field.rel, meta.ManyToOne):
36  
-                # Add "get_thingie" methods for many-to-one related objects.
37  
-                # EXAMPLE: Poll.get_choice()
38  
-                func = curry(meta.method_get_related, 'get_object', rel_mod, rel_field)
39  
-                func.__doc__ = "Returns the associated `%s.%s` object matching the given criteria." % (rel_obj.app_label, rel_obj.module_name)
40  
-                setattr(klass, 'get_%s' % rel_obj_name, func)
41  
-                # Add "get_thingie_count" methods for many-to-one related objects.
42  
-                # EXAMPLE: Poll.get_choice_count()
43  
-                func = curry(meta.method_get_related, 'get_count', rel_mod, rel_field)
44  
-                func.__doc__ = "Returns the number of associated `%s.%s` objects." % (rel_obj.app_label, rel_obj.module_name)
45  
-                setattr(klass, 'get_%s_count' % rel_obj_name, func)
46  
-                # Add "get_thingie_list" methods for many-to-one related objects.
47  
-                # EXAMPLE: Poll.get_choice_list()
48  
-                func = curry(meta.method_get_related, 'get_list', rel_mod, rel_field)
49  
-                func.__doc__ = "Returns a list of associated `%s.%s` objects." % (rel_obj.app_label, rel_obj.module_name)
50  
-                setattr(klass, 'get_%s_list' % rel_obj_name, func)
51  
-                # Add "add_thingie" methods for many-to-one related objects,
52  
-                # but only for related objects that are in the same app.
53  
-                # EXAMPLE: Poll.add_choice()
54  
-                if rel_obj.app_label == klass._meta.app_label:
55  
-                    func = curry(meta.method_add_related, rel_obj, rel_mod, rel_field)
56  
-                    func.alters_data = True
57  
-                    setattr(klass, 'add_%s' % rel_obj_name, func)
58  
-                del func
59  
-            del rel_obj_name, rel_mod, rel_obj, rel_field # clean up
60  
-
61  
-        # Do the same for all related many-to-many objects.
62  
-        for rel_opts, rel_field in klass._meta.get_all_related_many_to_many_objects():
63  
-            rel_mod = rel_opts.get_model_module()
64  
-            rel_obj_name = klass._meta.get_rel_object_method_name(rel_opts, rel_field)
65  
-            setattr(klass, 'get_%s' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_object', klass._meta, rel_mod, rel_field))
66  
-            setattr(klass, 'get_%s_count' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_count', klass._meta, rel_mod, rel_field))
67  
-            setattr(klass, 'get_%s_list' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_list', klass._meta, rel_mod, rel_field))
68  
-            if rel_opts.app_label == klass._meta.app_label:
69  
-                func = curry(meta.method_set_related_many_to_many, rel_opts, rel_field)
70  
-                func.alters_data = True
71  
-                setattr(klass, 'set_%s' % rel_opts.module_name, func)
72  
-                del func
73  
-            del rel_obj_name, rel_mod, rel_opts, rel_field # clean up
74  
-
75  
-        # Add "set_thingie_order" and "get_thingie_order" methods for objects
76  
-        # that are ordered with respect to this.
77  
-        for obj in klass._meta.get_ordered_objects():
78  
-            func = curry(meta.method_set_order, obj)
79  
-            func.__doc__ = "Sets the order of associated `%s.%s` objects to the given ID list." % (obj.app_label, obj.module_name)
80  
-            func.alters_data = True
81  
-            setattr(klass, 'set_%s_order' % obj.object_name.lower(), func)
82  
-
83  
-            func = curry(meta.method_get_order, obj)
84  
-            func.__doc__ = "Returns the order of associated `%s.%s` objects as a list of IDs." % (obj.app_label, obj.module_name)
85  
-            setattr(klass, 'get_%s_order' % obj.object_name.lower(), func)
86  
-            del func, obj # clean up
87  
-        del klass # clean up
88  
-    del mod
89  
-del modules
90  
-
91  
-# Expose get_app and get_module.
92  
-from django.core.meta import get_app, get_module
  1
+from django.core import meta
  2
+from django.utils.functional import curry
  3
+
  4
+__all__ = ['auth', 'core']
  5
+
  6
+# Alter this package's __path__ variable so that calling code can import models
  7
+# from "django.models" even though the model code doesn't physically live
  8
+# within django.models.
  9
+for mod in meta.get_installed_models():
  10
+    __path__.extend(mod.__path__)
  11
+
  12
+# First, import all models so the metaclasses run.
  13
+modules = meta.get_installed_model_modules(__all__)
  14
+
  15
+# Now, create the extra methods that we couldn't create earlier because
  16
+# relationships hadn't been known until now.
  17
+for mod in modules:
  18
+    for klass in mod._MODELS:
  19
+
  20
+        # Add "get_thingie", "get_thingie_count" and "get_thingie_list" methods
  21
+        # for all related objects.
  22
+        for rel_obj, rel_field in klass._meta.get_all_related_objects():
  23
+            # Determine whether this related object is in another app.
  24
+            # If it's in another app, the method names will have the app
  25
+            # label prepended, and the add_BLAH() method will not be
  26
+            # generated.
  27
+            rel_mod = rel_obj.get_model_module()
  28
+            rel_obj_name = klass._meta.get_rel_object_method_name(rel_obj, rel_field)
  29
+            if isinstance(rel_field.rel, meta.OneToOne):
  30
+                # Add "get_thingie" methods for one-to-one related objects.
  31
+                # EXAMPLE: Place.get_restaurants_restaurant()
  32
+                func = curry(meta.method_get_related, 'get_object', rel_mod, rel_field)
  33
+                func.__doc__ = "Returns the associated `%s.%s` object." % (rel_obj.app_label, rel_obj.module_name)
  34
+                setattr(klass, 'get_%s' % rel_obj_name, func)
  35
+            elif isinstance(rel_field.rel, meta.ManyToOne):
  36
+                # Add "get_thingie" methods for many-to-one related objects.
  37
+                # EXAMPLE: Poll.get_choice()
  38
+                func = curry(meta.method_get_related, 'get_object', rel_mod, rel_field)
  39
+                func.__doc__ = "Returns the associated `%s.%s` object matching the given criteria." % (rel_obj.app_label, rel_obj.module_name)
  40
+                setattr(klass, 'get_%s' % rel_obj_name, func)
  41
+                # Add "get_thingie_count" methods for many-to-one related objects.
  42
+                # EXAMPLE: Poll.get_choice_count()
  43
+                func = curry(meta.method_get_related, 'get_count', rel_mod, rel_field)
  44
+                func.__doc__ = "Returns the number of associated `%s.%s` objects." % (rel_obj.app_label, rel_obj.module_name)
  45
+                setattr(klass, 'get_%s_count' % rel_obj_name, func)
  46
+                # Add "get_thingie_list" methods for many-to-one related objects.
  47
+                # EXAMPLE: Poll.get_choice_list()
  48
+                func = curry(meta.method_get_related, 'get_list', rel_mod, rel_field)
  49
+                func.__doc__ = "Returns a list of associated `%s.%s` objects." % (rel_obj.app_label, rel_obj.module_name)
  50
+                setattr(klass, 'get_%s_list' % rel_obj_name, func)
  51
+                # Add "add_thingie" methods for many-to-one related objects,
  52
+                # but only for related objects that are in the same app.
  53
+                # EXAMPLE: Poll.add_choice()
  54
+                if rel_obj.app_label == klass._meta.app_label:
  55
+                    func = curry(meta.method_add_related, rel_obj, rel_mod, rel_field)
  56
+                    func.alters_data = True
  57
+                    setattr(klass, 'add_%s' % rel_obj_name, func)
  58
+                del func
  59
+            del rel_obj_name, rel_mod, rel_obj, rel_field # clean up
  60
+
  61
+        # Do the same for all related many-to-many objects.
  62
+        for rel_opts, rel_field in klass._meta.get_all_related_many_to_many_objects():
  63
+            rel_mod = rel_opts.get_model_module()
  64
+            rel_obj_name = klass._meta.get_rel_object_method_name(rel_opts, rel_field)
  65
+            setattr(klass, 'get_%s' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_object', klass._meta, rel_mod, rel_field))
  66
+            setattr(klass, 'get_%s_count' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_count', klass._meta, rel_mod, rel_field))
  67
+            setattr(klass, 'get_%s_list' % rel_obj_name, curry(meta.method_get_related_many_to_many, 'get_list', klass._meta, rel_mod, rel_field))
  68
+            if rel_opts.app_label == klass._meta.app_label:
  69
+                func = curry(meta.method_set_related_many_to_many, rel_opts, rel_field)
  70
+                func.alters_data = True
  71
+                setattr(klass, 'set_%s' % rel_opts.module_name, func)
  72
+                del func
  73
+            del rel_obj_name, rel_mod, rel_opts, rel_field # clean up
  74
+
  75
+        # Add "set_thingie_order" and "get_thingie_order" methods for objects
  76
+        # that are ordered with respect to this.
  77
+        for obj in klass._meta.get_ordered_objects():
  78
+            func = curry(meta.method_set_order, obj)
  79
+            func.__doc__ = "Sets the order of associated `%s.%s` objects to the given ID list." % (obj.app_label, obj.module_name)
  80
+            func.alters_data = True
  81
+            setattr(klass, 'set_%s_order' % obj.object_name.lower(), func)
  82
+
  83
+            func = curry(meta.method_get_order, obj)
  84
+            func.__doc__ = "Returns the order of associated `%s.%s` objects as a list of IDs." % (obj.app_label, obj.module_name)
  85
+            setattr(klass, 'get_%s_order' % obj.object_name.lower(), func)
  86
+            del func, obj # clean up
  87
+        del klass # clean up
  88
+    del mod
  89
+del modules
  90
+
  91
+# Expose get_app and get_module.
  92
+from django.core.meta import get_app, get_module

0 notes on commit 827ebe5

Please sign in to comment.
Something went wrong with that request. Please try again.