Beispiel #1
0
def statistics(request):

    user = request.user
    active_projects = Project.objects.get_projects_for_user(user, status='A')
    projects = []
    for project in active_projects:
        if checkperm(PERMISSIONS_MESSAGE_VIEW, user, project ):
            nummessages = project.message_set.count()
        else:
            nummessages = -1
        if checkperm(PERMISSIONS_TODO_VIEW, user, project ):
            numtodos = project.todolist_set.count()
        else:
            numtodos = -1
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project ):
            nummilestones = project.milestone_set.count()
        else:
            nummilestones = -1
        if checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project ):
            numwikiboards = project.wiki_set.count()
        else:
            numwikiboards = -1
        if checkperm(PERMISSIONS_FILE_VIEW, user, project ):
            numfiles = project.file_set.count()
        else:
            numfiles = -1

        data={'project': project, 'messages': nummessages,
              'todos': numtodos, 'milestones': nummilestones,
              'wikiboards': numwikiboards, 'files': numfiles, }
        projects.append( data )

    return render_to_response('dashboard/statistics.html',
                              {'projects': projects},
                              context_instance = RequestContext(request))
Beispiel #2
0
def get_overview(user, project):
    """
    only get object user can view
    """
    if checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project ):
        wikiboards = WikiEntry.objects.filter(wiki__project = project, wiki__project__status='A').order_by('-creation_date')
        wikiboards_ids = [(wiki_object.creation_date, 'wikiboards_%s' % wiki_object.id) for wiki_object in wikiboards[:50]]
    else:
        wikiboards_ids = []

    if checkperm(PERMISSIONS_MESSAGE_VIEW, user, project ):
        messages = Message.objects.filter(project = project, project__status='A').extra(where=['message_message.initial_message_id = message_message.id']).order_by('-creation_date')
        messages_ids = [(message_object.creation_date, 'messages_%s' % message_object.id) for message_object in messages[:50]]
    else:
        messages_ids = []

    if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project ):
        milestones = Milestone.objects.filter(project = project, project__status='A', completion_date__isnull = True).order_by('-creation_date')
        milestones_ids = [(milestone_object.creation_date, 'milestones_%s' % milestone_object.id) for milestone_object in milestones[:50]]

        completemilestones = Milestone.objects.filter(project = project, project__status='A', completion_date__isnull = False).order_by('-completion_date')
        completemilestones_ids = [(milestone_object.completion_date, 'completemilestones_%s' % milestone_object.id) for milestone_object in completemilestones[:50]]
    else:
        milestones_ids = completemilestones_ids = []

    if checkperm(PERMISSIONS_FILE_VIEW, user, project ):
        files = FileVersion.objects.filter(file__project = project, file__project__status='A').order_by('-creation_date')
        files_ids = [(file_object.creation_date, 'files_%s' % file_object.id) for file_object in files[:50]]
    else:
        files_ids = []

    if checkperm(PERMISSIONS_TODO_VIEW, user, project ):
        todos = ToDo.objects.filter(todo_list__project = project, todo_list__project__status='A', completion_date__isnull = True).order_by('-creation_date')
        todos_ids = [(todo.creation_date, 'todos_%s' % todo.id) for todo in todos[:50]]

        completetodos = ToDo.objects.filter(todo_list__project = project, todo_list__project__status='A', completion_date__isnull = False).order_by('-completion_date')
        completetodos_ids = [(todo.completion_date, 'completetodos_%s' % todo.id) for todo in completetodos[:50]]
    else:
        todos_ids = completetodos_ids = []

    all_events = messages_ids + milestones_ids + completemilestones_ids + wikiboards_ids + files_ids + todos_ids + completetodos_ids
    all_events.sort()
    all_events.reverse()
    sorted_events = []
    for event in all_events:
        object = eval('%s.get(id = %s)' % tuple(event[1].split('_')))
        try:
            if object.completion_date:
                setattr(object, 'overview_date', object.completion_date.date)
            else:
                setattr(object, 'overview_date', object.creation_date.date)
        except AttributeError:
            setattr(object, 'overview_date', object.creation_date.date)
        sorted_events.append(object)
    return sorted_events
Beispiel #3
0
def delete(request, p_id, m_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    message = get_object_or_404(Message, pk=m_id)
    project.check_user_in_project_or_404(user)

    if not checkperm(PERMISSIONS_MESSAGE_EDITDELETE, user, project,
                     message) or message.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    kw = {'m_id': message.initial_message.id, 'p_id': project.id}

    events_log(user, 'D', message.title, message)

    if message.initial_message == message:  #delete main thread
        Message.objects.filter(
            initial_message=message.initial_message).delete()
    else:
        message.delete()

    request.user.message_set.create(message=_("Message Deleted."))

    page = request.GET.get('page')
    if page == 'msg':
        return HttpResponseRedirect(
            urlresolvers.reverse('rancho.message.views.read_add_comment',
                                 kwargs=kw))
    else:
        return HttpResponseRedirect(
            urlresolvers.reverse('rancho.message.views.list',
                                 args=[project.id]))
Beispiel #4
0
def save_changes(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id = p_id)

    if request.method == 'POST':
        todo = get_object_or_404(ToDo, id = int(request.POST.get('todo')))
        todo_list = todo.todo_list

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project, todo) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        responsible_id = int(request.POST.get('responsible'))
        if responsible_id:
            responsible = get_object_or_404(User, id = responsible_id)
        else:
            responsible = None
        description = request.POST.get('description')
        todo.responsible = responsible
        if description:
            todo.description = description
        todo.save()

        events_log(user, 'U', todo.description, todo)

        result = loader.get_template('todo/display_todo.html').render(Context({'todo': todo}))
        return HttpResponse(result, mimetype='text/xml')
    return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
