Exemple #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)
Exemple #2
0
def widget_news_social(request, response_format='html'):
    "Widget: Social Activity"

    profile = request.user.get_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 #3
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)
Exemple #4
0
def widget_news_social(request, response_format='html'):
    "Widget: Social Activity"

    profile = request.user.get_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 #5
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)
Exemple #6
0
def project_view(request, project_id, response_format='html'):
    "Single project view page"
    
    project = get_object_or_404(Project, pk=project_id)
    if not request.user.get_profile().has_permission(project):
        return user_denied(request, message="You don't have access to this Project") 
   
    query = Q(parent__isnull=True, project=project)
    if request.GET:
        if 'status' in request.GET and request.GET['status']:
            query = query & _get_filter_query(request.GET)
        else:
            query = query & Q(status__hidden=False) & _get_filter_query(request.GET)
    else:
        query = query & Q(status__hidden=False)

    if request.user.get_profile().has_permission(project, mode='r'):
        if request.POST:
            record = UpdateRecord()
            record.record_type = 'manual'
            form = TaskRecordForm(request.user.get_profile(), request.POST, instance=record)
            if form.is_valid():
                record = form.save()
                record.set_user_from_request(request)
                record.save()
                record.about.add(project)
                project.set_last_updated()
                return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
        else:
            form = TaskRecordForm(request.user.get_profile())
    else:
        form = None
    
    tasks = Object.filter_by_request(request, Task.objects.filter(query))

    tasks_progress = float(0)
    tasks_progress_query = Object.filter_by_request(request, Task.objects.filter(Q(parent__isnull=True, project=project)))
    if tasks_progress_query:
        for task in tasks_progress_query:
            if not task.status.active:
                tasks_progress += 1
        tasks_progress = (tasks_progress / len(tasks_progress_query)) * 100
        tasks_progress = round(tasks_progress, ndigits=1)
    
    filters = FilterForm(request.user.get_profile(), 'project', request.GET)
    
    milestones = Object.filter_by_request(request, 
                                          Milestone.objects.filter(project=project).filter(status__hidden=False))
    subprojects = Project.objects.filter(parent=project)
    
    context = _get_default_context(request)
    context.update({'project': project,
                    'milestones': milestones,
                    'tasks':tasks,
                    'tasks_progress':tasks_progress,
                    'record_form':form,
                    'subprojects':subprojects,
                    'filters': filters})
    return render_to_response('projects/project_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
def task_view(request, task_id, response_format='html'):
    "Single task view page"

    task = get_object_or_404(Task, pk=task_id)
    if not request.user.get_profile().has_permission(task):
        return user_denied(request, message="You don't have access to this Task")

    if request.user.get_profile().has_permission(task, mode='x'):
        if request.POST:
            if 'add-work' in request.POST:
                return HttpResponseRedirect(reverse('projects_task_time_slot_add', args=[task.id]))
            elif 'start-work' in request.POST:
                return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
            record = UpdateRecord()
            record.record_type = 'manual'
            form = TaskRecordForm(
                request.user.get_profile(), request.POST, instance=record)
            if form.is_valid():
                record = form.save()
                record.set_user_from_request(request)
                record.save()
                record.about.add(task)
                task.set_last_updated()
                return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        else:
            form = TaskRecordForm(request.user.get_profile())
    else:
        form = None

    subtasks = Object.filter_by_request(
        request, Task.objects.filter(parent=task))
    time_slots = Object.filter_by_request(
        request, TaskTimeSlot.objects.filter(task=task))

    context = _get_default_context(request)
    context.update({'task': task,
                    'subtasks': subtasks,
                    'record_form': form,
                    'time_slots': time_slots})

    if 'massform' in context and 'project' in context['massform'].fields:
        del context['massform'].fields['project']

    return render_to_response('projects/task_view', context,
                              context_instance=RequestContext(request), response_format=response_format)