Пример #1
0
    def post(req):

        # if DELETE was clicked... delete
        # the object, then and redirect
        if req.POST.get("delete", ""):
            pk = rep.pk
            rep_profile.delete()
            rep.delete()

            transaction.commit()
            return message(req,
                "Tester %d deleted" % (pk),
                link="/testers")

        else:
            # check the form for errors (just
            # missing fields, for the time being)
            reporter_errors = check_reporter_form(req)
            profile_errors = check_profile_form(req)

            # if any fields were missing, abort. this is
            # the only server-side check we're doing, for
            # now, since we're not using django forms here
            missing = reporter_errors["missing"] + profile_errors["missing"]
            if missing:
                transaction.rollback()
                return message(req,
                    "Missing Field(s): %s" %
                        ", ".join(missing),
                    link="/testers/%s" % (rep.pk))

            try:
                # automagically update the fields of the
                # reporter object, from the form
                update_via_querydict(rep, req.POST).save()
                # add relevent connections
                update_reporter(req, rep)
                # update reporter profile
                update_reporterprofile(req, rep, req.POST.get("chw_id", ""), \
                                       req.POST.get("chw_username", ""), \
                                       req.POST.get("e_mail", ""), \
                                       req.POST.get("facility",""))

                # no exceptions, so no problems
                # commit everything to the db
                transaction.commit()

                # full-page notification
                return message(req,
                    "Tester %d updated" % (rep.pk),
                    link="/testers")

            except Exception, err:
                transaction.rollback()
                raise
Пример #2
0
    def post(req):
        # delete notification if a delete button was pressed.
        if req.POST.get("delete", ""):
            pk = resource.pk
            resource.delete()

            transaction.commit()
            return message(req, "Resource %d deleted" % (pk), link="/resources")
        else:
            # check the form for errors
            notice_errors = check_resource_form(req)

            # if any fields were missing, abort.
            missing = notice_errors["missing"]
            exists = notice_errors["exists"]

            if missing:
                transaction.rollback()
                return message(req, "Missing Field(s): %s" % comma(missing), link="/resources/add")

            try:
                # create the resource object from the form
                cat = ResourceCategory.objects.get(pk=req.POST.get("category", ""))
                resource.category = cat

                status = Status.objects.get(pk=req.POST.get("status", ""))
                resource.status = status

                pk = req.POST.get("facility", "")
                if pk != "":
                    facility = Facility.objects.get(pk=req.POST.get("facility", ""))
                    resource.facility = facility
                else:
                    resource.facility = None

                resource.name = req.POST.get("name", "")
                resource.code = req.POST.get("code", "")

                # save the changes to the db
                resource.save()
                transaction.commit()

                # full-page notification
                return message(req, "A resource %s updated" % (resource.pk), link="/resources")

            except Exception, err:
                transaction.rollback()
                raise
Пример #3
0
def delete_notifications(req, pk):
    notification = get_object_or_404(SmsNotification, pk=pk)
    notification.delete()

    # transaction.commit()
    id = int(pk)
    return message(req, "SMS Notification %d deleted" % (id), link="/smsnotification")
Пример #4
0
def confirm(req, pk):
    def get_reporter(current_user, station):
        # todo: get the testers in the system with the same
        # domain as the login user.
        rep_profile = ReporterProfile.objects.filter(domain=current_user.selected_domain)
        rep_profile = rep_profile.filter(facility=station)
        reporters = []

        if rep_profile:
            for rep in rep_profile:
                reporter = rep.reporter
                reporters.append(reporter)
        return reporters

    def get_resource(station):
        resources = Resource.objects.filter(facility=station)
        return resources

    template_name = "facilities/confirm.html"

    facility = get_object_or_404(Facility, pk=pk)
    if facility:
        personnel = len(get_reporter(req.user, facility))
        resources = get_resource(facility).count()

    else:
        return message(req, "A facility not found!" % (id), link="/facilities")

    return render_to_response(
        req, template_name, {"facility": facility, "personnel": personnel, "resources": resources}
    )
