Exemple #1
0
def index(request, response_format='html'):
    "Default index page"

    profile = request.user.profile
    query = _get_filter_query(profile, filters=request.GET)
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index'))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=_('All Activity'),
                          link=request.path,
                          description=_('Updates on activity in your Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({'form': form,
                    'updates': updates,
                    'profile': profile})

    return render_to_response('news/index', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #2
0
def widget_news_index(request, response_format='html'):
    "Widget: All Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & (
        ~Q(author=profile) | Q(record_type='share') | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    # don't do updates if social widget is used
    if Widget.objects.filter(user=profile, widget_name='widget_news_social').exists():
        form = None

    else:
        if request.POST:
            record = UpdateRecord()
            record.record_type = 'share'
            form = UpdateRecordForm(
                request.POST, user=profile, instance=record)
            if form.is_valid():
                record = form.save()
                record.body = record.body.replace('\n', ' <br />')
                record.save()
                record.set_user_from_request(request)
                return HttpResponseRedirect(reverse('core_dashboard_index'))
        else:
            form = UpdateRecordForm(user=profile)

    context = _get_default_context(request)
    context.update({'form': form,
                    'updates': updates,
                    'profile': profile})

    return render_to_response('news/widgets/index', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #3
0
def widget_news_social(request, response_format='html'):
    "Widget: Social Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & Q(record_type='share')
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('core_dashboard_index'))
    else:
        form = UpdateRecordForm(user=profile)

    context = _get_default_context(request)
    context.update({'form': form,
                    'updates': updates,
                    'profile': profile})

    return render_to_response('news/widgets/social', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #4
0
def my_watchlist(request, response_format='html'):
    "Displays news about all objects a User is subscribed to"

    profile = request.user.profile
    query = _get_filter_query(profile, do_recipients=False, filters=request.GET) & Q(
        about__in=profile.subscriptions.all()) & ~Q(author=profile)
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save(commit=False)
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index'))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=_('My Watchlist'),
                          link=request.path,
                          description=_(
                              'Updates on your watchlist in Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({'form': form,
                    'updates': updates,
                    'profile': profile})

    return render_to_response('news/my_watchlist', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #5
0
def index_by_module(request, module_name, response_format='html'):
    "Default index page"

    profile = request.user.profile
    try:
        module = profile.get_perspective().get_modules().filter(
            name__icontains=module_name)[0]
    except:
        raise Http404('No such module in your Perspective')
    query = _get_filter_query(profile, filters=request.GET) & Q(
        about__object_type__icontains=module_name) & (~Q(author=profile) | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index_by_module', filters=[module_name]))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=(_(module.title) + ' ' + _('Activity')),
                          link=request.path,
                          description=_('Updates on activity in your Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({'form': form,
                    'active_module': module,
                    'updates': updates,
                    'profile': profile,
                    'module_name': module_name})

    return render_to_response('news/index_by_module', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #6
0
def index(request, response_format='html'):
    "Default index page"

    profile = request.user.profile
    query = _get_filter_query(profile, filters=request.GET)
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index'))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=_('All Activity'),
                          link=request.path,
                          description=_('Updates on activity in your Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({'form': form, 'updates': updates, 'profile': profile})

    return render_to_response('news/index',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemple #7
0
def widget_news_social(request, response_format='html'):
    "Widget: Social Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & Q(record_type='share')
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('core_dashboard_index'))
    else:
        form = UpdateRecordForm(user=profile)

    context = _get_default_context(request)
    context.update({'form': form, 'updates': updates, 'profile': profile})

    return render_to_response('news/widgets/social',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemple #8
0
def my_watchlist(request, response_format='html'):
    "Displays news about all objects a User is subscribed to"

    profile = request.user.profile
    query = _get_filter_query(
        profile, do_recipients=False, filters=request.GET) & Q(
            about__in=profile.subscriptions.all()) & ~Q(author=profile)
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save(commit=False)
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(reverse('news_index'))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=_('My Watchlist'),
                          link=request.path,
                          description=_('Updates on your watchlist in Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({'form': form, 'updates': updates, 'profile': profile})

    return render_to_response('news/my_watchlist',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemple #9
0
def index_by_module(request, module_name, response_format='html'):
    "Default index page"

    profile = request.user.profile
    try:
        module = profile.get_perspective().get_modules().filter(
            name__icontains=module_name)[0]
    except:
        raise Http404('No such module in your Perspective')
    query = _get_filter_query(profile, filters=request.GET) & Q(
        about__object_type__icontains=module_name) & (~Q(author=profile)
                                                      | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    if request.POST:
        record = UpdateRecord()
        record.record_type = 'share'
        form = UpdateRecordForm(request.POST, user=profile, instance=record)
        if form.is_valid():
            record = form.save()
            record.body = record.body.replace('\n', ' <br />')
            record.save()
            record.set_user_from_request(request)
            return HttpResponseRedirect(
                reverse('news_index_by_module', filters=[module_name]))
    else:
        form = UpdateRecordForm(user=profile)

    if response_format == 'rss':
        return ObjectFeed(title=(_(module.title) + ' ' + _('Activity')),
                          link=request.path,
                          description=_('Updates on activity in your Anaf'),
                          objects=updates)(request)

    context = _get_default_context(request)
    context.update({
        'form': form,
        'active_module': module,
        'updates': updates,
        'profile': profile,
        'module_name': module_name
    })

    return render_to_response('news/index_by_module',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Exemple #10
0
def widget_news_index(request, response_format='html'):
    "Widget: All Activity"

    profile = request.user.profile
    query = _get_filter_query(profile) & (
        ~Q(author=profile) | Q(record_type='share') | Q(score__gt=0))
    updates = UpdateRecord.objects.filter(query).distinct()

    # don't do updates if social widget is used
    if Widget.objects.filter(user=profile,
                             widget_name='widget_news_social').exists():
        form = None

    else:
        if request.POST:
            record = UpdateRecord()
            record.record_type = 'share'
            form = UpdateRecordForm(request.POST,
                                    user=profile,
                                    instance=record)
            if form.is_valid():
                record = form.save()
                record.body = record.body.replace('\n', ' <br />')
                record.save()
                record.set_user_from_request(request)
                return HttpResponseRedirect(reverse('core_dashboard_index'))
        else:
            form = UpdateRecordForm(user=profile)

    context = _get_default_context(request)
    context.update({'form': form, 'updates': updates, 'profile': profile})

    return render_to_response('news/widgets/index',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)