Example #1
0
File: views.py Project: somair/xvs
def position(request, position_id):
    position = get_object_or_404(Position, pk=position_id)

    if REQUIRE_REGISTRATION_TO_VIEW_ADVERTS and not request.user.is_authenticated(
    ):
        # Redirect the user to the must-register page.
        return redirect_to_login(position.get_absolute_url())

    if not position.approved:
        # The position is not approved, so it should not be publicly viewable.
        allowed = False
        if not request.user.is_authenticated():
            allowed = False
        elif request.user.is_staff:
            allowed = True
        elif request.user.get_profile(
        ).is_representative and request.user.get_profile(
        ).representativeprofile.organisation == position.organisation:
            allowed = True

        if not allowed:
            # raise Exception("Cannot view unapproved position unless staff admin or representative of organisation.")
            return redirect_to_login(position.get_absolute_url())

    if request.method == "POST":
        # Only a representative of the organisation is allowed to modify the position.
        if not request.user.is_staff and not request.user.get_profile(
        ).representativeprofile.organisation == position.organisation:
            raise Exception(
                "Cannot edit: not the owning organisation of this position.")

        if "copy" in request.POST:
            position_form = PositionForm(instance=position)
            return render_to_response("positions/new.html",
                                      {'position_form': position_form},
                                      context_instance=RequestContext(request))

        else:
            # The POST is toggling the "active" property of the position to either de-list or re-list it.
            position.active = request.POST['active'] == "True"
            position.save()

    if request.user.is_staff:
        # Valid volunteer list for admin recommendations.
        volunteers = User.objects.filter(
            baseprofile__volunteerprofile__id__isnull=False,
            baseprofile__archived=False).order_by("last_name")
    else:
        volunteers = None

    return render_to_response("positions/position.html", {
        'position': position,
        'notes': get_notes(request, position),
        'volunteers': volunteers,
    },
                              context_instance=RequestContext(request))
Example #2
0
def organisation(request, organisation_id):
    organisation = get_object_or_404(Organisation, pk=organisation_id)

    template_name = "positions/organisation.html"
    if "print" in request.REQUEST:
        template_name = "positions/organisation_print.html"

    return render_to_response(template_name, {
            'notes': get_notes(request, organisation),
            'organisation': organisation,
            }, context_instance=RequestContext(request))
Example #3
0
File: views.py Project: somair/xvs
def organisation(request, organisation_id):
    organisation = get_object_or_404(Organisation, pk=organisation_id)

    template_name = "positions/organisation.html"
    if "print" in request.REQUEST:
        template_name = "positions/organisation_print.html"

    return render_to_response(template_name, {
        'notes': get_notes(request, organisation),
        'organisation': organisation,
    },
                              context_instance=RequestContext(request))
Example #4
0
def position(request, position_id):
    position = get_object_or_404(Position, pk=position_id)

    if REQUIRE_REGISTRATION_TO_VIEW_ADVERTS and not request.user.is_authenticated():
        # Redirect the user to the must-register page.
        return redirect_to_login(position.get_absolute_url())

    if not position.approved:
        # The position is not approved, so it should not be publicly viewable.
        allowed = False
        if not request.user.is_authenticated():
            allowed = False
        elif request.user.is_staff:
            allowed = True
        elif request.user.get_profile().is_representative and request.user.get_profile().representativeprofile.organisation == position.organisation:
            allowed = True

        if not allowed:
            # raise Exception("Cannot view unapproved position unless staff admin or representative of organisation.")
            return redirect_to_login(position.get_absolute_url())

    if request.method == "POST":
        # Only a representative of the organisation is allowed to modify the position.
        if not request.user.get_profile().representativeprofile.organisation == position.organisation and not request.user.is_staff:
            raise Exception("Cannot edit: not the owning organisation of this position.")

        if "copy" in request.POST:
            position_form = PositionForm(instance=position)
            return render_to_response("positions/new.html", { 'position_form': position_form }, context_instance=RequestContext(request))

        else:
            # The POST is toggling the "active" property of the position to either de-list or re-list it.
            position.active = request.POST['active'] == "True"
            position.save()

    if request.user.is_staff:
        # Valid volunteer list for admin recommendations.
        volunteers = User.objects.filter(baseprofile__volunteerprofile__id__isnull=False, baseprofile__archived=False).order_by("last_name")
    else:
        volunteers = None

    return render_to_response("positions/position.html", {
            'position': position,
            'notes': get_notes(request, position),
            'volunteers': volunteers,
            }, context_instance=RequestContext(request))
Example #5
0
def offer(request, offer_id):
    offer = get_object_or_404(Offer, pk=offer_id)

    # You may only view information about an offer if you are the user, a representative of the company or a staff member.
    if request.user.is_staff:
        pass
    elif request.user == offer.volunteer:
        pass
    elif request.user.get_profile().is_representative and request.user.get_profile().representativeprofile.organisation == offer.position.organisation:
        pass
    else:
        raise Exception("You don't have permission to see details on this offer. You must either be the volunteer making the offer, a representative of the organisation that is advertising the position or a member of staff in order to view offer details.")

    return render_to_response("offers/offer.html", {
            'offer': offer,
            'notes': get_notes(request, offer),
            'v_user': offer.volunteer,
            }, context_instance=RequestContext(request))
Example #6
0
def offer(request, offer_id):
    offer = get_object_or_404(Offer, pk=offer_id)

    # You may only view information about an offer if you are the user, a representative of the company or a staff member.
    if request.user.is_staff:
        pass
    elif request.user == offer.volunteer:
        pass
    elif request.user.get_profile(
    ).is_representative and request.user.get_profile(
    ).representativeprofile.organisation == offer.position.organisation:
        pass
    else:
        raise Exception(
            "You don't have permission to see details on this offer. You must either be the volunteer making the offer, a representative of the organisation that is advertising the position or a member of staff in order to view offer details."
        )

    return render_to_response("offers/offer.html", {
        'offer': offer,
        'notes': get_notes(request, offer),
        'v_user': offer.volunteer,
    },
                              context_instance=RequestContext(request))
