Пример #1
0
def training_materials_assign(request, pk=None):
    if pk:
        tm = get_object_or_404(TrainingMaterial, pk=pk)
    else:
        tm = TrainingMaterial()
    tm_form = AssignForm(instance=tm)
    if request.method == 'POST':
        data = {}
        for key in request.POST:
            val = request.POST[key]
            if isinstance(val, basestring):
                data[key] = val
            else:
                try:
                    data[key] = val[0]
                except (IndexError, TypeError):
                    data[key] = val
        del data
        if pk:
            tm_form = AssignForm(request.POST, instance=tm)
        else:
            tm_form = AssignForm(request.POST)
        if tm_form.is_valid():
            tm = tm_form.save()
            assigned_users = tm_form.cleaned_data['assigned_users']
            notification = 'You have been assigned %s. To begin, reply with START %s.' % (tm.title, tm.tag)
            #self.cleaned_data['text']
            connections = []
            #assigned_users = tm_form.cleaned_data['assigned_users']
            for user in assigned_users:
                connections.append(user.default_connection)
            #connections = self.cleaned_data['assigned_users']
            send(notification, connections)
            #send(tm, assigned_users)
            tm.save()
            messages.add_message(request, messages.INFO, "Saved and sent training material.")
            return HttpResponseRedirect(reverse(training_materials))
    return render(request, 'training_materials/tm_assign1.html', {
        "tm": tm,
        "tm_form": tm_form,
        "range": range(tm.messagenum),#"x"*tm.messagenum,
    })
Пример #2
0
def admin_assign_all(request):
    from forms import AssignForm
    from signup.models import CustomUser
    
    context = {}

    if request.method == "POST":
        form = AssignForm(request.POST, request.FILES)
        if form.is_valid():
            all_users = CustomUser.objects.filter(
                is_active=True)
            context['message'] = []
            for task in form.cleaned_data['tasks']:
                (assigned, already_assigned) = TaskUser.objects.trigger_assign(task, all_users)
                context['message'].append((task, assigned, already_assigned))
                
            context['form'] = form
        else:
            context['form'] = form
    else:
        context['form'] = AssignForm()
    
    return render_with_context(request, 'tasks/task_admin.html', context)
Пример #3
0
def ticket(request, pk):
    """
    View a ticket
    """
    ticket = get_object_or_404(Ticket, id=pk)
    if request.method == 'POST':
        assignform = AssignForm(request.POST, prefix="assign")
        stateform = StateForm(
                request.POST, 
                prefix="state",
                workflow_manager=ticket.workflow_manager
                )
        if "change" in request.POST:
            if stateform.is_valid():
                transition = stateform.cleaned_data['transition']
                p = Participant.objects.get(
                    user=request.user,
                    workflowmanager=ticket.workflow_manager
                    )
                ticket.workflow_manager.progress(
                        transition,
                        p
                        )
                request.user.message_set.create(message=_("The ticket has been"\
                    " successfully transitioned to a new state.."))
                assign_dict={}
                if ticket.assigned_to:
                    assign_dict = {'assign-assignee': ticket.assigned_to.id}
                assignform = AssignForm(assign_dict, prefix="assign")
                stateform = StateForm(
                    prefix="state", 
                    workflow_manager=ticket.workflow_manager
                    )
        elif "assign" in request.POST:
            if assignform.is_valid():
                u = assignform.cleaned_data['assignee']
                ticket.assigned_to = u 
                ticket.save()
                r = Role.objects.get(id=settings.ROLE_ASSIGNEE)
                p = Participant.objects.filter(user=u, 
                        workflowmanager=ticket.workflow_manager)
                if len(p)==1:
                    p[0].role=r
                    p[0].save()
                else:
                    p = Participant(
                        role=r, 
                        user=u,
                        workflowmanager=ticket.workflow_manager
                        )
                    p.save()
                request.user.message_set.create(message=_("The ticket has been"\
                    " successfully re-assigned."))
    else:
        assign_dict={}
        if ticket.assigned_to:
            assign_dict = {'assign-assignee': ticket.assigned_to.id}
        assignform = AssignForm(assign_dict, prefix="assign")
        stateform = StateForm(
                prefix="state", 
                workflow_manager=ticket.workflow_manager
                )
    c = RequestContext(request, {
        'ticket': ticket,
        'assignform': assignform,
        'stateform': stateform,
        })
    return render_to_response('ticket.html', c)