Beispiel #5
0
def switch_todo_status(request, p_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    if request.method=='GET':
        todo = get_object_or_404(ToDo, id=int(request.GET.get('todo')))

        if not checkperm(PERMISSIONS_TODO_VIEW, user, project):
            return HttpResponseForbidden(_('Forbidden Access'))

        if todo.completion_date != None:
            todo.completion_date = None

            events_log(user, 'ICOMP', todo.description, todo)
        else:
            todo.completion_date = datetime.datetime.now()
            todo.responsible = user

            events_log(user, 'COMP', todo.description, todo)

        todo.save()
        milestone = todo.todo_list.milestone
        if milestone:
            if todo.todo_list.is_complete():
                todo.todo_list.milestone.completion_date = todo.completion_date
                todo.todo_list.milestone.responsible = user
            else:
                todo.todo_list.milestone.completion_date = None
            todo.todo_list.milestone.save()
        result = loader.get_template('todo/display_todo.html').render(Context({'todo':todo}))
        return HttpResponse(result, mimetype='text/xml')
    else:
        return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
Beispiel #6
0
def edit_todo_list(request, p_id, todo_list_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    edit_todo_list = get_object_or_404(ToDoList, id = todo_list_id)

    if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project, edit_todo_list)  or edit_todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

    context = {'todo_list': edit_todo_list, 'project': project}
    milestones = [(milestone.id, milestone.title) for milestone \
                  in edit_todo_list.get_free_milestones()]
    milestones = [(0, _("None"))] + milestones
    if request.method == 'POST':
        data = request.POST.copy()
        edit_todo_list_form = EditToDoListForm(milestones, data)
        context['edit_todo_list_form'] = edit_todo_list_form
        if edit_todo_list_form.is_valid():
            edit_todo_list_form.save_with_form_data(edit_todo_list)
            events_log(user, 'U', edit_todo_list.title, edit_todo_list)
            request.user.message_set.create(message=_('ToDo list successfully updated.'))

        return render_to_response('todo/edit_todo_list.html',
                                  context,
                                  context_instance=RequestContext(request))
    milestone_id = 0
    if edit_todo_list.milestone:
        milestone_id = edit_todo_list.milestone.id
    data = {'todolist_name': edit_todo_list.title,
            'todolist_description': edit_todo_list.description,
            'milestone': milestone_id}
    edit_todo_list_form = EditToDoListForm(milestones, data)
    context['edit_todo_list_form'] = edit_todo_list_form
    return render_to_response('todo/edit_todo_list.html', context,
                              context_instance=RequestContext(request))
Beispiel #7
0
def list(request,p_id, tag=None):
    '''
    List all messages from a project
    '''

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    #Get all the messages, except the ones that are comments
    if tag:
        tag = "\"%s\""%tag
        messagelist = TaggedItem.objects.get_by_model(Message, tag)
    else:
        messagelist = Message.objects
    messagelist = messagelist.filter(project=project).extra(where=['message_message.initial_message_id = message_message.id']).order_by('-creation_date')

    message_tags = Tag.objects.cloud_for_model(Message, steps=6, filters=dict(project=project))

    context = {'project': project,
               'users_in_project': users_in_project,
               'message_tags': message_tags,
               'messagelist': messagelist }
    return render_to_response('message/message_list.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #8
0
def view_page(request, p_id, entry_id, entry_version):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project, None):
        return HttpResponseForbidden(_('Forbidden Access'))

    wiki = get_object_or_404(Wiki, id=entry_id)
    wikicurentry = get_object_or_404(WikiEntry, id=entry_version)
    wiki_entries = WikiEntry.objects.filter(
        wiki=wiki).order_by('-creation_date')

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'wiki': wiki,
        'wikicurentry': wikicurentry,
        'wiki_entries': wiki_entries
    }

    return render_to_response('wikiboard/view.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #9
0
def create(request, p_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)

    if not checkperm(PERMISSIONS_TODO_CREATE, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    context = {}
    context['users_in_project'] = users_in_project
    context['project'] = project
    project.check_user_in_project_or_404(user)
    milestones = Milestone.objects.filter(project = project)
    milestones = [(milestone.id, milestone.title) for milestone \
                  in milestones if milestone.todolist == None]
    milestones = [(0, _("None"))] + milestones
    newTDLform = NewToDoListForm(milestones)
    if request.method=='POST':
        newTDLform = NewToDoListForm(milestones, request.POST)
        if newTDLform.is_valid():
            context['project'] = project
            todo_list = newTDLform.save(user, project)
            events_log(user, 'A', todo_list.title, todo_list)
            request.user.message_set.create(message=_('ToDo list "%(todo_list_name)s" successfully created.') % {'todo_list_name': todo_list.title})
            return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
    context['newTDLform'] = newTDLform
    return render_to_response('todo/new_todo_list.html', context,
                              context_instance=RequestContext(request))
Beispiel #10
0
def view_file(request, p_id, file_id):
    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()
    file = get_object_or_404(File, id=file_id)

    if not checkperm(PERMISSIONS_FILE_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    file_list = []
    file_version_list = []
    versions = FileVersion.objects.filter(file=file).order_by('-creation_date')
    index = versions.count()
    for file_version in versions:
        file_name = str(_remove_ids_from_file(file_version.file_location))
        file_version_list.append((index, file_name, file_version))
        index -= 1
    file_list.append((file, file_version_list))

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'files': file_list,
        'media_path':
        'http://' + request.META['HTTP_HOST'] + settings.MEDIA_URL + 'icons/',
        'view_alone': True
    }
    return render_to_response('file/list_file.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #11
0
def switch_todo_status(request, p_id):

    user = request.user
    project = get_object_or_404(Project, id=p_id)
    if request.method == 'GET':
        todo = get_object_or_404(ToDo, id=int(request.GET.get('todo')))

        if not checkperm(PERMISSIONS_TODO_VIEW, user, project):
            return HttpResponseForbidden(_('Forbidden Access'))

        if todo.completion_date != None:
            todo.completion_date = None

            events_log(user, 'ICOMP', todo.description, todo)
        else:
            todo.completion_date = datetime.datetime.now()
            todo.responsible = user

            events_log(user, 'COMP', todo.description, todo)

        todo.save()
        milestone = todo.todo_list.milestone
        if milestone:
            if todo.todo_list.is_complete():
                todo.todo_list.milestone.completion_date = todo.completion_date
                todo.todo_list.milestone.responsible = user
            else:
                todo.todo_list.milestone.completion_date = None
            todo.todo_list.milestone.save()
        result = loader.get_template('todo/display_todo.html').render(
            Context({'todo': todo}))
        return HttpResponse(result, mimetype='text/xml')
    else:
        return HttpResponseRedirect(
            urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
Beispiel #12
0
def new_upload(request, p_id, f_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    file = get_object_or_404(File, pk=f_id)

    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_FILE_CREATE, user,
                     project) or file.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)

    if request.method == 'POST':
        form = UploadFileForm(tags, request.POST, request.FILES)
        if form.is_valid():
            form.save(user, file)

            link_url = u"http://%s%s" % (
                unicode(Site.objects.get_current()),
                urlresolvers.reverse('rancho.file.views.view_file',
                                     kwargs={
                                         'p_id': project.id,
                                         'file_id': file.id
                                     }),
            )
            notification.send(
                file.notify_to.all(), "fileversion_new", {
                    'link_url':
                    link_url,
                    'file':
                    file,
                    'file_name':
                    os.path.basename(
                        file.last_file_version.file_location.path).split(
                            '_', 2)[-1]
                })

            events_log(user, 'U', file.title, file)
            request.user.message_set.create(
                message=_("New file revision created"))

            return HttpResponseRedirect(
                urlresolvers.reverse('rancho.file.views.list',
                                     args=[project.id]))
    else:
        form = UploadFileForm(tags)

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'file': file,
        'form': form,
    }

    return render_to_response('file/new_upload.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #13
0
def save_changes(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    if request.method == 'POST':
        todo = get_object_or_404(ToDo, id=int(request.POST.get('todo')))
        todo_list = todo.todo_list

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project,
                         todo) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        responsible_id = int(request.POST.get('responsible'))
        if responsible_id:
            responsible = get_object_or_404(User, id=responsible_id)
        else:
            responsible = None
        description = request.POST.get('description')
        todo.responsible = responsible
        if description:
            todo.description = description
        todo.save()

        events_log(user, 'U', todo.description, todo)

        result = loader.get_template('todo/display_todo.html').render(
            Context({'todo': todo}))
        return HttpResponse(result, mimetype='text/xml')
    return HttpResponseRedirect(
        urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
Beispiel #14
0
def get_events(request, year, month, day):
    user = request.user
    import datetime
    from django.db.models import Q
    event_date = datetime.date(int(year), int(month), int(day))
    milestone_list = []
    milestones = Milestone.objects.filter(Q(responsible=None)
                                          | Q(responsible=user),
                                          due_date__year=year,
                                          due_date__month=month,
                                          due_date__day=day,
                                          completion_date=None)
    for milestone in milestones:
        project = milestone.project
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            milestone_list.append(milestone)
    if not milestone_list:
        return Http404()
    context = Context({
        'user': user,
        'milestone_list': milestone_list,
        'event_date': event_date
    })
    result = loader.get_template('cal/show_events.html').render(context)
    return HttpResponse(result, mimetype='text/xml')
Beispiel #15
0
def delete(request,p_id,m_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    message = get_object_or_404(Message, pk=m_id)
    project.check_user_in_project_or_404(user)

    if not checkperm(PERMISSIONS_MESSAGE_EDITDELETE, user, project, message ) or message.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))


    kw = {'m_id': message.initial_message.id, 'p_id': project.id}

    events_log(user, 'D', message.title, message)

    if message.initial_message == message: #delete main thread
        Message.objects.filter(initial_message=message.initial_message).delete()
    else:
        message.delete()

    request.user.message_set.create(message=_("Message Deleted."))

    page = request.GET.get('page')
    if page == 'msg':
        return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs=kw))
    else:
        return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.list', args=[project.id]))
Beispiel #16
0
def create(request, p_id):

    user = request.user
    project = get_object_or_404(Project, id=p_id)

    if not checkperm(PERMISSIONS_TODO_CREATE, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    context = {}
    context['users_in_project'] = users_in_project
    context['project'] = project
    project.check_user_in_project_or_404(user)
    milestones = Milestone.objects.filter(project=project)
    milestones = [(milestone.id, milestone.title) for milestone \
                  in milestones if milestone.todolist == None]
    milestones = [(0, _("None"))] + milestones
    newTDLform = NewToDoListForm(milestones)
    if request.method == 'POST':
        newTDLform = NewToDoListForm(milestones, request.POST)
        if newTDLform.is_valid():
            context['project'] = project
            todo_list = newTDLform.save(user, project)
            events_log(user, 'A', todo_list.title, todo_list)
            request.user.message_set.create(
                message=_(
                    'ToDo list "%(todo_list_name)s" successfully created.') %
                {'todo_list_name': todo_list.title})
            return HttpResponseRedirect(
                urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
    context['newTDLform'] = newTDLform
    return render_to_response('todo/new_todo_list.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #17
0
def read_add_comment(request,p_id,m_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    message = get_object_or_404(Message, pk=m_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_VIEW, user, project ) or message.project != project :
        return HttpResponseForbidden(_('Forbidden Access'))

    #if not initial message redirect to id
    if message.initial_message != message:
        return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':message.initial_message.id}))

    message.read_by.add(user)

    if request.method == 'POST':
        if not checkperm(PERMISSIONS_MESSAGE_CREATE, user, project ) or message.project != project :
            return HttpResponseForbidden(_('Forbidden Access'))

        form=CommentForm(request.POST)
        if form.is_valid():
            msg = form.save(user, project, message, True)

            message.read_by.clear()

            link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),)
            notification.send(msg.initial_message.notify_to.all(), "message_replied", {'link_url': link_url, 'message': msg })

            return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'m_id': message.id, 'p_id': project.id}))
    else:
        form = CommentForm()



    context = {'project': project,
               'message': message,
               'users_in_project': users_in_project,
               'original_message': message.initial_message,
               'allmessages': Message.objects.filter(initial_message=message.initial_message).exclude(id=message.id).order_by('-creation_date'),
               'form': form }
    return render_to_response("message/read_message.html", context,
                              context_instance=RequestContext(request))
