in between queries

default view/sort for lists
This commit is contained in:
rolux 2011-09-29 17:13:07 +00:00
parent d6e27be0cd
commit 0eefc3dfd3
3 changed files with 47 additions and 25 deletions

View file

@ -67,6 +67,10 @@ def parseCondition(condition):
in_find = False in_find = False
facet_value = 'facets__value%s' % { facet_value = 'facets__value%s' % {
'==': '__iexact', '==': '__iexact',
'>': '__gt',
'>=': '__gte',
'<': '__lt',
'<=': '__lte',
'^': '__istartswith', '^': '__istartswith',
'$': '__iendswith', '$': '__iendswith',
}.get(op, '__icontains') }.get(op, '__icontains')
@ -75,6 +79,10 @@ def parseCondition(condition):
else: else:
value_key = 'find__value%s' % { value_key = 'find__value%s' % {
'==': '__iexact', '==': '__iexact',
'>': '__gt',
'>=': '__gte',
'<': '__lt',
'<=': '__lte',
'^': '__istartswith', '^': '__istartswith',
'$': '__iendswith', '$': '__iendswith',
}.get(op, '__icontains') }.get(op, '__icontains')
@ -131,7 +139,7 @@ def parseCondition(condition):
}.get(op,'__exact')) }.get(op,'__exact'))
vk = str('find__%s' % vk) vk = str('find__%s' % vk)
if exclude: #!1960 if exclude: #!1960
return ~Q(**{'find__key': k, vk: v}) return ~Q(**{'find__key': k, vk: v})
else: #1960 else: #1960

View file

@ -34,6 +34,9 @@ class List(models.Model):
icon = models.ImageField(default=None, blank=True, icon = models.ImageField(default=None, blank=True,
upload_to=lambda i, x: i.path("icon.jpg")) upload_to=lambda i, x: i.path("icon.jpg"))
view = models.TextField(default=settings.CONFIG['user']['ui']['listView'])
sort = TupleField(default=tuple(settings.CONFIG['user']['ui']['listSort']), editable=False)
poster_frames = TupleField(default=[], editable=False) poster_frames = TupleField(default=[], editable=False)
#is through table still required? #is through table still required?
@ -50,7 +53,8 @@ class List(models.Model):
self.type = 'static' self.type = 'static'
else: else:
self.type = 'smart' self.type = 'smart'
self.items_sum = self.get_items_sum(self.user) if self.id:
self.items_sum = self.get_items_sum(self.user)
super(List, self).save(*args, **kwargs) super(List, self).save(*args, **kwargs)
def get_items_sum(self, user=None): def get_items_sum(self, user=None):
@ -144,7 +148,7 @@ class List(models.Model):
if not os.path.exists(path): if not os.path.exists(path):
folder = os.path.dirname(path) folder = os.path.dirname(path)
ox.makedirs(folder) ox.makedirs(folder)
if self.icon: if self.icon and os.path.exists(self.icon.path):
source = self.icon.path source = self.icon.path
max_size = min(self.icon.width, self.icon.height) max_size = min(self.icon.width, self.icon.height)
else: else:

View file

@ -192,6 +192,8 @@ def addList(request):
type type
query query
items items
view
sort
return { return {
status: {'code': int, 'text': string}, status: {'code': int, 'text': string},
@ -211,28 +213,32 @@ def addList(request):
num += 1 num += 1
name = data['name'] + ' [%d]' % num name = data['name'] + ' [%d]' % num
for key in data: if 'query' in data and data['query']:
if key == 'query' and not data['query']: setattr(list, 'query', data['query'])
setattr(list, key, {"static":True}) else:
elif key == 'query': setattr(list, 'query', {"static":True})
setattr(list, key, data[key]) if 'type' in data:
elif key == 'type': if data['type'] == 'static':
if data[key] == 'static': list.query = {"static":True}
list.query = {"static":True} list.type = 'static'
list.type = 'static' else:
else: list.type = 'dynamic'
list.type = 'dynamic' if list.query.get('static', False):
if list.query.get('static', False): list.query = {}
list.query = {} if 'status' in data:
elif key == 'status': value = data['status']
value = data[key] if value not in list._status:
if value not in list._status: value = list._status[0]
value = list._status[0] if not request.user.is_staff and value == 'featured':
if not request.user.is_staff and value == 'featured': value = 'private'
value = 'private' list.status = value
setattr(list, key, value) if 'description' in data:
elif key == 'description': list.description = data['description']
list.description = data['description'] if 'view' in data:
list.view = data['view']
if 'sort' in data:
list.sort= tuple(data['sort'])
list.save() list.save()
if 'items' in data: if 'items' in data:
@ -351,6 +357,10 @@ def editList(request):
if 'posterFrames' in data: if 'posterFrames' in data:
list.poster_frames = tuple(data['posterFrames']) list.poster_frames = tuple(data['posterFrames'])
list.update_icon() list.update_icon()
if 'view' in data:
list.view = data['view']
if 'sort' in data:
list.sort= tuple(data['sort'])
list.save() list.save()
response['data'] = list.json(user=request.user) response['data'] = list.json(user=request.user)
else: else: