def get_context_data(self, **kwargs):

        context = super().get_context_data(**kwargs)
        project = self.get_object()
        user = self.request.user

        permissions = Authorization.all_permissions(user, project)

        last_comments = Comment.objects.filter(
            project=project
        ).order_by('-created_on')[0:5]

        serialized_comments = CommentSerializer(last_comments, many=True).data

        features = Feature.objects.filter(
            project=project
        ).order_by('-created_on')

        serilized_projects = ProjectDetailedSerializer(project).data

        context['project'] = serilized_projects
        context['user'] = user
        context['last_comments'] = serialized_comments
        context['last_features'] = features[0:5]
        context['features'] = features
        context['permissions'] = permissions
        context['feature_types'] = project.featuretype_set.all()
        context['is_suscriber'] = Subscription.is_suscriber(user, project)

        # EDC
        layers = Layer.objects.filter(project=project)
        serialized_layers = LayerSerializer(layers, many=True)
        context['layers'] = serialized_layers.data

        return context
    def get_context_data(self, **kwargs):

        user = self.request.user
        project = self.get_object()
        permissions = Authorization.all_permissions(user, project)

        # On filtre les signalements selon leur statut et l'utilisateur courant
        features = Feature.handy.availables(
            user=user, project=project).order_by('-created_on')

        # On filtre les commentaire selon les signalements visibles
        last_comments = Comment.objects.filter(
            project=project,
            feature_id__in=[feat.feature_id
                            for feat in features]).order_by('-created_on')[0:5]

        serialized_comments = CommentSerializer(last_comments, many=True).data

        serilized_projects = ProjectDetailedSerializer(project).data

        context = super().get_context_data(**kwargs)

        context['project'] = serilized_projects
        context['title'] = project.title
        context['user'] = user
        context['last_comments'] = serialized_comments
        context['last_features'] = features[0:5]
        context['features'] = features
        context['permissions'] = permissions
        context['feature_types'] = project.featuretype_set.all()
        context['is_suscriber'] = Subscription.is_suscriber(user, project)
        return context
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context["title"] = settings.APPLICATION_NAME
     serilized_projects = ProjectDetailedSerializer(Project.objects.filter(
         is_project_type=True).order_by('-created_on'),
                                                    many=True)
     context['projects'] = serilized_projects.data
     return context
Beispiel #4
0
    def handle(self, *args, **options):

        frequency_setted = settings.DEFAULT_SENDING_FREQUENCY
        if frequency_setted not in ['instantly', 'daily', 'weekly']:
            logger.error('The default frequency setting is incorrect')
            return

        users = User.objects.filter(is_active=True)
        for user in users:

            # Pour chaque utilisateur on filtre les abonnements projets
            project_slugs = Subscription.objects.filter(
                users=user).values_list('project__slug', flat=True)
            stacked_events = []
            context = {}
            for slug in project_slugs:

                pending_stack = StackedEvent.objects.filter(
                    project_slug=slug,
                    state='pending',
                    schedualed_delivery_on__lte=now())

                if pending_stack.exists():
                    serialized_project = ProjectDetailedSerializer(
                        Project.objects.get(slug=slug))
                    # On ne peut avoir qu'une pile en attente pour un projet donnée
                    serialized_stack = StackedEventSerializer(
                        pending_stack.first())

                    stacked_events.append({
                        'project_data': serialized_project.data,
                        'stack_data': serialized_stack.data,
                    })

            context['stacked_events'] = stacked_events
            if len(context['stacked_events']) > 0:
                try:
                    notif_suscriber_grouped_events(emails=[
                        user.email,
                    ],
                                                   context=context)
                except Exception:
                    logger.exception(
                        'Error on notif_suscriber_grouped_events: {0}'.format(
                            user.email))
                else:
                    logger.info('Batch sent to {0}'.format(user.email))

        # TODO @cbenhabib: revoir la gestion des stack en erreur
        for row in StackedEvent.objects.filter(
                state='pending', schedualed_delivery_on__lte=now()):
            row.state = 'successful'
            row.save()

        logger.info('Command succeeded! ')
