Esempio n. 1
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info(f'Purging dataset {dataset}')
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove HarvestItem references
        HarvestJob.objects(items__dataset=dataset).update(
            set__items__S__dataset=None)
        # Remove each dataset's resource's file
        storage = storages.resources
        for resource in dataset.resources:
            if resource.fs_filename is not None:
                storage.delete(resource.fs_filename)
        # Remove each dataset related community resource and it's file
        community_resources = CommunityResource.objects(dataset=dataset)
        for community_resource in community_resources:
            if community_resource.fs_filename is not None:
                storage.delete(community_resource.fs_filename)
            community_resource.delete()
        # Remove dataset
        dataset.delete()
Esempio n. 2
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info('Purging reuse "{0}"'.format(reuse))
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove issues
        Issue.objects(subject=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        reuse.delete()
Esempio n. 3
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info('Purging reuse "{0}"'.format(reuse))
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove issues
        Issue.objects(subject=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        # Remove metrics
        Metrics.objects(object_id=reuse.id).delete()
        reuse.delete()
Esempio n. 4
0
 def get_context(self):
     context = super(OrganizationIssuesView, self).get_context()
     datasets = Dataset.objects(organization=self.organization)
     reuses = Reuse.objects(organization=self.organization)
     ids = [o.id for o in list(datasets) + list(reuses)]
     context['issues'] = Issue.objects(subject__in=ids)
     return context
Esempio n. 5
0
def purge_reuses(self):
    for reuse in Reuse.objects(deleted__ne=None):
        log.info(f'Purging reuse {reuse}')
        # Remove followers
        Follow.objects(following=reuse).delete()
        # Remove issues
        Issue.objects(subject=reuse).delete()
        # Remove discussions
        Discussion.objects(subject=reuse).delete()
        # Remove activity
        Activity.objects(related_to=reuse).delete()
        # Remove reuse's logo in all sizes
        if reuse.image.filename is not None:
            storage = storages.images
            storage.delete(reuse.image.filename)
            storage.delete(reuse.image.original)
            for key, value in reuse.image.thumbnails.items():
                storage.delete(value)
        reuse.delete()
Esempio n. 6
0
    def get(self):
        '''List all current user pending notifications'''

        user = current_user._get_current_object()
        notifications = []

        orgs = [o for o in user.organizations if o.is_admin(user)]

        # Fetch user open issues
        datasets = Dataset.objects.owned_by(user, *orgs)
        reuses = Reuse.objects.owned_by(user, *orgs)
        for issue in Issue.objects(subject__in=list(datasets) + list(reuses)):
            notifications.append({
                'type': 'issue',
                'created_on': issue.created,
                'details': {
                    'subject': {
                        'type': issue.subject.__class__.__name__.lower(),
                        'id': str(issue.subject.id)
                    }
                }
            })

        # Fetch pending membership requests
        for org in orgs:
            for request in org.pending_requests:
                notifications.append({
                    'type': 'membership_request',
                    'created_on': request.created,
                    'details': {
                        'organization': org.id,
                        'user': {
                            'id': str(request.user.id),
                            'fullname': request.user.fullname,
                            'avatar': str(request.user.avatar)
                        }
                    }
                })

        # Fetch pending transfer requests
        for transfer in Transfer.objects(recipient__in=[user] + orgs,
                                         status='pending'):
            notifications.append({
                'type': 'transfer_request',
                'created_on': transfer.created,
                'details': {
                    'id': str(transfer.id),
                    'subject': {
                        'class': transfer.subject.__class__.__name__.lower(),
                        'id': str(transfer.subject.id)
                    }
                }
            })

        return notifications
Esempio n. 7
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove
        dataset.delete()
Esempio n. 8
0
    def get(self):
        '''List all current user pending notifications'''

        user = current_user._get_current_object()
        notifications = []

        orgs = [o for o in user.organizations if o.is_admin(user)]

        # Fetch user open issues
        datasets = Dataset.objects.owned_by(user, *orgs)
        reuses = Reuse.objects.owned_by(user, *orgs)
        for issue in Issue.objects(subject__in=list(datasets)+list(reuses)):
            notifications.append({
                'type': 'issue',
                'created_on': issue.created,
                'details': {
                    'subject': {
                        'type': issue.subject.__class__.__name__.lower(),
                        'id': str(issue.subject.id)
                    }
                }
            })

        # Fetch pending membership requests
        for org in orgs:
            for request in org.pending_requests:
                notifications.append({
                    'type': 'membership_request',
                    'created_on': request.created,
                    'details': {
                        'organization': org.id,
                        'user': {
                            'id': str(request.user.id),
                            'fullname': request.user.fullname,
                            'avatar': str(request.user.avatar)
                        }
                    }
                })

        # Fetch pending transfer requests
        for transfer in Transfer.objects(recipient__in=[user]+orgs, status='pending'):
            notifications.append({
                'type': 'transfer_request',
                'created_on': transfer.created,
                'details': {
                    'id': str(transfer.id),
                    'subject': {
                        'class': transfer.subject.__class__.__name__.lower(),
                        'id': str(transfer.subject.id)
                    }
                }
            })

        return notifications
Esempio n. 9
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove metrics
        Metrics.objects(object_id=dataset.id).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove
        dataset.delete()
Esempio n. 10
0
def purge_datasets(self):
    for dataset in Dataset.objects(deleted__ne=None):
        log.info('Purging dataset "{0}"'.format(dataset))
        # Remove followers
        Follow.objects(following=dataset).delete()
        # Remove issues
        Issue.objects(subject=dataset).delete()
        # Remove discussions
        Discussion.objects(subject=dataset).delete()
        # Remove activity
        Activity.objects(related_to=dataset).delete()
        # Remove topics' related dataset
        for topic in Topic.objects(datasets=dataset):
            datasets = topic.datasets
            datasets.remove(dataset)
            topic.update(datasets=datasets)
        # Remove HarvestItem references
        HarvestJob.objects(items__dataset=dataset).update(
            set__items__S__dataset=None)
        # Remove
        dataset.delete()
Esempio n. 11
0
def issues_notifications(user):
    '''Notify user about open issues'''
    orgs = [o for o in user.organizations if o.is_member(user)]
    datasets = Dataset.objects.owned_by(user, *orgs)
    reuses = Reuse.objects.owned_by(user, *orgs)
    notifications = []

    for issue in Issue.objects(
            subject__in=list(datasets) + list(reuses),
            closed__exists=False):
        notifications.append((issue.created, {
            'id': issue.id,
            'title': issue.title,
            'subject': {
                'id': issue.subject.id,
                'type': issue.subject.__class__.__name__.lower(),
            }
        }))

    return notifications
Esempio n. 12
0
 def count_issues(self):
     from udata.models import Issue
     self.metrics['issues'] = Issue.objects(subject=self,
                                            closed=None).count()
     self.save()
Esempio n. 13
0
 def get_context(self):
     context = super(DatasetIssuesView, self).get_context()
     context['issues'] = Issue.objects(subject=self.dataset)
     return context
Esempio n. 14
0
File: api.py Progetto: grouan/udata
    def get(self):
        """List all current user pending notifications"""

        user = current_user._get_current_object()
        notifications = []

        orgs = [o for o in user.organizations if o.is_member(user)]
        datasets = Dataset.objects.owned_by(user, *orgs)
        reuses = Reuse.objects.owned_by(user, *orgs)

        # TODO: use polymorph field

        # Fetch user open issues
        for issue in Issue.objects(subject__in=list(datasets) + list(reuses)):
            notifications.append(
                {
                    "type": "issue",
                    "created_on": issue.created,
                    "details": {
                        "id": str(issue.id),
                        "title": issue.title,
                        "subject": {"id": str(issue.subject.id), "type": issue.subject.__class__.__name__.lower()},
                    },
                }
            )

        # Fetch user open discussions
        for discussion in Discussion.objects(subject__in=list(datasets) + list(reuses)):
            notifications.append(
                {
                    "type": "discussion",
                    "created_on": discussion.created,
                    "details": {
                        "id": str(discussion.id),
                        "title": discussion.title,
                        "subject": {
                            "id": str(discussion.subject.id),
                            "type": discussion.subject.__class__.__name__.lower(),
                        },
                    },
                }
            )

        # Fetch pending membership requests
        for org in orgs:
            for request in org.pending_requests:
                notifications.append(
                    {
                        "type": "membership_request",
                        "created_on": request.created,
                        "details": {
                            "organization": org.id,
                            "user": {
                                "id": str(request.user.id),
                                "fullname": request.user.fullname,
                                "avatar": str(request.user.avatar),
                            },
                        },
                    }
                )

        # Fetch pending transfer requests
        for transfer in Transfer.objects(recipient__in=[user] + orgs, status="pending"):
            notifications.append(
                {
                    "type": "transfer_request",
                    "created_on": transfer.created,
                    "details": {
                        "id": str(transfer.id),
                        "subject": {
                            "class": transfer.subject.__class__.__name__.lower(),
                            "id": str(transfer.subject.id),
                        },
                    },
                }
            )

        return notifications
Esempio n. 15
0
 def get_context(self):
     context = super(DatasetIssuesView, self).get_context()
     context['issues'] = Issue.objects(subject=self.dataset)
     return context
Esempio n. 16
0
 def get_context(self):
     context = super(ReuseIssuesView, self).get_context()
     context['issues'] = Issue.objects(subject=self.reuse)
     return context