Beispiel #18
0
def edit(request, p_id, milestone_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    milestone = get_object_or_404(Milestone, id = milestone_id)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MILESTONE_EDITDELETE, user, project, milestone) or milestone.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MILESTONE_VIEW)

    if request.method=='POST':
        form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_to_notify), request.POST)

        if form.is_valid():

            user_id = int(form.cleaned_data['responsible'])
            if user_id != 0:
                milestone.responsible = get_object_or_404(User, id = user_id)
            else:
                milestone.responsible = None
                milestone.completion_date = None
            old_milestone_title = milestone.title
            milestone.title = form.cleaned_data['title']
            milestone.due_date = form.cleaned_data['due_date']
            milestone.send_notification_email = form.cleaned_data['send_notification_email']
            milestone.save()

            if milestone.send_notification_email:
                link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.milestone.views.list', args = [p_id]))
                #link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),)
                if milestone.responsible: #just notify one person
                    notification.send([milestone.responsible], "milestone_updated", {'link_url': link_url, 'milestone': milestone, 'old_milestone_title': old_milestone_title})
                else: #notify entire project
                    notification.send(users_to_notify, "milestone_updated", {'link_url': link_url, 'milestone': milestone, 'old_milestone_title': old_milestone_title })

            events_log(user, 'U', milestone.title, milestone)
            request.user.message_set.create(message=_('Milestone successfully edited.'))
    else:
        responsible_index = 0
        if milestone.responsible:
            responsible_index = milestone.responsible.id
        data = {'title': milestone.title,
                'due_date': milestone.due_date.date(),
                'responsible': responsible_index,
                'send_notification_email': milestone.send_notification_email}
        form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_in_project), data)

    context = {'project': project,
               'milestone': milestone,
               'newMilestone': form,
               }
    return render_to_response("milestone/edit_milestone.html", context, context_instance = RequestContext(request))
