Esempio n. 1
0
def change_observers(watch, decision, watcher):
    if watch:
        if not notification.is_observing(decision, watcher):
            notification.observe(decision, watcher, DECISION_CHANGE)
    else:
        if notification.is_observing(decision, watcher):
            notification.stop_observing(decision, watcher)
Esempio n. 2
0
def stop_observing_article(request, title,
                           group_slug=None, group_slug_field=None, group_qs=None,
                           article_qs=ALL_ARTICLES,
                           template_name='recentchanges.html',
                           template_dir='wiki',
                           extra_context=None,
                           is_member=None,
                           is_private=None,
                           *args, **kw):
    if request.method == 'POST':

        article_args = {'title': title}
        group = None
        if group_slug is not None:
            group = get_object_or_404(group_qs,**{group_slug_field: group_slug})
            article_args.update({'content_type': get_ct(group),
                                 'object_id': group.id})
            allow_read = has_read_perm(request.user, group, is_member,
                                       is_private)
        else:
            allow_read = True

        if not allow_read:
            return HttpResponseForbidden()

        article = get_object_or_404(article_qs, **article_args)

        notification.stop_observing(article, request.user)

        url = get_url('wiki_article', group,
                      [article.title], {'title': article.title,
                                        'group_slug': group_slug})

        return redirect_to(request, url)
    return HttpResponseNotAllowed(['POST'])
Esempio n. 3
0
def change_observers(watch, decision, watcher):
    if watch:
        if not notification.is_observing(decision, watcher):
            notification.observe(decision, watcher, DECISION_CHANGE)
    else:
        if notification.is_observing(decision, watcher):
            notification.stop_observing(decision, watcher)
Esempio n. 4
0
def observe_toggle(request, content_type_id, object_id,
                     signal, notice_type_label):
    success = False
    observing = None
    try:
        content_type = ContentType.objects.get(pk=content_type_id)
        observed = content_type.get_object_for_this_type(pk=object_id)
        if not is_observing(observed=observed, observer=request.user,
                            signal=signal):
            observe(observed=observed,
                    observer=request.user,
                    notice_type_label=notice_type_label,
                    signal=signal)
            observing = True
        else:
            stop_observing(observed=observed,
                           observer=request.user,
                           signal=signal)
            observing = False
        success = True
    except:
        pass

    return HttpResponse(
        json.dumps({"success": success,  "observing": observing, }),
        mimetype='application/json; charset=utf-8',
        status=200
    )
Esempio n. 5
0
def stop_observing_article(request,
                           title,
                           group_slug=None,
                           group_slug_field=None,
                           group_qs=None,
                           article_qs=ALL_ARTICLES,
                           template_name='recentchanges.html',
                           template_dir='wiki',
                           extra_context=None,
                           is_member=None,
                           is_private=None,
                           *args,
                           **kw):
    article_args = {'title': title}
    group = None
    if group_slug is not None:
        group = get_object_or_404(group_qs, **{group_slug_field: group_slug})
        article_args.update({
            'content_type': get_ct(group),
            'object_id': group.id
        })
        allow_read = has_read_perm(request.user, group, is_member, is_private)
    else:
        allow_read = True

    if not allow_read:
        return HttpResponseForbidden()

    article = get_object_or_404(article_qs, **article_args)

    if notification.is_observing(article, request.user):
        notification.stop_observing(article, request.user)

    return redirect(article)
Esempio n. 6
0
    def form_valid(self, form):
        form.instance.editor = self.request.user
        form.instance.last_status = self.last_status
        if not form.cleaned_data['watch'] and notification.is_observing(self.object, self.request.user):
            notification.stop_observing(self.object, self.request.user)
        elif form.cleaned_data['watch'] and not notification.is_observing(self.object, self.request.user):
            notification.observe(self.object, self.request.user, 'decision_change')

        return super(DecisionUpdate, self).form_valid(form)
Esempio n. 7
0
    def form_valid(self, form):
        form.instance.editor = self.request.user
        form.instance.last_status = self.last_status
        if not form.cleaned_data['watch'] and notification.is_observing(self.object, self.request.user):
            notification.stop_observing(self.object, self.request.user)
        elif form.cleaned_data['watch'] and not notification.is_observing(self.object, self.request.user):
            notification.observe(self.object, self.request.user, 'decision_change')

        return super(DecisionUpdate, self).form_valid(form)
