Exemplo n.º 1
0
def userinfoedit(request, username):
    # TODO: redirect if its not current logged user
    assert isinstance(request, HttpRequest)

    successSave = False
    if request.method == 'POST':

        form = CustomUserInfoEditForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()
            successSave = True
    else:
        form = CustomUserInfoEditForm(instance=User.objects.get_by_natural_key(username))

    dic = {
            'title': 'Edit info',
            'form': form,
        }

    if successSave:
        dic['successAlerts'] = ('Edit was successful!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'user/userinfoedit.html',
            context_instance = RequestContext(request,dic))
Exemplo n.º 2
0
def messagesend(request, username):
    """Renders form to send new message."""
    assert isinstance(request, HttpRequest)

    successSend = False
    if request.method == 'POST':
        form = SendMessageForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            message = Message(user_from = request.user,
                              user_to = User.objects.get_by_natural_key(username),
                              text = data['text'])
            message.save()
            form = SendMessageForm(initial={'username': User.objects.get_by_natural_key(username).username})
            successSend = True
    else:
        form = SendMessageForm(initial={'username': User.objects.get_by_natural_key(username).username})

    dic = {
            'title': 'Send new message',
            'form': form,
        }

    if successSend:
        dic['successAlerts'] = ('Sent!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'message/send.html',
            context_instance = RequestContext(request, dic))
Exemplo n.º 3
0
def taskedit(request, id):
    """Renders form to create new task."""
    assert isinstance(request, HttpRequest)

    successEdit = False
    if request.method == 'POST':
        form = EditTaskForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            task = Task.objects.get(id = id)
            task.text = data['text']
            task.status = data['status']
            task.deleted = data['deleted']
            task.save()
            successEdit = True
    else:
        form = EditTaskForm(instance=Task.objects.get(id = id))

    dic = {
            'title': 'Edit task',
            'form': form,
        }

    if successEdit:
        dic['successAlerts'] = ('Edited!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'task/edit.html',
            context_instance = RequestContext(request, dic))
Exemplo n.º 4
0
def taskcreate(request):
    """Renders form to create new task."""
    assert isinstance(request, HttpRequest)

    successCreate = False
    if request.method == 'POST':
        form = CreateTaskForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            task = Task(user = request.user, text = data['text'], status = data['status'])
            task.save()
            form = CreateTaskForm()
            successCreate = True
        else:
            invalidForm = True
    else:
        form = CreateTaskForm()

    dic = {
            'title': 'Create new task',
            'form': form,
        }

    if successCreate:
        dic['successAlerts'] = ('Created!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'task/create.html',
            context_instance = RequestContext(request, dic))
Exemplo n.º 5
0
def taskstatuscreate(request):
    """Renders create form page for task status."""
    assert isinstance(request, HttpRequest)
    successCreate = False
    if request.method == 'POST':
        form = CreateTaskStatusForm(request.POST)

        if form.is_valid():
            form.save()
            form = CreateTaskStatusForm()
            successCreate = True
    else:
        form = CreateTaskStatusForm()

    dic = {
            'title': 'Create new task status',
            'form': form,
        }

    if successCreate:
        dic['successAlerts'] = ('Created!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'taskstatus/create.html',
            context_instance = RequestContext(request,dic))
Exemplo n.º 6
0
def edititem(request,id):
    """Renders edit item page."""
    assert isinstance(request, HttpRequest)
     # TODO: redirect if its not current logged user
    successEdit = False
    if request.method == 'POST':
        form = CreateItemForm(request.POST)

        if form.is_valid():
            data = form.cleaned_data
            item = Item(user = request.user, id = id, name = data['name'], price = data['price'])
            item.save()
            successEdit = True
    else:
        form = CreateItemForm(instance=Item.objects.get(id = id))

    dic = {
            'title': 'Edit item',
            'form': form,
        }

    if successEdit:
        dic['successAlerts'] = ('Edit was successful!',)
    elif form.errors:
        dic['dangerAlerts'] = getFieldErrors(form)

    return render(request,
            'edititem.html',
            context_instance = RequestContext(request, dic))