Ejemplo n.º 1
0
def weblink_delete(request, weblink_id, response_format='html'):
    "WebLink delete"
    
    link = get_object_or_404(WebLink, pk=weblink_id)
    
    if not request.user.get_profile().has_permission(link, mode='w'):
        return user_denied(request, message="You don't have access to this Web Link")
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                link.trash = True
                link.save()
            else:
                link.delete()
            return HttpResponseRedirect(reverse('document_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))
        
    context = _get_default_context(request)
    context.update({'link':link})
        
    return render_to_response('documents/weblink_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 2
0
def folder_delete(request, knowledgeType_id, response_format='html'):
    "Type delete"
     
    folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id)
    items = Object.filter_by_request(request, manager=KnowledgeItem.objects.filter(folder=folder))
    
    if not request.user.get_profile().has_permission(folder, mode='w'):
        return user_denied(request, message="You don't have access to this Knowledge Type")
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                folder.trash = True
                folder.save()
            else:
                folder.delete()
            return HttpResponseRedirect(reverse('knowledge_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
        
    context = _get_default_context(request)
    context.update({'items': items,
                    'folder':folder})
        
    return render_to_response('knowledge/folder_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 3
0
def category_edit(request, knowledgeCategory_id, response_format='html'):
    "Knowledge category edit page"
    category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
    items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r')
    
    if not request.user.get_profile().has_permission(category, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Category")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
    else:
        form = KnowledgeCategoryForm(instance=category)
        
    context = _get_default_context(request)
    context.update({'form': form, 
                    'category': category, 
                    'items':items})
        
    return render_to_response('knowledge/category_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 4
0
def task_time_slot_add(request, task_id, response_format='html'):
    "Time slot add to preselected task"
    
    task = get_object_or_404(Task, pk=task_id)
    if not request.user.get_profile().has_permission(task, mode='x'):
        return user_denied(request, message="You don't have access to this Task")
    
    if request.POST:
        task_time_slot = TaskTimeSlot(task=task, time_to=datetime.now(), user=request.user.get_profile())
        form = TaskTimeSlotForm(request.user.get_profile(), task_id, request.POST, instance=task_time_slot)
        if 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        elif form.is_valid():
            task_time_slot = form.save()
            task_time_slot.set_user_from_request(request)
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
    else:
        form = TaskTimeSlotForm(request.user.get_profile(), task_id)
    
    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({'form': form,
                    'task': task,
                    'subtasks': subtasks,
                    'time_slots': time_slots})
    
    return render_to_response('projects/task_time_add', context,
                               context_instance=RequestContext(request), response_format=response_format)  
Ejemplo n.º 5
0
def task_time_slot_delete(request, time_slot_id, response_format='html'):
    "Task time slot delete"

    task_time_slot = get_object_or_404(TaskTimeSlot, pk=time_slot_id)
    task = task_time_slot.task
    
    if not request.user.get_profile().has_permission(task_time_slot, mode='w') \
        and not request.user.get_profile().has_permission(task, mode='w'):
        return user_denied(request, message="You don't have access to this Task Time Slot")

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                task_time_slot.trash = True
                task_time_slot.save()
            else:
                task_time_slot.delete()
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
    
    context = _get_default_context(request)
    context.update({'task_time_slot': task_time_slot,
                    'task':task})
    
    return render_to_response('projects/task_time_delete', context,
                               context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 6
0
def milestone_delete(request, milestone_id, response_format='html'):
    "Milestone delete"

    milestone = get_object_or_404(Milestone, pk=milestone_id)
    project = milestone.project
    if not request.user.get_profile().has_permission(milestone, mode='w'):
        return user_denied(request, message="You don't have access to this Milestone")

    query = Q(milestone=milestone, parent__isnull=True)
    if request.GET:
        query = query & _get_filter_query(request.GET)
    tasks = Object.filter_by_request(request, Task.objects.filter(query))
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                milestone.trash = True
                milestone.save()
            else:
                milestone.delete()
            return HttpResponseRedirect(reverse('projects_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))

    context = _get_default_context(request)
    context.update({'milestone': milestone, 
                    'tasks': tasks,
                    'project':project})
    
    return render_to_response('projects/milestone_delete', context,
                               context_instance=RequestContext(request), response_format=response_format) 
Ejemplo n.º 7
0
def task_delete(request, task_id, response_format='html'):
    "Task delete"

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

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                task.trash = True
                task.save()
            else:
                task.delete()
            return HttpResponseRedirect(reverse('projects_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))

    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,
                    'time_slots': time_slots})
    
    return render_to_response('projects/task_delete', context,
                               context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 8
0
def field_edit(request, field_id, response_format='html'):
    "ItemField edit"
    
    field = get_object_or_404(ItemField, pk=field_id)
    if not request.user.get_profile().has_permission(field, mode='w'):
        return user_denied(request, message="You don't have access to this Field Type", 
                           response_format=response_format)
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_field_view', args=[item.id]))
    else:
        form = ItemFieldForm(instance=field)

    context = _get_default_context(request)
    context.update({'form': form,
                    'field': field})
    
    return render_to_response('infrastructure/field_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 9
0
def field_add(request, response_format='html'):
    "ItemField add"
    
    if not request.user.get_profile().is_admin('maker.infrastructure'):
        return user_denied(request, 
                           message="You don't have administrator access to the Infrastructure module", 
                           response_format=response_format)
    
    if request.POST:
        if not 'cancel' in request.POST:
            field = ItemField()
            form = ItemFieldForm(request.POST, instance=field)
            if form.is_valid():
                field = form.save(request)
                field.set_user_from_request(request)
                return HttpResponseRedirect(reverse('infrastructure_field_view', args=[field.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_settings_view'))
    else:
        form = ItemFieldForm()

    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('infrastructure/field_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 10
0
def report_group(request, report_id, field_name, response_format='html'):
    "View to Group by a given field in a report"
    
    t = get_object_or_404(Report, pk=report_id)
    if not request.user.get_profile().has_permission(t, mode='w'):
        return user_denied(request, message="You don't have access to this Report")

    model = loads(t.model)
    
    #Check if this field is already grouped, if so then remove grouping
    thisfield = model.get_field(field_name)
    if thisfield.groupby  == 1:
        thisfield.groupby = 0
    else:
        #Other wise reset grouping and set selected field as groupfield
        for field in model.fields:
            field.groupby = 0
        
        field = model.get_field(field_name)
        field.groupby = 1
        
    t.model = dumps(model)
    t.save()
        
    return report_edit(request, report_id=report_id, response_format=response_format)
Ejemplo n.º 11
0
def type_edit(request, type_id, response_format='html'):
    "ItemType edit"
    
    item_type = get_object_or_404(ItemType, pk=type_id)
    if not request.user.get_profile().has_permission(item_type, mode='w'):
        return user_denied(request, message="You don't have access to this Item Type", 
                           response_format=response_format)
    infrastructure = Object.filter_by_request(request, 
                                              Item.objects.filter(item_type=item_type).order_by('name'))
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemTypeForm(request.user.get_profile(), request.POST, instance=item_type)
            if form.is_valid():
                item_type = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_type_view', args=[item_type.id]))
    else:
        form = ItemTypeForm(request.user.get_profile(), instance=item_type)

    context = _get_default_context(request)
    context.update({'infrastructure': infrastructure,
                    'form': form,
                    'item_type': item_type})
    
    return render_to_response('infrastructure/item_type_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 12
0
def mlist_delete(request, mlist_id, response_format='html'):
    "Delete mlist page"
    
    mlist = get_object_or_404(MailingList, pk=mlist_id)
    if not request.user.get_profile().has_permission(mlist, mode="w"):
        return user_denied(request, message="You don't have access to this Mailing List", 
                           response_format=response_format)
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                mlist.trash = True
                mlist.save()
            else:
                mlist.delete()
            return HttpResponseRedirect('/messaging/')
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('messaging_mlist_view', args=[mlist.id]))
        
    context = _get_default_context(request)
    context.update({'mlist':mlist})

    return render_to_response('messaging/mlist_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 13
0
def stream_delete(request, stream_id, response_format='html'):
    "Delete stream page"
    
    stream = get_object_or_404(MessageStream, pk=stream_id)
    if not request.user.get_profile().has_permission(stream, mode="w"):
        return user_denied(request, message="You don't have access to this Stream", 
                           response_format=response_format)
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                stream.trash = True
                stream.save()
            else:
                stream.delete()
            return HttpResponseRedirect('/messaging/')
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id]))
        
    context = _get_default_context(request)
    context.update({'stream':stream})

    return render_to_response('messaging/stream_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 14
0
def stream_edit(request, stream_id, response_format='html'):
    "Stream edit page"
    user = request.user.get_profile()
    
    stream = get_object_or_404(MessageStream, pk=stream_id)
    if not request.user.get_profile().has_permission(stream, mode="w"):
        return user_denied(request, message="You don't have access to this Stream", 
                           response_format=response_format)
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = MessageStreamForm(user, request.POST, instance=stream)
            if form.is_valid():
                stream = form.save()
                return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id]))
        else:
            return HttpResponseRedirect(reverse('messaging_stream_view', args=[stream.id]))
    else:
        form = MessageStreamForm(user, instance=stream)
        
    context = _get_default_context(request)
    context.update({'form': form,
                    'stream':stream})
    
    return render_to_response('messaging/stream_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 15
0
def task_status_delete(request, status_id, response_format='html'):
    "TaskStatus delete"
    
    status = get_object_or_404(TaskStatus, pk=status_id)
    if not request.user.get_profile().has_permission(status, mode='w'):
        return user_denied(request, message="You don't have access to this Task Status")

    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                status.trash = True
                status.save()
            else:
                status.delete()
            return HttpResponseRedirect(reverse('projects_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_index_by_status', args=[status.id]))
    
    milestones = Object.filter_by_request(request, Milestone.objects)

    context = _get_default_context(request)
    context.update({'status':status,
                    'milestones':milestones})    
    
    return render_to_response('projects/status_delete', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 16
0
def status_edit(request, status_id, response_format='html'):
    "ItemStatus edit"
    
    item_status = get_object_or_404(ItemStatus, pk=status_id)
    if not request.user.get_profile().has_permission(item_status, mode='w'):
        return user_denied(request, message="You don't have access to this Item Status", 
                           response_format=response_format)
        
    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemStatusForm(request.POST, instance=item_status)
            if form.is_valid():
                item_status = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id]))
    else:
        form = ItemStatusForm(instance=item_status)
    
    context = _get_default_context(request)
    context.update({'item_status': item_status,
                    'form': form})
    
    return render_to_response('infrastructure/item_status_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 17
0
def milestone_edit(request, milestone_id, response_format='html'):
    "Milestone edit page"
    
    milestone = get_object_or_404(Milestone, pk=milestone_id)
    project = milestone.project
    if not request.user.get_profile().has_permission(milestone, mode='w'):
        return user_denied(request, message="You don't have access to this Milestone")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = MilestoneForm(request.user.get_profile(), None, request.POST, instance=milestone)
            if form.is_valid():
                milestone = form.save()
                return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
        else:
            return HttpResponseRedirect(reverse('projects_milestone_view', args=[milestone.id]))
    else:
        form = MilestoneForm(request.user.get_profile(), None, instance=milestone)

    context = _get_default_context(request)
    context.update({'form': form, 
                    'milestone': milestone,
                    'project':project})

    return render_to_response('projects/milestone_edit', context,
                               context_instance=RequestContext(request), response_format=response_format) 
Ejemplo n.º 18
0
def status_add(request, response_format='html'):
    "ItemStatus edit"
    
    if not request.user.get_profile().is_admin('maker.infrastructure'):
        return user_denied(request, message="You are not an Administrator of the Infrastructure module", 
                           response_format=response_format)
       
    if request.POST:
        if not 'cancel' in request.POST:
            item_status = ItemStatus()
            form = ItemStatusForm(request.POST, instance=item_status)
            if form.is_valid():
                item_status = form.save(request)
                item_status.set_user_from_request(request)
                return HttpResponseRedirect(reverse('infrastructure_status_view', args=[item_status.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_settings_view'))
    else:
        form = ItemStatusForm()
        
    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('infrastructure/item_status_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 19
0
def milestone_set_status(request, milestone_id, status_id, response_format='html'):
    "Milestone quick set: Status"

    milestone = get_object_or_404(Milestone, pk=milestone_id)
    if not request.user.get_profile().has_permission(milestone, mode='x'):
        return user_denied(request, message="You don't have access to this Milestone")

    status = get_object_or_404(TaskStatus, pk=status_id)
    if not request.user.get_profile().has_permission(status):
        return user_denied(request, message="You don't have access to this Milestone Status")

    if not milestone.status == status:
        milestone.status = status
        milestone.save()
    
    return milestone_view(request, milestone_id, response_format)
Ejemplo n.º 20
0
def item_add_typed(request, type_id, response_format='html'):
    "Item add with preselected type"
    
    item_type = get_object_or_404(ItemType, pk=type_id)
    if not request.user.get_profile().has_permission(item_type, mode='x'):
        return user_denied(request, message="You don't have access to create " + unicode(item_type), 
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemForm(request.user.get_profile(), item_type, request.POST, files=request.FILES)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_index'))
    else:
        form = ItemForm(request.user.get_profile(), item_type)
    
    context = _get_default_context(request)
    context.update({'item_type': item_type,
                    'form': form})
    
    return render_to_response('infrastructure/item_add_typed', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 21
0
def task_set_status(request, task_id, status_id, response_format='html'):
    "Task quick set: Status"

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

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

    if not task.status == status:
        task.status = status
        task.save()
    
    return task_view(request, task_id, response_format)
Ejemplo n.º 22
0
def item_edit(request, item_id, response_format='html'):
    "Item edit page"
    item = get_object_or_404(Item, pk=item_id)
    if not request.user.get_profile().has_permission(item, mode="w"):
        return user_denied(request, message="You don't have write access to this Item", 
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ItemForm(request.user.get_profile(), item.item_type, request.POST, 
                            files=request.FILES, instance=item)
            if form.is_valid():
                item = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
    else:
        form = ItemForm(request.user.get_profile(), item.item_type, instance=item)
    
    context = _get_default_context(request)
    context.update({'item': item,
                    'form': form })

    return render_to_response('infrastructure/item_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 23
0
def task_time_slot_edit(request, time_slot_id, response_format='html'):
    "Task time slot edit page"
    
    task_time_slot = get_object_or_404(TaskTimeSlot, pk=time_slot_id)
    task = task_time_slot.task
    
    if not request.user.get_profile().has_permission(task_time_slot, mode='w') \
        and not request.user.get_profile().has_permission(task, mode='w'):
        return user_denied(request, message="You don't have access to this Task Time Slot")
    
    if request.POST:
        form = TaskTimeSlotForm(request.user.get_profile(), None, request.POST, instance=task_time_slot)
        if form.is_valid():
            task_time_slot = form.save()
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
        
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('projects_task_view', args=[task.id]))
    else:
        form = TaskTimeSlotForm(request.user.get_profile(), None, instance=task_time_slot)

    context = _get_default_context(request)
    context.update({'form': form, 
                    'task_time_slot': task_time_slot,
                    'task':task})

    return render_to_response('projects/task_time_edit', context,
                               context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 24
0
def settings_view(request, response_format='html'):
    "Settings"
    
    if not request.user.get_profile().is_admin('maker.infrastructure'):
        return user_denied(request, message="You are not an Administrator of the Infrastructure module", 
                           response_format=response_format)
    
    item_types = ItemType.objects.all().filter(trash=False)
    item_statuses = ItemStatus.objects.all().filter(trash=False)
    item_fields = ItemField.objects.all().filter(trash=False)
    
    default_item_status = None
    try:
        conf = ModuleSetting.get_for_module('maker.infrastructure', 'default_item_status')[0]
        default_item_status = ItemStatus.objects.get(pk=long(conf.value), trash=False)
    except Exception:
        pass
        
    context = _get_default_context(request)
    context.update({'item_types': item_types,
                    'item_fields': item_fields,
                    'item_statuses': item_statuses,
                    'default_item_status': default_item_status})
    
    return render_to_response('infrastructure/settings_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 25
0
def folder_edit(request, knowledgeType_id, response_format='html'):
    "Knowledge folder edit page"
    
    folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id)
    items = Object.filter_by_request(request, manager=KnowledgeItem.objects.filter(folder=folder)) 
    
    if not request.user.get_profile().has_permission(folder, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Type")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeFolderForm(request.user.get_profile(), None, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
    else:
        form = KnowledgeFolderForm(request.user.get_profile(), None, instance=folder)       

    context = _get_default_context(request)
    context.update({'items': items,
                    'folder': folder,
                    'form': form})
        
    return render_to_response('knowledge/folder_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 26
0
def service_record_add(request, response_format='html'):
    "New service_record form"
    
    if not request.user.get_profile().is_admin('maker.infrastructure'):
        return user_denied(request, 
                           message="You don't have administrator access to the Infrastructure module")
    
    service_record = ItemServicing()
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = ServiceRecordForm(request.user.get_profile(), service_record, request.POST)
            if form.is_valid():
                record = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_service_record_view', args=[record.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_service_record_index'))
    else:
        form = ServiceRecordForm(request.user.get_profile(), service_record)
    
    context = _get_default_context(request)
    context.update({'service_record': service_record,
                    'form': form})
    
    return render_to_response('infrastructure/service_record_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 27
0
def item_edit(request, knowledgeItem_id, response_format='html'):
    "Knowledge item edit page"
    item = get_object_or_404(KnowledgeItem, pk=knowledgeItem_id)
    items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r')
    
    if not request.user.get_profile().has_permission(item, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Item")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeItemForm(request.user.get_profile(), None, request.POST, instance=item)
            if form.is_valid():
                item = form.save()
                return HttpResponseRedirect(reverse('knowledge_item_view', 
                                                    args=[item.folder.treepath, item.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_item_view', 
                                                    args=[item.folder.treepath, item.treepath]))
    else:
        form = KnowledgeItemForm(request.user.get_profile(), None, instance=item)
        
    context = _get_default_context(request)
    context.update({'form': form,
                    'item':item,
                    'items':items})
        
    return render_to_response('knowledge/item_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 28
0
def service_record_edit(request, service_record_id, response_format='html'):
    "ServiceRecord edit page"
    
    service_record = get_object_or_404(ItemServicing, pk=service_record_id)
    if not request.user.get_profile().has_permission(service_record, mode="w"):
        return user_denied(request, message="You don't have write access to this ServiceRecord", 
                           response_format=response_format)

    if request.POST:
        if not 'cancel' in request.POST:
            form = ServiceRecordForm(request.user.get_profile(), None, request.POST, instance=service_record)
            if form.is_valid():
                service_record = form.save(request)
                return HttpResponseRedirect(reverse('infrastructure_service_record_view', 
                                                    args=[service_record.id]))
        else:
            return HttpResponseRedirect(reverse('infrastructure_service_record_view', 
                                                    args=[service_record.id]))
    else:
        form = ServiceRecordForm(request.user.get_profile(), None, instance=service_record)
    
    context = _get_default_context(request)
    context.update({'service_record': service_record,
                    'form': form })

    return render_to_response('infrastructure/service_record_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 29
0
def category_delete(request, knowledgeCategory_id, response_format='html'):
    "Knowledge Category delete"

    category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
    items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r')
    
    if not request.user.get_profile().has_permission(category, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Category")
    
    if request.POST:
        if 'delete' in request.POST:
            if 'trash' in request.POST:
                category.trash = True
                category.save()
            else:
                category.delete()
            return HttpResponseRedirect(reverse('knowledge_index'))
        elif 'cancel' in request.POST:
            return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
        
    context = _get_default_context(request)
    context.update({'category': category, 
                    'items':items})
        
    return render_to_response('knowledge/category_delete', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Ejemplo n.º 30
0
def weblink_edit(request, weblink_id, response_format='html'):
    "WebLink edit page"
    
    link = get_object_or_404(WebLink, pk=weblink_id)
    
    if not request.user.get_profile().has_permission(link, mode='w'):
        return user_denied(request, message="You don't have access to this Web Link")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = WebLinkForm(request.user.get_profile(), None, request.POST, instance=link)
            if form.is_valid():
                link = form.save()
                return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))
        else:
            return HttpResponseRedirect(reverse('documents_weblink_view', args=[link.id]))
            
    else:
        form = WebLinkForm(request.user.get_profile(), None, instance=link)
        
    context = _get_default_context(request)
    context.update({'form': form,
                    'link':link})
    
    return render_to_response('documents/weblink_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)