418 |
418 |
if not context.get('synchronous'):
|
419 |
419 |
raise NothingInCacheException()
|
420 |
420 |
return super(Invoices, self).render(context)
|
421 |
|
|
422 |
|
|
423 |
|
class Items(CellBase):
|
424 |
|
regie = models.CharField(_('Regie'), max_length=50, blank=True)
|
425 |
|
title = models.CharField(_('Title'), max_length=200, blank=True)
|
426 |
|
text = RichTextField(_('Text'), blank=True, null=True)
|
427 |
|
|
428 |
|
user_dependant = True
|
429 |
|
template_name = 'lingo/combo/items.html'
|
430 |
|
|
431 |
|
class Meta:
|
432 |
|
abstract = True
|
433 |
|
|
434 |
|
|
435 |
|
class Media:
|
436 |
|
js = ('xstatic/jquery-ui.min.js', 'js/gadjo.js',)
|
437 |
|
css = {'all': ('xstatic/themes/smoothness/jquery-ui.min.css', )}
|
438 |
|
|
439 |
|
@classmethod
|
440 |
|
def is_enabled(cls):
|
441 |
|
return Regie.objects.count() > 0
|
442 |
|
|
443 |
|
def get_default_form_class(self):
|
444 |
|
fields = ['title', 'text']
|
445 |
|
widgets = {}
|
446 |
|
if Regie.objects.count() > 1:
|
447 |
|
regies = [('', _('All'))]
|
448 |
|
regies.extend([(r.slug, r.label) for r in Regie.objects.all()])
|
449 |
|
widgets['regie'] = Select(choices=regies)
|
450 |
|
fields.insert(0, 'regie')
|
451 |
|
return model_forms.modelform_factory(self.__class__, fields=fields, widgets=widgets)
|
452 |
|
|
453 |
|
def get_regies(self):
|
454 |
|
if self.regie:
|
455 |
|
return [Regie.objects.get(slug=self.regie)]
|
456 |
|
return Regie.objects.all()
|
457 |
|
|
458 |
|
def get_cell_extra_context(self, context):
|
459 |
|
ctx = {'title': self.title, 'text': self.text}
|
460 |
|
items = self.get_items()
|
461 |
|
# sort items by creation date
|
462 |
|
items.sort(key=lambda i: i.creation_date, reverse=True)
|
463 |
|
ctx.update({'items': items})
|
464 |
|
return ctx
|
465 |
|
|
466 |
|
def render(self, context):
|
467 |
|
self.context = context
|
468 |
|
if not context.get('synchronous'):
|
469 |
|
raise NothingInCacheException()
|
470 |
|
return super(Items, self).render(context)
|
471 |
|
|
472 |
|
|
473 |
|
@register_cell_class
|
474 |
|
class ItemsHistory(Items):
|
475 |
|
|
476 |
|
class Meta:
|
477 |
|
verbose_name = _('Items History Cell')
|
478 |
|
|
479 |
|
def get_items(self):
|
480 |
|
items = []
|
481 |
|
for r in self.get_regies():
|
482 |
|
items.extend(r.get_past_items(self.context))
|
483 |
|
return items
|
484 |
|
|
485 |
|
|
486 |
|
@register_cell_class
|
487 |
|
class ActiveItems(Items):
|
488 |
|
|
489 |
|
class Meta:
|
490 |
|
verbose_name = _('Active Items Cell')
|
491 |
|
|
492 |
|
def get_items(self):
|
493 |
|
items = []
|
494 |
|
for r in self.get_regies():
|
495 |
|
items.extend(r.get_items(self.context))
|
496 |
|
return items
|
497 |
|
-
|