Beispiel #1
0
    def save(self, *args, **kwargs):

        original_channel = None
        if self.pk and Channel.objects.filter(pk=self.pk).exists():
            original_channel = Channel.objects.get(pk=self.pk)

        record_channel_stats(self, original_channel)

        # Check if original thumbnail is no longer referenced
        if original_channel and original_channel.thumbnail and 'static' not in original_channel.thumbnail:
            filename, ext = os.path.splitext(original_channel.thumbnail)
            delete_empty_file_reference(filename, ext[1:])

        if not self.main_tree:
            self.main_tree = ContentNode.objects.create(
                title=self.name,
                kind_id=content_kinds.TOPIC,
                sort_order=0,
                content_id=self.id,
                node_id=self.id,
            )
            self.main_tree.save()
        elif self.main_tree.title != self.name:
            self.main_tree.title = self.name
            self.main_tree.save()

        if not self.trash_tree:
            self.trash_tree = ContentNode.objects.create(
                title=self.name,
                kind_id=content_kinds.TOPIC,
                sort_order=0,
                content_id=self.id,
                node_id=self.id,
            )
            self.trash_tree.save()
        elif self.trash_tree.title != self.name:
            self.trash_tree.title = self.name
            self.trash_tree.save()

        super(Channel, self).save(*args, **kwargs)

        if original_channel and not self.main_tree.changed:
            fields_to_check = [
                'description', 'language_id', 'thumbnail', 'name', 'language',
                'thumbnail_encoding', 'deleted'
            ]
            self.main_tree.changed = any([
                f for f in fields_to_check
                if getattr(self, f) != getattr(original_channel, f)
            ])

            # Delete db if channel has been deleted and mark as unpublished
            if not original_channel.deleted and self.deleted:
                self.pending_editors.all().delete()
                channel_db_url = os.path.join(settings.DB_ROOT,
                                              self.id) + ".sqlite3"
                if os.path.isfile(channel_db_url):
                    os.unlink(channel_db_url)
                    self.main_tree.published = False
            self.main_tree.save()
Beispiel #2
0
    def save(self, *args, **kwargs):

        original_channel = None
        if self.pk and Channel.objects.filter(pk=self.pk).exists():
            original_channel = Channel.objects.get(pk=self.pk)

        record_channel_stats(self, original_channel)

        # Check if original thumbnail is no longer referenced
        if original_channel and original_channel.thumbnail and 'static' not in original_channel.thumbnail:
            filename, ext = os.path.splitext(original_channel.thumbnail)
            delete_empty_file_reference(filename, ext[1:])

        if not self.main_tree:
            self.main_tree = ContentNode.objects.create(
                title=self.name,
                kind_id=content_kinds.TOPIC,
                sort_order=0,
                content_id=self.id,
                node_id=self.id,
            )
            self.main_tree.save()
        elif self.main_tree.title != self.name:
            self.main_tree.title = self.name
            self.main_tree.save()

        if not self.trash_tree:
            self.trash_tree = ContentNode.objects.create(
                title=self.name,
                kind_id=content_kinds.TOPIC,
                sort_order=0,
                content_id=self.id,
                node_id=self.id,
            )
            self.trash_tree.save()
        elif self.trash_tree.title != self.name:
            self.trash_tree.title = self.name
            self.trash_tree.save()

        super(Channel, self).save(*args, **kwargs)