class Module(Element): app_label = models.CharField(_('application label'), max_length=64, unique=True) name = models.CharField(_('name'), max_length=128, null=False, unique=True) description = models.CharField(_('description'), max_length=256) author = models.CharField(_('author'), max_length=64) license_type = models.CharField( _('license'), max_length=64, help_text='Commercial, BSD, MIT, LGPL, GPL...') version = models.CharField(max_length=32, verbose_name=_('version')) db_version = models.PositiveIntegerField(_('DB version'), help_text=_('Database version'), null=True) last_update = models.PositiveIntegerField(_('last update')) icon = models.CharField(_('icon'), max_length=256) details = models.TextField(_('details')) dependencies = models.TextField(_('dependencies')) tooltip = models.CharField(_('tooltip'), max_length=64) visible = models.BooleanField(_('visible'), default=True) class Meta: verbose_name = _('module') def __str__(self): return '%s (%s)' % (self.app_label, self.name)
class AttributeValue(models.Model): attribute = models.ForeignKey(Attribute) object_id = models.PositiveIntegerField() text_value = models.CharField(max_length=1024) texta_value = models.TextField() logical_value = models.BooleanField() #file_value = models.FileField() fk_value = models.PositiveIntegerField() int_value = models.IntegerField() decimal_value = models.MoneyField() date_value = models.DateTimeField() class Meta: db_table = 'base_attribute_value'
class Comment(models.Model): """ Provides user comment to any allowed content object. """ user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'), null=False) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') comment = models.TextField(_('comment')) submit_date = models.DateTimeField(_('date/time submitted'), default=datetime.datetime.now()) ip_address = models.GenericIPAddressField(_('IP address'), unpack_ipv4=True) is_public = models.BooleanField(_('is public'), default=True, help_text=_('Uncheck this box to make the comment effectively ' \ 'disappear from the site.')) is_removed = models.BooleanField(_('is removed'), default=False, help_text=_('Check this box if the comment is inappropriate. ' \ 'A "This comment has been removed" message will ' \ 'be displayed instead.')) class Meta: db_table = 'comment_content'
class UserContent(models.Model): """ User/author content object log. """ content_type = models.ForeignKey(ContentType, verbose_name=_('content type'), null=False, related_name='+') object_id = models.PositiveIntegerField(_('object id'), null=False) content_object = generic.GenericForeignKey('content_type', 'object_id') created_by = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('created by'), null=False, related_name='+') created_on = models.DateTimeField(auto_now_add=True, verbose_name=_('created on'), null=False) modified_by = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('modified by'), related_name='+') modified_on = models.DateTimeField(auto_now=True, verbose_name=_('modified on')) class Meta: db_table = 'base_user_content'
class ModelData(models.Model): name = models.CharField(max_length=128, db_index=True) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') can_change = models.BooleanField(default=True) class Meta: db_table = 'base_model_data'
class Attachment(models.Model): name = models.CharField(max_length=128, null=False, verbose_name=_('name')) description = models.TextField(_('description')) type = models.CharField(_('type'), max_length=16, choices=(('url', 'URL'), ('file', _('File')))) body = models.BinaryField(_('body')) url = models.URLField('URL') content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') class Meta: db_table = 'base_attachment' verbose_name = _('attachment') verbose_name = _('attachments')
class Follow(models.Model): """ Used to user follow any allowed content object. """ user = models.ForeignKey(settings.AUTH_USER_MODEL, null=False, related_name='+') content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') join_date = models.DateTimeField(_('date/time'), auto_now_add=True, null=False) active = models.BooleanField(default=True) class Meta: db_table = 'comment_follow'
class UserLog(models.Model): """ User log record. """ user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('user'), null=False, related_name='+') content_type = models.ForeignKey(ContentType, verbose_name=_('content type'), null=False, related_name='+') object_id = models.PositiveIntegerField(_('object id')) content_object = generic.GenericForeignKey('content_type', 'object_id') operation = models.CharField( max_length=64, null=False) # create, read, update, delete, print... description = models.TextField() log_time = models.DateTimeField(_('date/time'), null=False, auto_now_add=True) class Meta: db_table = 'base_user_log'
class Menu(ModuleElement): name = models.CharField(_('name'), max_length=128, null=False, db_index=True) parent = models.ForeignKey('self', verbose_name=_('parent')) action = models.ForeignKey(Action, verbose_name=_('action')) image = models.CharField(_('image'), max_length=256, help_text=_('menu image file path')) sequence = models.PositiveIntegerField(_('sequence'), help_text=_('menu item sequence'), default=0, db_index=True) objects = MenuManager() class Meta: db_table = 'base_menu' verbose_name = _('menu item') verbose_name_plural = _('menu items') ordering = ['sequence', 'id'] def __str__(self): return self.get_full_name() @property def is_leaf(self): return self.__class__.objects.filter(parent_id=self.pk).count() == 0 def get_full_name(self): parents = [] parent = self while parent: parents.insert(0, parent.name) parent = parent.parent return '/'.join(parents) def set_full_name(self, path): cls = self.__class__ menu = None parents = path.split('/') self.name = parents[-1] for item in parents[:-1]: parent = menu try: menu = cls.objects.get(parent_id=menu, name=item) except: menu = None if not menu: menu = cls.objects.create(name=item.replace('\\', '/'), parent=parent, module_id=self.module_id) self.parent = menu full_name = property(get_full_name, set_full_name) ## Auto create model form action for target menu item def get_model(self): if self.action and self.action.action_type == 'form': return FormAction.objects.get(pk=self.action.pk).model def set_model(self, model): if isinstance(model, str): model = model.split('.') model = BaseModel.objects.get(content_type__app_label=model[0], content_type__model=model[1]) action = FormAction.objects.create( name='%s "%s.%s"' % (('showmodel', ) + model.content_type.natural_key()), model=model) self.action = action self.image = '/static/keops/icons/page.png' model = property(get_model, set_model) ## Auto create form action for target menu item def get_form(self): if self.action and self.action.action_type == 'form': return FormAction.objects.get(pk=self.action.pk).view def set_form(self, form): if isinstance(form, str): form = View.objects.get(name=form) action = FormAction.objects.create(name='%s "%s"' % ('showform', form.name), view=form) self.action = action self.image = '/static/keops/icons/page.png' form = property(get_form, set_form) ## Auto create report action for target menu item def get_report(self): if self.action and self.action.action_type == 'report': return ReportAction.objects.get(pk=self.action.pk).report def set_report(self, report): if isinstance(report, str): try: rep = Report.objects.get(name=report) except: rep = Report.objects.create(name=report) report = rep action = ReportAction.objects.create(name='%s "%s"' % ('showreport', report.name), report=report) self.action = action self.image = '/static/keops/icons/page.png' report = property(get_report, set_report)