Exemple #1
0
def contactView(request, CONTACT_ID):
    """
    The contacts page - Displays all the contacts
    of the current user.
    """

    events = request.user.emailcontact_set.all()
    context = {}

    # note that CONTACT_ID is a string variable and not an int
    if int(CONTACT_ID) <= len(events) and int(CONTACT_ID) > 0:

        display = None

        selectedData = events[int(CONTACT_ID)-1]
        TemplateFormSet = inlineformset_factory(FormTemplate, FormField, extra=1)

        if request.method == "POST":

            templateForm = EmailContactForm(request.POST, instance=selectedData)

            if templateForm.is_valid():

                templateForm.save()
                display = "You have successfully updated the event !"
                return HttpResponseRedirect(urlresolvers.reverse("surveyApp:ViewContact", args=(CONTACT_ID,)))
        else:

            templateForm = EmailContactForm(instance=selectedData)

    else:
        return HttpResponseRedirect(urlresolvers.reverse("surveyApp:ViewContacts"))


    context["templateForm"] = templateForm
    context["display"] = display
    context["TemplateID"] = CONTACT_ID

    return render(request, "surveyApp/contactID.html", context)
Exemple #2
0
def contactAddAjaxView(request):

    response_data = {}
    if request.method == "POST":

        form = EmailContactForm(request.POST)
        response_data['result'] = "Error!"

        if form.is_valid():
                fieldObject = form.save(commit=False)
                fieldObject.ownedBy = request.user
                fieldObject.save()
                response_data['result'] = "Creating contact successfull!"
                response_data['name'] = fieldObject.name
                response_data['email'] = fieldObject.email

        return JsonResponse(response_data)