コード例 #1
0
ファイル: views.py プロジェクト: rorycl/clwmail
def holidayadd(request, username, domain):
    """ 
		This methos allows a user to add a holiday message It requires the data
		to be posted and all data to be validated. Upon succesfull completion
		of the message form, the user is redirected to the same holiday
		management page with the new holiday message appearing in the list of
		holidays. If an error has occured the holiday responder is called in
		order to show the errors 
	"""

    if not canview(request, username, domain):
        return HttpResponseRedirect(urlrel + "auth/deny/profile/")

        # Instantiate model
    model = MailModel()
    # Mode set
    mode = "add"
    # Ensure we have posted data
    if request.method == "POST":
        # create a copy of the post data
        # so we are not directly manipulating it
        new_data = request.POST.copy()
        # Create a concat version of the different fields
        # for the startdate
        new_data["hstart_date"] = _datemaker(
            new_data["hs_day"], new_data["hs_month"], new_data["hs_year"], new_data["hs_hour"], new_data["hs_min"]
        )
        # Create a concat version of the different fields
        # for the end date
        new_data["hend_date"] = _datemaker(
            new_data["he_day"], new_data["he_month"], new_data["he_year"], new_data["he_hour"], new_data["he_min"]
        )
        # Bind form to post data
        form = HolidayForm(new_data)
        # Check if form is valid
        if form.is_valid():
            # Standardized data
            cleaned_data = form.clean()
            param_dict = {
                "mode": 1,
                "username": username,
                "domain": domain,
                "hstart": cleaned_data["hstart_date"],
                "hend": cleaned_data["hend_date"],
                "message": cleaned_data["message"],
                "id": -1,
                "b_default": cleaned_data["b_default"],
            }

            result = model.manageholiday(**param_dict)
            if not result and model.error:
                errors = {"form": form, "new_data": new_data, "mode": mode, "dberror": model.error}
                return _holidayresponder(request, username, domain, adict=errors)

                # If not valid call responder with error
        else:
            errors = {"form": form, "new_data": new_data, "mode": mode}
            return _holidayresponder(request, username, domain, adict=errors)

    return HttpResponseRedirect(urlrel + "mailstore/user/%s/domain/%s/holiday/" % (username, domain))
コード例 #2
0
ファイル: views.py プロジェクト: rorycl/clwmail
def holidayedit(request, username, domain, hol_id):
    """ 
		This method allows a user to edit a holiday message from the queue.
		succesfull update of the message redirects the user to the same holiday
		management page .  If an error has occured the holiday responder is
		called in order to show the errors 
	"""

    # Ensure the user can view this.
    if not canview(request, username, domain):
        return HttpResponseRedirect(urlrel + "auth/deny/profile/")

    model = MailModel()
    # Set the mode
    mode = "edit"
    # Get the requested holiday
    holiday = model.getholiday(int(hol_id), username, domain)
    # If the holiday was not found
    if holiday and not holiday.holid:
        raise Http404

    if request.method == "POST":
        # create a copy of the post data
        # so we are not directly manipulating it
        new_data = request.POST.copy()
        # Create a concat version of the different fields
        # for the startdate
        new_data["hstart_date"] = _datemaker(
            new_data["hs_day"], new_data["hs_month"], new_data["hs_year"], new_data["hs_hour"], new_data["hs_min"]
        )
        # Create a concat version of the different fields
        # for the end date
        new_data["hend_date"] = _datemaker(
            new_data["he_day"], new_data["he_month"], new_data["he_year"], new_data["he_hour"], new_data["he_min"]
        )
        # Bind form to post data
        form = HolidayForm(new_data)

        # Check if form is valid
        if form.is_valid():
            # Standardized data
            cleaned_data = form.clean()
            # Set up for edit
            param_dict = {
                "mode": 2,
                "username": username,
                "domain": domain,
                "hstart": cleaned_data["hstart_date"],
                "hend": cleaned_data["hend_date"],
                "message": cleaned_data["message"],
                "id": holiday.holid,
                "b_default": cleaned_data["b_default"],
            }

            # Manage the holiday
            result = model.manageholiday(**param_dict)

            # Ensure no errors have occured
            if not result and model.error:
                errors = {"form": form, "new_data": new_data, "mode": mode, "dberror": model.error, "holiday": holiday}
                return _holidayresponder(request, username, domain, adict=errors)

            return HttpResponseRedirect(urlrel + "mailstore/user/%s/domain/%s/holiday/" % (username, domain))

            # If not valid call responder with error
        else:
            errors = {"form": form, "new_data": new_data, "holiday": holiday, "mode": mode}
            return _holidayresponder(request, username, domain, errors)

    return _holidayresponder(request, username, domain, adict={"mode": mode, "holiday": holiday})