Пример #5
0
def delete_resources(req, pk):
    resource = get_object_or_404(Resource, pk=pk)
    resource.delete()

    transaction.commit()
    id = int(pk)
    return message(req, "A resource %d deleted" % (id), link="/resources")
Пример #6
0
def delete_facilities(req, pk):
    facility = get_object_or_404(Facility, pk=pk)
    facility.delete()

    transaction.commit()
    id = int(pk)
    return message(req, "A facility %d deleted" % (id), link="/facilities")
Пример #7
0
def delete_samplingpoints(req, pk):
    point = get_object_or_404(SamplingPoint, pk=pk)
    point.delete()

    transaction.commit()
    id = int(pk)
    return message(req, "Sampling point %d deleted" % (id), link="/samplingpoints")
Пример #8
0
    def post(req):
        # delete notification if a delete button was pressed.
        if req.POST.get("delete", ""):
            pk = facility.pk
            facility.delete()

            transaction.commit()
            return message(req, "Facility %d deleted" % (pk), link="/facilities")
        else:
            # check the form for errors
            notice_errors = check_facility_form(req)

            # if any fields were missing, abort.
            missing = notice_errors["missing"]
            exists = notice_errors["exists"]

            if missing:
                transaction.rollback()
                return message(req, "Missing Field(s): %s" % comma(missing), link="/facilities/add")

            try:
                loc = Location.objects.get(pk=req.POST.get("location", ""))
                facility.location = loc

                latitude = req.POST.get("latitude", "")
                if latitude == "":
                    latitude = None
                longitude = req.POST.get("longitude", "")
                if longitude == "":
                    longitude = None

                facility.latitude = latitude
                facility.longitude = longitude
                facility.name = req.POST.get("name", "")
                facility.description = req.POST.get("description", "")
                facility.domain = req.user.selected_domain

                # save the changes to the db
                facility.save()
                transaction.commit()

                # full-page notification
                return message(req, "A facility %s updated" % (facility.pk), link="/facilities")

            except Exception, err:
                transaction.rollback()
                raise
Пример #9
0
    def post(req):
        # check the form for errors
        notice_errors = check_facility_form(req)

        # if any fields were missing, abort.
        missing = notice_errors["missing"]
        exists = notice_errors["exists"]

        if missing:
            transaction.rollback()
            return message(req, "Missing Field(s): %s" % comma(missing), link="/facilities/add")
        # if a resource with the same code is already register abort
        if exists:
            transaction.rollback()
            return message(req, "%s already exist" % comma(exists), link="/facilities/add")

        try:
            # create the resource object from the form
            facility = Facility()

            loc = Location.objects.get(pk=req.POST.get("location", ""))
            facility.location = loc

            latitude = req.POST.get("latitude", "")
            if latitude == "":
                latitude = None
            longitude = req.POST.get("longitude", "")
            if longitude == "":
                longitude = None

            facility.latitude = latitude
            facility.longitude = longitude
            facility.name = req.POST.get("name", "")
            facility.description = req.POST.get("description", "")
            facility.domain = req.user.selected_domain

            # save the changes to the db
            facility.save()
            transaction.commit()

            # full-page notification
            return message(req, "A facility %s added" % (facility.pk), link="/facilities")

        except Exception, err:
            transaction.rollback()
            raise
Пример #10
0
def deny_resource_requests(req, pk):
    resource_req = get_object_or_404(ResourceSupplyRequest, pk=pk)
    resource_req.status = "Denied"
    resource_req.save()

    #    transaction.commit()
    id = int(pk)
    return message(req, "A resource request %d is Denied" % (id), link="/resources/requests")
Пример #11
0
def delete_testers(req, pk):
    rep = get_object_or_404(Reporter, pk=pk)
    rep_profile = get_object_or_404(ReporterProfile, reporter=rep)
    rep_profile.delete()
    rep.delete()

    transaction.commit()
    id = int(pk)
    return message(req, "Tester %d deleted" % (id), link="/testers")