Beispiel #19
0
def edit(request, p_id, m_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    message = get_object_or_404(Message, pk=m_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_EDITDELETE, user, project,
                     message) or message.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)

    if request.method == 'POST':
        if message.initial_message == message:
            form = MessageForm(project.get_users(), tags, request.POST)
        else:
            form = CommentForm(request.POST)

        if form.is_valid():
            form.save(user, project, message)
            events_log(user, 'U', message.title, message)

            if message.initial_message == message:
                return HttpResponseRedirect(
                    urlresolvers.reverse('rancho.message.views.list',
                                         args=[project.id]))
            else:
                return HttpResponseRedirect(
                    urlresolvers.reverse(
                        'rancho.message.views.read_add_comment',
                        kwargs={
                            'p_id': project.id,
                            'm_id': message.initial_message.id
                        }))
    else:
        data = {'title': message.title, 'message': message.body}
        if message.initial_message == message:
            data['tags'] = message.tags
            form = MessageForm(project.get_users(), tags, data)
        else:
            form = CommentForm(data)

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'form': form,
        'edit_initial': isinstance(form, MessageForm),
        'message': message
    }
    return render_to_response("message/edit_message.html",
                              context,
                              context_instance=RequestContext(request))
Beispiel #20
0
def delete(request, p_id, milestone_id):
    user = request.user
    project = get_object_or_404(Project, id = p_id)
    milestone = get_object_or_404(Milestone, id = milestone_id)

    if not checkperm(PERMISSIONS_MILESTONE_EDITDELETE, user, project, milestone) or milestone.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    request.user.message_set.create(message=_('Milestone "%s" successfully deleted.') % milestone.title)
    events_log(user, 'D', milestone.title, milestone)
    milestone.delete()
    return HttpResponseRedirect(urlresolvers.reverse('rancho.milestone.views.list', args = [p_id]))
Beispiel #21
0
def create(request, p_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_CREATE, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    if request.method == 'POST':
        form = NewWikiEntryForm(project, request.POST)
        if form.is_valid():

            #TODO: put in form save
            wiki = Wiki()
            wiki.project = project
            wiki.creator = user
            wiki.name = form.cleaned_data['wiki_name']
            wiki.save()

            wikientry = WikiEntry()
            wikientry.content = form.cleaned_data['content']
            wikientry.author = user
            wikientry.wiki = wiki
            wikientry.save()
            wiki.last_version = wikientry
            wiki.save()

            events_log(user, 'A', wiki.name, wikientry)
            request.user.message_set.create(
                message=_('Wikiboard "%s" was successfully created.') %
                wiki.name)

            kw = {
                'p_id': project.id,
                'entry_id': wiki.id,
                'entry_version': wikientry.id
            }
            return HttpResponseRedirect(
                urlresolvers.reverse('rancho.wikiboard.views.view_page',
                                     kwargs=kw))
    else:
        form = NewWikiEntryForm(project)

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'form': form
    }
    return render_to_response("wikiboard/create_entry.html",
                              context,
                              context_instance=RequestContext(request))
Beispiel #22
0
def statistics(request):

    user = request.user
    active_projects = Project.objects.get_projects_for_user(user, status='A')
    projects = []
    for project in active_projects:
        if checkperm(PERMISSIONS_MESSAGE_VIEW, user, project):
            nummessages = project.message_set.count()
        else:
            nummessages = -1
        if checkperm(PERMISSIONS_TODO_VIEW, user, project):
            numtodos = project.todolist_set.count()
        else:
            numtodos = -1
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            nummilestones = project.milestone_set.count()
        else:
            nummilestones = -1
        if checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project):
            numwikiboards = project.wiki_set.count()
        else:
            numwikiboards = -1
        if checkperm(PERMISSIONS_FILE_VIEW, user, project):
            numfiles = project.file_set.count()
        else:
            numfiles = -1

        data = {
            'project': project,
            'messages': nummessages,
            'todos': numtodos,
            'milestones': nummilestones,
            'wikiboards': numwikiboards,
            'files': numfiles,
        }
        projects.append(data)

    return render_to_response('dashboard/statistics.html',
                              {'projects': projects},
                              context_instance=RequestContext(request))
Beispiel #23
0
def create(request, p_id):
    '''
    Creates a new message
    '''
    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_CREATE, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)

    users_to_notify = utils.get_users_to_notify(project,
                                                PERMISSIONS_MESSAGE_VIEW)

    if request.method == 'POST':
        form = MessageForm(users_to_notify, tags, request.POST)
        if form.is_valid():
            msg = form.save(user, project)

            link_url = u"http://%s%s" % (
                unicode(Site.objects.get_current()),
                urlresolvers.reverse('rancho.message.views.read_add_comment',
                                     kwargs={
                                         'p_id': project.id,
                                         'm_id': msg.id
                                     }),
            )
            notification.send(msg.notify_to.all(), "message_new", {
                'link_url': link_url,
                'message': msg
            })

            request.user.message_set.create(message=_("Message Created"))
            events_log(user, 'A', msg.title, msg)
            return HttpResponseRedirect(
                urlresolvers.reverse('rancho.message.views.list',
                                     args=[project.id]))
    else:
        form = MessageForm(users_to_notify, tags)

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'form': form
    }
    return render_to_response("message/new_message.html",
                              context,
                              context_instance=RequestContext(request))
Beispiel #24
0
def list(request, p_id, tag=None):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_FILE_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    #Get all the files (consider tag filter)
    if tag:
        tag = "\"%s\"" % tag
        files = TaggedItem.objects.get_by_model(File, tag)
    else:
        files = File.objects
    files = files.filter(project=project).order_by('-id')

    file_list = []
    for file in files:
        file_version_list = []
        versions = FileVersion.objects.filter(
            file=file).order_by('-creation_date')
        index = versions.count()
        for file_version in versions:
            #TODO: ROCHA: this is ugly... think about cleaning please
            file_name = str(_remove_ids_from_file(file_version.file_location))
            file_version_list.append((index, file_name, file_version))
            index -= 1
        file_list.append((file, file_version_list))

    file_tags = Tag.objects.cloud_for_model(File,
                                            steps=6,
                                            filters=dict(project=project))

    context = {
        'project':
        project,
        'users_in_project':
        users_in_project,
        'files':
        file_list,
        'file_tags':
        file_tags,
        'media_path':
        'http://' + request.META['HTTP_HOST'] + settings.MEDIA_URL + 'icons/',
    }
    return render_to_response('file/list_file.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #25
0
def edit(request, p_id,entry_id=None,entry_version=None):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if entry_id and entry_version:
        wiki = get_object_or_404(Wiki, pk=entry_id)
        wikicurentry = get_object_or_404(WikiEntry, id=entry_version)

        if not checkperm(PERMISSIONS_WIKIBOARD_CREATE, user, project, wiki ) or wiki.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))


    if request.method=='POST':
        tinyMceForm = TinyMceForm(request.POST)
        if tinyMceForm.is_valid():

            wikientry = WikiEntry()
            wikientry.content = tinyMceForm.cleaned_data['content']
            wikientry.author = user
            wikientry.wiki = wiki
            wikientry.save()
            wiki.last_version = wikientry
            wiki.save()

            events_log(user, 'U', wiki.name, wikientry)

            request.user.message_set.create(message=_('Wikiboard "%s" was successfully updated.') % wiki.name)
            kw = {'p_id': project.id, 'entry_id': wiki.id, 'entry_version': wikientry.id}
            return HttpResponseRedirect(urlresolvers.reverse('rancho.wikiboard.views.view_page', kwargs=kw))

    else:
        if wiki:
            data = {'content': wikicurentry.content}
        else:
            data = {}

        tinyMceForm = TinyMceForm(data)

    context = {'project': project,
               'users_in_project': users_in_project,
               'wiki': wiki,
               'wikicurentry': wikicurentry,
               'wiki_entrys': WikiEntry.objects.filter(wiki=wiki).order_by('-creation_date'),
               'form': tinyMceForm }
    return render_to_response("wikiboard/edit_entry.html", context,
                              context_instance=RequestContext(request))