Example #7
0
File: views.py Project: somair/xvs
def profile(request, user_id):
    profile = get_object_or_404(BaseProfile, user__id=user_id)
    timerecords = profile.user.timerecord_set.all()
    endorsements = Endorsement.objects.filter(
        commitment__volunteer__id=user_id)
    mailouts = Recipient.objects.filter(user__id=user_id).exclude(
        mailout__sent=None)

    minutes = 0
    for tr in timerecords:
        minutes += (60 * tr.hours + tr.minutes)
    hours = int(minutes / 60)
    minutes = minutes % 60

    # You may only view a profile if you are the user, a representative of a company receiving an offer or a staff member.
    if request.user.is_staff:
        pass
    elif request.user == profile.user:
        pass
    elif request.user.get_profile().is_representative:
        # Get the organisations this user has made offers to.
        offers = profile.user.offers_made.all()
        rep_organisation = request.user.get_profile(
        ).try_get_representative_profile().organisation
        organisations = [offer.position.organisation for offer in offers]
        if rep_organisation in organisations:
            # This user has made an offer to this organisation.
            # Only show time records for this organisation
            timerecords = profile.user.timerecord_set.filter(
                organisation=rep_organisation)
            pass
        else:
            raise Exception(
                "You don't have permission to see this profile. You must either be the profile owner, a representative of an organisation that is advertising a position that this volunteer is applying to, or a member of staff in order to view offer details."
            )
    else:
        raise Exception(
            "You don't have permission to see this profile. You must either be the profile owner, a representative of an organisation that is advertising a position that this volunteer is applying to, or a member of staff in order to view offer details."
        )

    # Get a list of currently active positions
    positions = Position.objects.filter(approved=True, active=True)

    awards = Award.objects.filter(user=profile.user)

    skill_set = set(s.name for p in positions for s in p.skills_gained.all())

    if settings.FEATURE_PROFILE_V2:
        template_name = "profiles/profilev2.html"
    else:
        template_name = "profiles/profile.html"

    if "print" in request.REQUEST and settings.FEATURE_PROFILE_V2:
        template_name = "profiles/printv2.html"
    elif "print" in request.REQUEST:
        template_name = "profiles/print.html"

    return render_to_response(template_name, {
        'profile':
        profile,
        'endorsements':
        endorsements,
        'awards':
        awards,
        'mailouts':
        mailouts,
        'notes':
        get_notes(request,
                  profile.user,
                  redirect=reverse('profiles.views.profile',
                                   args=(profile.user.id, ))),
        'v_user':
        profile.user,
        'timerecords':
        timerecords,
        'total_hours':
        hours,
        'total_minutes':
        minutes,
        'positions':
        positions,
        'readonly':
        'print' in request.REQUEST,
        'skill_set':
        skill_set,
    },
                              context_instance=RequestContext(request))
Example #8
0
def profile(request, user_id):
    profile = get_object_or_404(BaseProfile, user__id=user_id)
    timerecords = profile.user.timerecord_set.all()
    endorsements = Endorsement.objects.filter(commitment__volunteer__id=user_id)
    mailouts = Recipient.objects.filter(user__id=user_id).exclude(mailout__sent=None)

    minutes = 0
    for tr in timerecords:
        minutes += (60*tr.hours + tr.minutes)
    hours = int(minutes/60)
    minutes = minutes%60

    # You may only view a profile if you are the user, a representative of a company receiving an offer or a staff member.
    if request.user.is_staff:
        pass
    elif request.user == profile.user:
        pass
    elif request.user.get_profile().is_representative:
        # Get the organisations this user has made offers to.
        offers = profile.user.offers_made.all()
        rep_organisation = request.user.get_profile().try_get_representative_profile().organisation
        organisations = [offer.position.organisation for offer in offers]
        if rep_organisation in organisations:
            # This user has made an offer to this organisation.
            # Only show time records for this organisation
            timerecords = profile.user.timerecord_set.filter(organisation=rep_organisation)
            pass
        else:
            raise Exception("You don't have permission to see this profile. You must either be the profile owner, a representative of an organisation that is advertising a position that this volunteer is applying to, or a member of staff in order to view offer details.")
    else:
        raise Exception("You don't have permission to see this profile. You must either be the profile owner, a representative of an organisation that is advertising a position that this volunteer is applying to, or a member of staff in order to view offer details.")

    # Get a list of currently active positions
    positions = Position.objects.filter(approved=True, active=True)

    awards = Award.objects.filter(user=profile.user)

    skill_set = set(s.name for p in positions for s in p.skills_gained.all())

    if settings.FEATURE_PROFILE_V2:
        template_name = "profiles/profilev2.html"
    else:
        template_name = "profiles/profile.html"

    if "print" in request.REQUEST and settings.FEATURE_PROFILE_V2:
        template_name = "profiles/printv2.html"
    elif "print" in request.REQUEST:
        template_name = "profiles/print.html"

    return render_to_response(template_name, {
            'profile': profile,
            'endorsements': endorsements,
            'awards': awards,
            'mailouts': mailouts,
            'notes': get_notes(request, profile.user, redirect=reverse('profiles.views.profile', args=(profile.user.id,))),
            'v_user': profile.user,
            'timerecords': timerecords,
            'total_hours': hours,
            'total_minutes': minutes,
            'positions': positions,
            'readonly': 'print' in request.REQUEST,
            'skill_set': skill_set,
            }, context_instance=RequestContext(request))