murano-dashboard/muranodashboard/models.py
Igor Yozhikov e9f38c707d Cherry-pick the following change-ids from release-0.2.
I08b8b7391e591d0131af8c4fe074ddaf0222eddc
I9eab7412b67b1cf83025688dba8d879aa0be3b01
I487019103d4ad00c993a6e2df0962dea68c4c86b
I8d8463e79675778f6a8dc01623c81227d06e8d4b
I6609d418150053ee4953a2ae9dba80f76da03fb2
Ic496352384412e53860ee48d696d2794b06ad2ca
I2ae97838ac45eac65032f71f9f6e9445974f0236
I35279696b2aee81739a5c4cb7657e4a9fc4f52e2
Ia6b32e14213b147881b242710ca130a4dea3cdb2
I25ff8448c3cde53aa69905ba5f3736a37e7ed692
Icc1651aeed02784b8a3bde792550efb067af19c9
Ibd5529e1b1754b12fcfade77361dc393cc1780ab
Ice7a3cca2f7931c6f9089f207eddb6f1f802bf4e
I283a67e437d1495257e4c39b18e558072875ffea
I10d4bfd2a0a6a35dbb3e9fca437ceae9e853cc1b
I6c48f803b57399604211ad9a9faee44d87d4dd6d
I7ae888d2708ca438f7e5c94a53e7ddbcc134f4f6
I6b7c54e3700b3b2511f87dfb107d91a13dee9d9b
I2e5c1a4edea567fc2aa31541e7fbc582fc63b885
Ia2d2eaa17c6f8c3e53da4745b03a2b27ff6738fe
I20f03d21c09d090b7edb3360da385e12cad28102
I932674e2b789be54c4366a9a2b81ceaa0c37a133
I64000e26965e8fabb883e5b1294b7639bdade849
I2093b4ed5c33340904698e0d0f01128ece7a2f2b
I2c1e5e156bba1c4c4ed1cd5fb643410c24055706
Iebfe935385a3eeab2ea258bd8dad2ccb70ab14ef
Id7b215a610c0c3375055fb1ff7c75e384fab2d3a
Ie74f5a48ce90e3dab33cd3fc8b57a366433d7fe5
I136eb043e915d4028d5256efbb071c61906a3f69
I4fc13f58f679893b68abbc87c2650743c0258260
Idde251b1c7b1a31cadb5f416f753e365fe572961
Icd385908dd620837b0f4c779059ff540e10263df
I29e4ef69087a78a85d9ea323590e70b0fc8ad642
I2f284035fc656a48c1c7525724a34a3b75f72c64
Ie46f5d27f21f6ddfc1e2cb86e081bea14e1099f4

Change-Id: I96cb8ee13e2905fab9ba41b6dea1ae84b74c7765
2013-09-03 14:04:43 +04:00

78 lines
2.4 KiB
Python

"""
Stub file to work around django bug: https://code.djangoproject.com/ticket/7198
"""
from django.db import models
from django.db.models.query import EmptyQuerySet
import copy
class FakeQuerySet(EmptyQuerySet):
"""Turn a list into a Django QuerySet... kind of."""
def __init__(self, model=None, query=None, using=None, items=[]):
super(FakeQuerySet, self).__init__(model, query, using)
self._result_cache = items
def __getitem__(self, k):
if isinstance(k, slice):
obj = self._clone()
obj._result_cache = super(FakeQuerySet, self).__getitem__(k)
return obj
else:
return super(FakeQuerySet, self).__getitem__(k)
def count(self):
return len(self)
def _clone(self, klass=None, setup=False, **kwargs):
c = super(FakeQuerySet, self)._clone(klass, setup=setup, **kwargs)
c._result_cache = copy.copy(self._result_cache)
return c
def iterator(self):
# This slightly odd construction is because we need an empty generator
# (it raises StopIteration immediately).
yield iter(self._result_cache).next()
def order_by(self, *fields):
obj = self._clone()
cache = obj._result_cache
for field in fields:
reverse = False
if field[0] == '-':
reverse = True
field = field[1:]
cache = sorted(cache, None, lambda item: getattr(item, field),
reverse=reverse)
obj._result_cache = cache
return obj
def distinct(self, *fields):
obj = self._clone()
return obj
def values_list(self, *fields, **kwargs):
obj = self._clone()
cache = []
for item in self._result_cache:
value = []
for field in fields:
value.append(getattr(item, field))
cache.append(tuple(value))
if kwargs.get('flat', False) and len(fields) == 1:
cache = [item[0] for item in cache]
obj._result_cache = cache
return obj
def add(self, item):
self._result_cache.append(item)
def remove(self):
self._result_cache.pop()
class Node(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=20)
isMaster = models.BooleanField(default=False)
isSync = models.BooleanField(default=False)