Beispiel #26
0
def milestones(request):

    user = request.user
    active_projects = Project.objects.get_projects_for_user(user, status='A')
    projects = []
    for project in active_projects:
        if not checkperm(PERMISSIONS_MILESTONE_VIEW, user, project ):
            continue
        upcoming_milestones = Milestone.objects.get_upcoming_milestones(project = project, user = user)
        late_milestones = Milestone.objects.get_late_milestones(project = project, user = user)
        if upcoming_milestones or late_milestones:
            projects.append({'project': project, 'late_milestones': late_milestones, 'upcoming_milestones': upcoming_milestones})
    return render_to_response('dashboard/milestones.html',
                              {'projects': projects},
                              context_instance = RequestContext(request))
Beispiel #27
0
def send_file(request, p_id, v_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    file_version = get_object_or_404(FileVersion, pk=v_id)

    if not checkperm(PERMISSIONS_FILE_VIEW, user,
                     project) or file_version.file.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    filepath = os.path.join(settings.MEDIA_ROOT,
                            file_version.file_location.name)
    realfilename = file_version.file_location.name.split('_', 2)[-1]
    return utils.send_file(filepath, realfilename)
Beispiel #28
0
def delete(request,p_id,entry_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    wiki = get_object_or_404(Wiki, pk=entry_id)
    project.check_user_in_project_or_404(user)

    if not checkperm(PERMISSIONS_WIKIBOARD_EDITDELETE, user, project, wiki ) or wiki.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    events_log(user, 'D', wiki.name, wiki)
    user.message_set.create(message = _('The Wikiboard "%s" has been successfully deleted.') % wiki.name)
    wiki.delete()

    return HttpResponseRedirect(urlresolvers.reverse('rancho.wikiboard.views.list', args=[p_id]))
Beispiel #29
0
def add_todo(request, p_id, todo_list):
    user = request.user
    project = get_object_or_404(Project, id = p_id)
    todo_list = get_object_or_404(ToDoList, id = todo_list)

    if not checkperm(PERMISSIONS_TODO_CREATE, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    if request.method == 'GET':
        try:
            todo_desc = request.GET.get('todo_desc')
            todo_responsible = int(request.GET.get('todo_responsible'))
        except:
            return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
        if not todo_desc:
            result = """<taconite>
                            <show select="#empty_todo_error{{ todo_list }}"/>
                        </taconite>"""
            result = loader.get_template_from_string(result).render(Context({'todo_list': todo_list.id}))
            return HttpResponse(result, mimetype='text/xml')
        if todo_responsible:
            todo_responsible = get_object_or_404(User, pk = todo_responsible)
        todo = ToDo()
        todo.creator = user
        if todo_responsible != 0:
            todo.responsible = todo_responsible
        todo.description = todo_desc
        todo.todo_list = todo_list
        todo.save()
        todo_list.number_of_todos+=1
        todo_list.save()
        todo.position = todo_list.number_of_todos + 1
        todo.save()

        events_log(user, 'A', todo.description, todo)

        #notify all users with perm
        link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.todo.views.view_todo_list', kwargs={'p_id': project.id, 'todo_list_id': todo_list.id}),)
        if todo.responsible: #just notify one person
            notification.send([todo.responsible], "todo_new", {'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list})
        else: #notify all users with perm
            users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_TODO_VIEW)
            notification.send(users_to_notify, "todo_new", {'link_url': link_url, 'todo': todo, 'project': project, 'todo_list': todo_list})

        context = Context({'todo_list': todo_list.id, 'user': user,
                           'todo': todo, 'project': project})
        result = loader.get_template('todo/add_todo.html').render(context)
        return HttpResponse(result, mimetype='text/xml')
Beispiel #30
0
def delete_todo_list(request, p_id):

    #TODOS: Need to delete todo in todo list
    user = request.user
    project = get_object_or_404(Project, id = p_id)
    if request.method == 'GET':
        todo_list = get_object_or_404(ToDoList, id = int(request.GET.get('todo_list')))

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project, todo_list) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        request.user.message_set.create(message=_('ToDo list "%(todo_list_name)s" deleted.') % {'todo_list_name': todo_list.title})
        todo_list.delete()

        events_log(user, 'D', todo_list.title, todo_list)
    return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
Beispiel #31
0
def export_wiki(request,p_id,entry_id,entry_version, file_type):
    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)

    wiki = get_object_or_404(Wiki, id=entry_id)
    wikicurentry = get_object_or_404(WikiEntry, id=entry_version)

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    text  = u"<h1>%s</h1> %s"%(wiki.name,wikicurentry.content)
    html = u"""
<html>
<style>
@page {
   margin: 1cm;
   @frame footer {
     -pdf-frame-content: footerContent;
     bottom: 1cm;
     margin-left: 1cm;
     margin-right: 1cm;
     height: 1cm;
     text-align: center;
   }
}
</style>
<body>
  %s
  <div id="footerContent"  align="right">
     <pdf:pagenumber>
  </div>
</body>
</html>
"""%text

    if file_type == 'pdf':
        result = StringIO()
        pdf = pisa.pisaDocument(StringIO(html.encode("ISO-8859-1")), result)
        if not pdf.err:
            return HttpResponse(result.getvalue(), mimetype='application/pdf')
        return HttpResponseServerError(_('Could not generate pdf file.'))

    elif file_type == 'html':
        response = HttpResponse(mimetype='text/html')
        response.write(html)
        return response
Beispiel #32
0
def export_wiki(request, p_id, entry_id, entry_version, file_type):
    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)

    wiki = get_object_or_404(Wiki, id=entry_id)
    wikicurentry = get_object_or_404(WikiEntry, id=entry_version)

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    text = u"<h1>%s</h1> %s" % (wiki.name, wikicurentry.content)
    html = u"""
<html>
<style>
@page {
   margin: 1cm;
   @frame footer {
     -pdf-frame-content: footerContent;
     bottom: 1cm;
     margin-left: 1cm;
     margin-right: 1cm;
     height: 1cm;
     text-align: center;
   }
}
</style>
<body>
  %s
  <div id="footerContent"  align="right">
     <pdf:pagenumber>
  </div>
</body>
</html>
""" % text

    if file_type == 'pdf':
        result = StringIO()
        pdf = pisa.pisaDocument(StringIO(html.encode("ISO-8859-1")), result)
        if not pdf.err:
            return HttpResponse(result.getvalue(), mimetype='application/pdf')
        return HttpResponseServerError(_('Could not generate pdf file.'))

    elif file_type == 'html':
        response = HttpResponse(mimetype='text/html')
        response.write(html)
        return response
Beispiel #33
0
def get_events(request, year, month, day):
    user = request.user
    import datetime
    from django.db.models import Q
    event_date = datetime.date(int(year), int(month), int(day))
    milestone_list = []
    milestones = Milestone.objects.filter(Q(responsible = None) | Q(responsible = user), due_date__year = year, due_date__month = month, due_date__day = day, completion_date = None)
    for milestone in milestones:
        project = milestone.project
        if checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            milestone_list.append(milestone)
    if not milestone_list:
        return Http404()
    context = Context({'user': user, 'milestone_list': milestone_list,
                       'event_date': event_date})
    result = loader.get_template('cal/show_events.html').render(context)
    return HttpResponse(result, mimetype='text/xml')
Beispiel #34
0
def incomplete(request, p_id, milestone_id):
    user = request.user
    project = get_object_or_404(Project, id = p_id)
    milestone = get_object_or_404(Milestone, id = milestone_id)
    if not checkperm(PERMISSIONS_MILESTONE_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))
    if milestone.completion_date:
        milestone.completion_date = None
        # PERMISSIONS
        if milestone.todolist:
            for todo in milestone.todolist.get_todos():
                todo.responsible = user
                todo.completion_date = None
                todo.save()
        milestone.save()
        events_log(user, 'ICOMP', milestone.title, milestone)
    return HttpResponseRedirect(urlresolvers.reverse('rancho.milestone.views.list', args = [p_id]))