Esempio n. 8
0
def stop_observing_article(request,
                           title,
                           group_slug=None,
                           bridge=None,
                           article_qs=ALL_ARTICLES,
                           template_name='recentchanges.html',
                           template_dir='wiki',
                           extra_context=None,
                           is_member=None,
                           is_private=None,
                           *args,
                           **kw):
    if request.method == 'POST':

        article_args = {'title': title}
        group = None
        if group_slug is not None:
            try:
                group = bridge.get_group(group_slug)
            except ObjectDoesNotExist:
                raise Http404
            article_args.update({
                'content_type': get_ct(group),
                'object_id': group.id
            })
            allow_read = has_read_perm(request.user, group, is_member,
                                       is_private)
        else:
            group = None
            allow_read = True
            article_args.update({'object_id': None})

        if not allow_read:
            return HttpResponseForbidden()

        article = get_object_or_404(article_qs, **article_args)

        notification.stop_observing(article, request.user)

        url = get_url('wiki_article',
                      group,
                      kw={
                          'title': article.title,
                      },
                      bridge=bridge)

        return redirect_to(request, url)
    return HttpResponseNotAllowed(['POST'])
Esempio n. 9
0
    def form_valid(self, form):
        form.instance.editor = self.request.user
        form.instance.last_status = self.last_status
        form.instance.minor_edit = form.cleaned_data['minor_edit']
        if (not form.cleaned_data['watch'] and
            notification.is_observing(self.object, self.request.user)):
            notification.stop_observing(self.object, self.request.user)
        elif (form.cleaned_data['watch'] and
              not notification.is_observing(self.object, self.request.user)):
            notification.observe(
                self.object,
                self.request.user,
                DECISION_CHANGE
            )

        return super(DecisionUpdate, self).form_valid(form)
Esempio n. 10
0
def project_toggle_watch(request, project_slug):
    """Add/Remove watches on a project for a specific user."""
    if request.method != 'POST':
        return json_error(_('Must use POST to activate'))

    if not settings.ENABLE_NOTICES:
        return json_error(_('Notification is not enabled'))

    project = get_object_or_404(Project, slug=project_slug)
    url = reverse('project_toggle_watch', args=(project_slug,))

    project_signals = ['project_changed',
                       'project_deleted',
                       'project_release_added',
                       'project_release_deleted',
                       'project_resource_added',
                       'project_resource_deleted']
    release_signals = ['project_release_changed',]

    resource_signals = ['project_resource_changed']
    try:
        result = {
            'style': 'watch_add',
            'title': _('Watch this project'),
            'project': True,
            'url': url,
            'error': None,
        }

        for signal in project_signals:
            try:
                notification.stop_observing(project, request.user, signal)
            except notification.ObservedItem.MultipleObjectsReturned, e:
                notification.ObservedItem.objects.filter(user=request.user,
                        signal=signal, content_type__model='project',
                        object_id = project.id).delete()
        for release in project.releases.all():
            for signal in release_signals:
                try:
                    notification.stop_observing(release, request.user, signal)
                except notification.ObservedItem.MultipleObjectsReturned, e:
                    notification.ObservedItem.objects.filter(user=request.user,
                        signal=signal, content_type__model='release',
                        object_id = release.id).delete()
Esempio n. 11
0
def project_toggle_watch(request, project_slug):
    """Add/Remove watches on a project for a specific user."""
    if request.method != 'POST':
        return json_error(_('Must use POST to activate'))

    if not settings.ENABLE_NOTICES:
        return json_error(_('Notification is not enabled'))

    project = get_object_or_404(Project, slug=project_slug)
    url = reverse('project_toggle_watch', args=(project_slug,))

    project_signals = ['project_changed',
                       'project_deleted',]
    try:
        result = {
            'style': 'watch_add',
            'title': _('Watch this project'),
            'project': True,
            'url': url,
            'error': None,
        }

        for signal in project_signals:
            notification.stop_observing(project, request.user, signal)

    except notification.ObservedItem.DoesNotExist:
        try:
            result = {
                'style': 'watch_remove',
                'title': _('Stop watching this project'),
                'project': True,
                'url': url,
                'error': None,
            }

            for signal in project_signals:
                notification.observe(project, request.user, signal, signal)

        except WatchException, e:
            return json_error(e.message, result)
Esempio n. 12
0
def stop_observing_article(request, title,
                           group_slug=None, bridge=None,
                           article_qs=ALL_ARTICLES,
                           template_name='recentchanges.html',
                           template_dir='wiki',
                           extra_context=None,
                           is_member=None,
                           is_private=None,
                           *args, **kw):
    if request.method == 'POST':

        article_args = {'title': title}
        group = None
        if group_slug is not None:
            try:
                group = bridge.get_group(group_slug)
            except ObjectDoesNotExist:
                raise Http404
            article_args.update({'content_type': get_ct(group),
                                 'object_id': group.id})
            allow_read = has_read_perm(request.user, group, is_member,
                                       is_private)
        else:
            group = None
            allow_read = True
            article_args.update({'object_id': None})

        if not allow_read:
            return HttpResponseForbidden()

        article = get_object_or_404(article_qs, **article_args)

        notification.stop_observing(article, request.user)
        
        url = get_url('wiki_article', group, kw={
            'title': article.title,
        }, bridge=bridge)
        
        return redirect_to(request, url)
    return HttpResponseNotAllowed(['POST'])