Beispiel #5
0
    def get(self, request):
        data = {}
        user = request.user
        # data['user'] = user

        # on liste les droits de l'utilisateur pour chaque projet
        data['permissions'] = {}
        data['rank'] = {}
        for project in Project.objects.all():
            data['permissions'][project.slug] = Authorization.has_permission(
                user, 'can_view_project', project)

            try:
                rank = Authorization.objects.get(project=project,
                                                 user=user).level
                rank = AuthorizationSerializer(rank).data
            except Exception:
                if user.is_superuser:
                    usertype = choices.ADMIN
                else:
                    usertype = choices.LOGGED_USER
                serializer_rank = UserLevelPermission.objects.get(
                    user_type_id=usertype)
                rank = UserLevelPermissionSerializer(serializer_rank).data

            data['rank'][project.slug] = rank

        project_authorized = Authorization.objects.filter(user=user).filter(
            level__rank__lte=2).values_list('project__pk', flat=True)
        serialized_projects = ProjectDetailedSerializer(Project.objects.filter(
            Q(pk__in=project_authorized)
            | Q(creator=user)).order_by('-created_on'),
                                                        many=True)

        all_events = Event.objects.filter(user=user).order_by('-created_on')
        serialized_events = EventSerializer(all_events[0:5], many=True)

        feature_events = Event.objects.filter(
            user=user, object_type='feature').order_by('-created_on')
        serialized_feature_events = EventSerializer(feature_events[0:5],
                                                    many=True)

        comment_events = Event.objects.filter(
            user=user, object_type='comment').order_by('-created_on')
        serialized_comment_events = EventSerializer(comment_events[0:5],
                                                    many=True)

        data['projects'] = serialized_projects.data
        data['events'] = serialized_events.data
        data['features'] = serialized_feature_events.data
        data['comments'] = serialized_comment_events.data
        data['title'] = "Mon compte"

        return Response(data=data, status=status.HTTP_200_OK)
Beispiel #6
0
    def get(self, request):
        context = {}
        user = request.user
        # context['user'] = user

        # on liste les droits de l'utilisateur pour chaque projet
        context['permissions'] = {}
        context['rank'] = {}
        for project in Project.objects.all():
            context['permissions'][
                project.slug] = Authorization.has_permission(
                    user, 'can_view_project', project)

            try:
                rank = Authorization.objects.get(project=project,
                                                 user=user).level
            except Exception:
                if user.is_superuser:
                    usertype = choices.ADMIN
                else:
                    usertype = choices.LOGGED_USER
                rank = UserLevelPermission.objects.get(user_type_id=usertype)

            context['rank'][project.slug] = rank

        project_authorized = Authorization.objects.filter(user=user).filter(
            level__rank__lte=2).values_list('project__pk', flat=True)
        serilized_projects = ProjectDetailedSerializer(Project.objects.filter(
            Q(pk__in=project_authorized)
            | Q(creator=user)).order_by('-created_on'),
                                                       many=True)

        all_events = Event.objects.filter(user=user).order_by('-created_on')
        serialized_events = EventSerializer(all_events[0:5], many=True)

        feature_events = Event.objects.filter(
            user=user, object_type='feature').order_by('-created_on')
        serialized_feature_events = EventSerializer(feature_events[0:5],
                                                    many=True)

        comment_events = Event.objects.filter(
            user=user, object_type='comment').order_by('-created_on')
        serialized_comment_events = EventSerializer(comment_events[0:5],
                                                    many=True)

        context['projects'] = serilized_projects.data
        context['events'] = serialized_events.data
        context['features'] = serialized_feature_events.data
        context['comments'] = serialized_comment_events.data

        return render(request, 'geocontrib/my_account.html', context)
Beispiel #7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["title"] = settings.APPLICATION_NAME

        context["can_create_project"] = False
        user = self.request.user
        if user.is_authenticated:
            if user.is_superuser or user.is_administrator:
                context["can_create_project"] = True

        serilized_projects = ProjectDetailedSerializer(
            Project.objects.all().order_by('-created_on'), many=True)

        context['projects'] = serilized_projects.data

        return context