Beispiel #35
0
def edit(request,p_id,m_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    message = get_object_or_404(Message, pk=m_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_EDITDELETE, user, project, message ) or message.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)

    if request.method == 'POST':
        if message.initial_message == message:
            form=MessageForm(project.get_users(), tags, request.POST)
        else:
            form=CommentForm(request.POST)

        if form.is_valid():
            form.save(user, project, message)
            events_log(user, 'U', message.title, message)

            if message.initial_message == message:
                return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.list', args=[project.id]))
            else:
                return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id': message.initial_message.id}))
    else:
        data = {'title':message.title,
                'message':message.body
                }
        if message.initial_message == message:
            data['tags'] = message.tags
            form=MessageForm(project.get_users(), tags, data)
        else:
            form=CommentForm(data)

    context = {'project': project,
               'users_in_project': users_in_project,
               'form': form,
               'edit_initial': isinstance(form, MessageForm),
               'message': message
                }
    return render_to_response("message/edit_message.html", context,
                              context_instance=RequestContext(request))
Beispiel #36
0
def delete_todo(request, p_id):

    #TODOS: Need to delete todo in todo list
    user = request.user
    project = get_object_or_404(Project, id = p_id)
    if request.method == 'GET':
        todo_item = get_object_or_404(ToDo, id = int(request.GET.get('todo')))
        todo_list = todo_item.todo_list

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project, todo_item) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        todo_item.delete()
        events_log(user, 'D', todo_item.description, todo_item)

        return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
    else:
        return HttpResponseRedirect(urlresolvers.reverse('rancho.todo.views.list', args = [p_id]))