Пример #12
0
    def post(req):
        # check the form for errors
        reporter_errors = check_reporter_form(req)
        profile_errors = check_profile_form(req)

        # if any fields were missing, abort.
        missing = reporter_errors["missing"] + profile_errors["missing"]
        exists = reporter_errors["exists"] + profile_errors["exists"]

        if missing:
            transaction.rollback()
            return message(req,
                "Missing Field(s): %s" % comma(missing),
                link="/testers/add")
        # if chw_id exists, abort.
        if exists:
            transaction.rollback()
            return message(req,
                "Field(s) already exist: %s" % comma(exists),
                link="/testers/add")

        try:
            # create the reporter object from the form
            rep = insert_via_querydict(Reporter, req.POST)
            rep.save()

            # add relevent connections
            update_reporter(req, rep)
            # create reporter profile
            update_reporterprofile(req, rep, req.POST.get("chw_id", ""), \
                                   req.POST.get("alias", ""), \
                                   req.POST.get("e_mail", ""),\
                                   req.POST.get("facility",""))
            # save the changes to the db
            transaction.commit()

            # full-page notification
            return message(req,
                "Testers %d added" % (rep.pk),
                link="/testers")

        except Exception, err:
            transaction.rollback()
            raise
Пример #13
0
    def post(req):
        # check the form for errors
        notice_errors = check_resource_form(req)

        # if any fields were missing, abort.
        missing = notice_errors["missing"]
        exists = notice_errors["exists"]

        if missing:
            transaction.rollback()
            return message(req, "Missing Field(s): %s" % comma(missing), link="/resources/add")
        # if a resource with the same code is already register abort
        if exists:
            transaction.rollback()
            return message(req, "%s already exist" % comma(exists), link="/resources/add")

        # TODO: Finish adding a resource.
        try:
            # create the resource object from the form
            resource = Resource()

            cat = ResourceCategory.objects.get(pk=req.POST.get("category", ""))
            resource.category = cat

            status = Status.objects.get(pk=req.POST.get("status", ""))
            resource.status = status

            facility = Facility.objects.get(pk=req.POST.get("facility", ""))
            resource.facility = facility

            resource.name = req.POST.get("name", "")
            resource.code = req.POST.get("code", "")

            # save the changes to the db
            resource.save()
            transaction.commit()

            # full-page notification
            return message(req, "A resource %s added" % (resource.pk), link="/resources")

        except Exception, err:
            transaction.rollback()
            raise
Пример #14
0
def add_notifications(request):
    template_name = "sms-notifications.html"
    if request.method == "POST":  # If the form has been submitted...
        form = SmsNotificationForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request, "SMS Notification Added", link="/smsnotification")
    else:
        form = SmsNotificationForm()  # An unbound form

    return render_to_response(request, template_name, {"form": form})
Пример #15
0
def edit_samplingpoints(request, pk):
    template_name = "samplingpoints.html"
    point = get_object_or_404(SamplingPoint, pk=pk)
    if request.method == "POST":  # If the form has been submitted...
        form = SamplingPointForm(request.POST, instance=point)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request, "Sampling Point Updated", link="/samplingpoints")
    else:
        form = SamplingPointForm(instance=point)  # An unbound form

    return render_to_response(request, template_name, {"form": form, "point": point})
Пример #16
0
def edit_notifications(request, pk):
    template_name = "sms-notifications.html"
    notification = get_object_or_404(SmsNotification, pk=pk)
    if request.method == "POST":  # If the form has been submitted...
        form = SmsNotificationForm(request.POST, instance=notification)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request, "SMS Notification Updated", link="/smsnotification")
    else:
        form = SmsNotificationForm(instance=notification)

    return render_to_response(request, template_name, {"form": form, "notification": notification})
Пример #17
0
def add_samplingpoint(request):
    template_name = "samplingpoints.html"
    if request.method == 'POST': # If the form has been submitted...
        form = SamplingPointForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # saving the form data is not cleaned
            form.save()
            return message(request,
                        "Sampling Point Added",
                        link="/samplingpoints")
    else:
        form = SamplingPointForm() # An unbound form

    return render_to_response(request,template_name, {
        'form': form,
    })