Esempio n. 13
0
File: views.py Progetto: liup/ohort
def stop_observing_topic(request, topic_id,
                           group_slug=None, bridge=None,
                           topic_qs=ALL_TOPICS,
                           template_name='recentchanges.html',
                           template_dir='forums',
                           extra_context=None,
                           is_member=None,
                           is_private=None,
                           *args, **kw):
    if request.method == 'POST':
        topic_args = {'id': topic_id}
        group = None
        if group_slug is not None:
            try:
                group = bridge.get_group(group_slug)
            except ObjectDoesNotExist:
                raise Http404
            topic_args.update({'content_type': get_ct(group),
                                 'object_id': group.id})
            allow_read = has_read_perm(request.user, group, is_member,
                                       is_private)
        else:
            group = None
            allow_read = True
            topic_args.update({'object_id': None})

        if not allow_read:
            return HttpResponseForbidden()

        topic = get_object_or_404(topic_qs, **topic_args)

        notification.stop_observing(topic, request.user)
        
        url = get_url('forums_topic', group, kw={
            'topic_id': topic.id,
        }, bridge=bridge)
        
        return redirect_to(request, url)
    return HttpResponseNotAllowed(['POST'])
Esempio n. 14
0
def unsubscribe_user(user, feedback):
    """
    Unsubscribe a user to any change of a given feedback
    """
    if notification.is_observing(feedback, user, signal='feedback_updated'):
        notification.stop_observing(feedback, user, 'feedback_updated')
Esempio n. 15
0
def resource_translation_toggle_watch(request, project_slug, resource_slug, language_code):
    """Add/Remove a TranslationWatch for a specific user."""

    if request.method != 'POST':
        return json_error(_('Must use POST to activate'))

    if not settings.ENABLE_NOTICES:
        return json_error(_('Notification is not enabled'))

    resource = get_object_or_404(Resource, slug=resource_slug,
                                project__slug=project_slug)
    project = resource.project
    language = get_object_or_404(Language, code=language_code)
    team = Team.objects.get_or_none(project, language_code)

    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not \
        check.maintain(project) and not \
        request.user.has_perm('watches.add_translationwatch') and not \
        request.user.has_perm('watches.delete_translationwatch'):
        return permission_denied(request)

    url = reverse('resource_translation_toggle_watch', args=(project_slug,
        resource_slug, language_code))

    try:
        twatch = TranslationWatch.objects.get(resource=resource,
            language=language)

        result = {
            'style': 'watch_add',
            'title': _('Watch it'),
            'id': twatch.id,
            'url': url,
            'error': None,
        }

        notification.stop_observing(twatch, request.user,
            signal='project_resource_translation_changed')

    except (TranslationWatch.DoesNotExist,
        notification.ObservedItem.DoesNotExist):

        try:
            twatch = TranslationWatch.objects.get_or_create(resource=resource,
                language=language)[0]

            result = {
                'style': 'watch_remove',
                'title': _('Stop watching'),
                'id': twatch.id,
                'url': url,
                'error': None,
            }

            notification.observe(twatch, request.user,
                'project_resource_translation_changed',
                signal='project_resource_translation_changed')

        except WatchException, e:
            return json_error(e.message, result)
Esempio n. 16
0
 def get(self, request, *args, **kwargs):
     decision = self.get_object()
     user = self.get_user()
     if notification.is_observing(decision, user):
         notification.stop_observing(decision, user)
     return HttpResponseRedirect(request.GET['next'])
Esempio n. 17
0
            except notification.ObservedItem.MultipleObjectsReturned, e:
                notification.ObservedItem.objects.filter(user=request.user,
                        signal=signal, content_type__model='project',
                        object_id = project.id).delete()
        for release in project.releases.all():
            for signal in release_signals:
                try:
                    notification.stop_observing(release, request.user, signal)
                except notification.ObservedItem.MultipleObjectsReturned, e:
                    notification.ObservedItem.objects.filter(user=request.user,
                        signal=signal, content_type__model='release',
                        object_id = release.id).delete()
        for resource in project.resources.all():
            for signal in resource_signals:
                try:
                    notification.stop_observing(resource, request.user, signal)
                except notification.ObservedItem.MultipleObjectsReturned, e:
                    notification.ObservedItem.objects.filter(user=request.user,
                        signal=signal, content_type__model='resource',
                        object_id=resource.id).delete()

    except notification.ObservedItem.DoesNotExist:
        try:
            result = {
                'style': 'watch_remove',
                'title': _('Stop watching this project'),
                'project': True,
                'url': url,
                'error': None,
            }