Beispiel #37
0
def view_todo_list(request, p_id, todo_list_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    todo_list = get_object_or_404(ToDoList, id = todo_list_id)

    if not checkperm(PERMISSIONS_TODO_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    context = {
               'users_in_project': utils.format_users_for_dropdown(user, users_in_project),
               'project': project,
               'todo_lists': [(todo_list, todo_list.get_todos())],
               'view_alone': True,
               }
    return render_to_response('todo/todos_list.html', context,
                              context_instance = RequestContext(request))
Beispiel #38
0
def delete(request, p_id, entry_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    wiki = get_object_or_404(Wiki, pk=entry_id)
    project.check_user_in_project_or_404(user)

    if not checkperm(PERMISSIONS_WIKIBOARD_EDITDELETE, user, project,
                     wiki) or wiki.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    events_log(user, 'D', wiki.name, wiki)
    user.message_set.create(
        message=_('The Wikiboard "%s" has been successfully deleted.') %
        wiki.name)
    wiki.delete()

    return HttpResponseRedirect(
        urlresolvers.reverse('rancho.wikiboard.views.list', args=[p_id]))
Beispiel #39
0
def list(request, p_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    wikis = Wiki.objects.filter(project=project).order_by('-last_version')


    context = {'project': project,
               'users_in_project': users_in_project,
               'wikis': wikis }
    return render_to_response('wikiboard/list_wiki.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #40
0
def create(request, p_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_CREATE, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))


    if request.method=='POST':
        form = NewWikiEntryForm(project, request.POST)
        if form.is_valid():

            #TODO: put in form save
            wiki = Wiki()
            wiki.project = project
            wiki.creator = user
            wiki.name = form.cleaned_data['wiki_name']
            wiki.save()

            wikientry = WikiEntry()
            wikientry.content = form.cleaned_data['content']
            wikientry.author = user
            wikientry.wiki = wiki
            wikientry.save()
            wiki.last_version = wikientry
            wiki.save()

            events_log(user, 'A', wiki.name, wikientry)
            request.user.message_set.create(message=_('Wikiboard "%s" was successfully created.') % wiki.name)

            kw = {'p_id': project.id, 'entry_id': wiki.id, 'entry_version': wikientry.id}
            return HttpResponseRedirect(urlresolvers.reverse('rancho.wikiboard.views.view_page', kwargs=kw))
    else:
        form = NewWikiEntryForm(project)

    context = {'project': project,
               'users_in_project': users_in_project,
               'form': form }
    return render_to_response("wikiboard/create_entry.html", context,
                              context_instance=RequestContext(request))
Beispiel #41
0
def list(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id = p_id)

    if not checkperm(PERMISSIONS_TODO_VIEW, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    todo_list = ToDoList.objects.filter(project = project)
    context = {
        'users_in_project': utils.format_users_for_dropdown(user, users_in_project),
        'project': project,
        'todo_lists': [],
        }
    for l in todo_list:
        context['todo_lists'].append((l, l.get_todos()))


    return render_to_response('todo/todos_list.html', context,
                              context_instance = RequestContext(request))
Beispiel #42
0
def list(request, p_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    wikis = Wiki.objects.filter(project=project).order_by('-last_version')

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'wikis': wikis
    }
    return render_to_response('wikiboard/list_wiki.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #43
0
def view_todo_list(request, p_id, todo_list_id):

    user = request.user
    project = get_object_or_404(Project, id=p_id)
    todo_list = get_object_or_404(ToDoList, id=todo_list_id)

    if not checkperm(PERMISSIONS_TODO_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    context = {
        'users_in_project':
        utils.format_users_for_dropdown(user, users_in_project),
        'project': project,
        'todo_lists': [(todo_list, todo_list.get_todos())],
        'view_alone': True,
    }
    return render_to_response('todo/todos_list.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #44
0
def edit_todo(request, p_id, todo_id):

    user = request.user
    project = get_object_or_404(Project, id=p_id)
    todo = get_object_or_404(ToDo, id=todo_id)
    todo_list = todo.todo_list

    if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project,
                     todo) or todo_list.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = utils.format_users_for_dropdown(user,
                                                       project.get_users())
    context = {'project': project, 'todo': todo, 'todo_list': todo_list}
    if request.method == 'POST':
        edit_todo_form = EditToDoForm(users_in_project, request.POST)
        context['edit_todo_form'] = edit_todo_form
        if edit_todo_form.is_valid():
            user_id = int(edit_todo_form.cleaned_data['responsible'])
            if user_id != 0:
                todo.responsible = get_object_or_404(User, id=user_id)
            else:
                todo.responsible = None
            todo.description = edit_todo_form.cleaned_data['title']
            todo.save()

            events_log(user, 'U', todo.description, todo)
            request.user.message_set.create(
                message=_('ToDo item successfully updated.'))
        return render_to_response('todo/edit_todo.html',
                                  context,
                                  context_instance=RequestContext(request))
    responsible_index = 0
    if todo.responsible:
        responsible_index = todo.responsible.id
    data = {'title': todo.description, 'responsible': responsible_index}
    edit_todo_form = EditToDoForm(users_in_project, data)
    context['edit_todo_form'] = edit_todo_form
    return render_to_response('todo/edit_todo.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #45
0
def list(request, p_id):
    user = request.user
    project = get_object_or_404(Project, id=p_id)

    if not checkperm(PERMISSIONS_TODO_VIEW, user, project):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = project.get_users()
    todo_list = ToDoList.objects.filter(project=project)
    context = {
        'users_in_project':
        utils.format_users_for_dropdown(user, users_in_project),
        'project': project,
        'todo_lists': [],
    }
    for l in todo_list:
        context['todo_lists'].append((l, l.get_todos()))

    return render_to_response('todo/todos_list.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #46
0
def milestones(request):

    user = request.user
    active_projects = Project.objects.get_projects_for_user(user, status='A')
    projects = []
    for project in active_projects:
        if not checkperm(PERMISSIONS_MILESTONE_VIEW, user, project):
            continue
        upcoming_milestones = Milestone.objects.get_upcoming_milestones(
            project=project, user=user)
        late_milestones = Milestone.objects.get_late_milestones(
            project=project, user=user)
        if upcoming_milestones or late_milestones:
            projects.append({
                'project': project,
                'late_milestones': late_milestones,
                'upcoming_milestones': upcoming_milestones
            })
    return render_to_response('dashboard/milestones.html',
                              {'projects': projects},
                              context_instance=RequestContext(request))
Beispiel #47
0
def delete_todo_list(request, p_id):

    #TODOS: Need to delete todo in todo list
    user = request.user
    project = get_object_or_404(Project, id=p_id)
    if request.method == 'GET':
        todo_list = get_object_or_404(ToDoList,
                                      id=int(request.GET.get('todo_list')))

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project,
                         todo_list) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        request.user.message_set.create(
            message=_('ToDo list "%(todo_list_name)s" deleted.') %
            {'todo_list_name': todo_list.title})
        todo_list.delete()

        events_log(user, 'D', todo_list.title, todo_list)
    return HttpResponseRedirect(
        urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
Beispiel #48
0
def delete_todo(request, p_id):

    #TODOS: Need to delete todo in todo list
    user = request.user
    project = get_object_or_404(Project, id=p_id)
    if request.method == 'GET':
        todo_item = get_object_or_404(ToDo, id=int(request.GET.get('todo')))
        todo_list = todo_item.todo_list

        if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project,
                         todo_item) or todo_list.project != project:
            return HttpResponseForbidden(_('Forbidden Access'))

        todo_item.delete()
        events_log(user, 'D', todo_item.description, todo_item)

        return HttpResponseRedirect(
            urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
    else:
        return HttpResponseRedirect(
            urlresolvers.reverse('rancho.todo.views.list', args=[p_id]))
Beispiel #49
0
def edit_todo_list(request, p_id, todo_list_id):

    user = request.user
    project = get_object_or_404(Project, id=p_id)
    edit_todo_list = get_object_or_404(ToDoList, id=todo_list_id)

    if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project,
                     edit_todo_list) or edit_todo_list.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    context = {'todo_list': edit_todo_list, 'project': project}
    milestones = [(milestone.id, milestone.title) for milestone \
                  in edit_todo_list.get_free_milestones()]
    milestones = [(0, _("None"))] + milestones
    if request.method == 'POST':
        data = request.POST.copy()
        edit_todo_list_form = EditToDoListForm(milestones, data)
        context['edit_todo_list_form'] = edit_todo_list_form
        if edit_todo_list_form.is_valid():
            edit_todo_list_form.save_with_form_data(edit_todo_list)
            events_log(user, 'U', edit_todo_list.title, edit_todo_list)
            request.user.message_set.create(
                message=_('ToDo list successfully updated.'))

        return render_to_response('todo/edit_todo_list.html',
                                  context,
                                  context_instance=RequestContext(request))
    milestone_id = 0
    if edit_todo_list.milestone:
        milestone_id = edit_todo_list.milestone.id
    data = {
        'todolist_name': edit_todo_list.title,
        'todolist_description': edit_todo_list.description,
        'milestone': milestone_id
    }
    edit_todo_list_form = EditToDoListForm(milestones, data)
    context['edit_todo_list_form'] = edit_todo_list_form
    return render_to_response('todo/edit_todo_list.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #50
0
def create(request, p_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MILESTONE_CREATE, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MILESTONE_VIEW)

    if request.method == 'POST':
        form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_to_notify), request.POST)

        if form.is_valid():
            mstone = form.save(user, project)

            if mstone.send_notification_email:
                #TODO: make a view milestone url to use here
                link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.milestone.views.list', args = [p_id]))
                #link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),)
                if mstone.responsible: #just notify one person
                    notification.send([mstone.responsible], "milestone_new", {'link_url': link_url, 'milestone': mstone })
                else: #notify all users with perm
                    notification.send(users_to_notify, "milestone_new", {'link_url': link_url, 'milestone': mstone })

            events_log(user, 'A', mstone.title, mstone)
            request.user.message_set.create(message=_('Milestone "%s" successfully created.') % mstone.title)
            return HttpResponseRedirect(urlresolvers.reverse('rancho.milestone.views.list', args = [p_id]))

    else:
        form = NewMilestoneForm(utils.format_users_for_dropdown(user, users_in_project))

    context = { 'project': project,
               'newMilestone': form,
               }

    return render_to_response("milestone/create_milestone.html", context,
                                  context_instance=RequestContext(request))
Beispiel #51
0
def edit(request, p_id, v_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    file_version = get_object_or_404(FileVersion, pk=v_id)

    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_FILE_EDITDELETE, user, project,
                     file_version) or file_version.file.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)
    if request.method == 'POST':
        form = FileVersionForm(tags, request.POST)
        if form.is_valid():
            form.save(file_version)
            return HttpResponseRedirect(
                urlresolvers.reverse('rancho.file.views.list',
                                     args=[project.id]))
    else:
        form = FileVersionForm(
            tags, {
                'tags': file_version.file.tags,
                'description': file_version.description
            })

    context = {
        'project': project,
        'users_in_project': users_in_project,
        'form': form,
        'file_version': file_version,
        'title': file_version.file.title,
    }

    return render_to_response('file/edit_version.html',
                              context,
                              context_instance=RequestContext(request))
Beispiel #52
0
def delete(request, p_id, v_id):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    file_version = get_object_or_404(FileVersion, pk=v_id)

    if not checkperm(PERMISSIONS_FILE_EDITDELETE, user, project,
                     file_version) or file_version.file.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    #delete all versions if main or delete just one
    if file_version.file.last_file_version == file_version:
        FileVersion.objects.filter(file=file_version.file).delete()
        File.objects.filter(id=file_version.file.id).delete()

        events_log(user, 'D', file_version.file.title, file_version.file)
    else:
        file_version.delete()
    request.user.message_set.create(message=_('File successfully deleted'))
    return HttpResponseRedirect(
        urlresolvers.reverse('rancho.file.views.list', args=[project.id]))
Beispiel #53
0
def edit_todo(request, p_id, todo_id):

    user = request.user
    project = get_object_or_404(Project, id = p_id)
    todo = get_object_or_404(ToDo, id = todo_id)
    todo_list = todo.todo_list

    if not checkperm(PERMISSIONS_TODO_EDITDELETE, user, project, todo) or todo_list.project != project:
        return HttpResponseForbidden(_('Forbidden Access'))

    users_in_project = utils.format_users_for_dropdown(user, project.get_users())
    context = {'project': project, 'todo': todo, 'todo_list': todo_list}
    if request.method == 'POST':
        edit_todo_form = EditToDoForm(users_in_project, request.POST)
        context['edit_todo_form'] = edit_todo_form
        if edit_todo_form.is_valid():
            user_id = int(edit_todo_form.cleaned_data['responsible'])
            if user_id != 0:
                todo.responsible = get_object_or_404(User, id = user_id)
            else:
                todo.responsible = None
            todo.description = edit_todo_form.cleaned_data['title']
            todo.save()

            events_log(user, 'U', todo.description, todo)
            request.user.message_set.create(message=_('ToDo item successfully updated.'))
        return render_to_response('todo/edit_todo.html', context,
                      context_instance=RequestContext(request))
    responsible_index = 0
    if todo.responsible:
        responsible_index = todo.responsible.id
    data = {'title': todo.description, 'responsible': responsible_index}
    edit_todo_form = EditToDoForm(users_in_project, data)
    context['edit_todo_form'] = edit_todo_form
    return render_to_response('todo/edit_todo.html', context,
                          context_instance=RequestContext(request))
Beispiel #54
0
def create(request,p_id):
    '''
    Creates a new message
    '''
    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_MESSAGE_CREATE, user, project ):
        return HttpResponseForbidden(_('Forbidden Access'))

    tags = utils.get_site_tags(project)

    users_to_notify = utils.get_users_to_notify(project, PERMISSIONS_MESSAGE_VIEW)

    if request.method == 'POST':
        form = MessageForm(users_to_notify,tags, request.POST)
        if form.is_valid():
            msg = form.save(user, project)

            link_url = u"http://%s%s" % ( unicode(Site.objects.get_current()), urlresolvers.reverse('rancho.message.views.read_add_comment', kwargs={'p_id': project.id, 'm_id':msg.id}),)
            notification.send(msg.notify_to.all(), "message_new", {'link_url': link_url, 'message': msg })

            request.user.message_set.create(message=_("Message Created"))
            events_log(user, 'A', msg.title, msg)
            return HttpResponseRedirect(urlresolvers.reverse('rancho.message.views.list', args=[project.id]))
    else:
        form = MessageForm(users_to_notify, tags)

    context = {'project': project,
               'users_in_project': users_in_project,
               'form': form }
    return render_to_response("message/new_message.html", context,
                              context_instance=RequestContext(request)
                              )
Beispiel #55
0
def view_page(request, p_id,entry_id,entry_version):

    user = request.user
    project = get_object_or_404(Project, pk=p_id)
    project.check_user_in_project_or_404(user)
    users_in_project = project.get_users()

    if not checkperm(PERMISSIONS_WIKIBOARD_VIEW, user, project, None ):
        return HttpResponseForbidden(_('Forbidden Access'))


    wiki = get_object_or_404(Wiki, id=entry_id)
    wikicurentry = get_object_or_404(WikiEntry, id=entry_version)
    wiki_entries = WikiEntry.objects.filter(wiki=wiki).order_by('-creation_date')

    context = {'project': project,
               'users_in_project': users_in_project,
               'wiki': wiki,
               'wikicurentry': wikicurentry,
               'wiki_entries':wiki_entries }

    return render_to_response('wikiboard/view.html',
                              context,
                              context_instance=RequestContext(request))