Esempio n. 1
0
def index(request, response_format='html'):
    "Default index page"

    profile = request.user.get_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 Tree.io'),
                          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)
Esempio n. 2
0
def index_by_module(request, module_name, response_format='html'):
    "Default index page"

    profile = request.user.get_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 Tree.io'),
                          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)
Esempio n. 3
0
def my_watchlist(request, response_format='html'):
    "Displays news about all objects a User is subscribed to"

    profile = request.user.get_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 Tree.io'),
            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)