Ejemplo n.º 1
0
def deleteEvent(request, event_id):
    event = Event.event.get(id=event_id)
    group = event.parentGroup
    if not group.get_is_organzer(request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/event/' + str(event.id))

    if group.get_is_organzer(request.user):
        name = event.name

        event.delete()

        feed_entry = Feed_Entry(group=group,
                                user=request.user,
                                datetime=get_dt(),
                                description="Deleted event \"" + name + "\"",
                                url="/volunteer/events",
                                private=False)
        feed_entry.save()

        alert = Alert(user=request.user,
                      text="Deleted event " + name,
                      color=Alert.getRed())
        alert.saveIP(request)

        return redirect("/volunteer/events")

    else:
        alert = Alert(user=request.user,
                      text="Only organizers can delete events",
                      color=Alert.getRed())
        alert.saveIP(request)

        return redirect("/volunteer/event/" + str(object.id))
Ejemplo n.º 2
0
def removeUserSlot(request, user_slot_id):
    user_slot = User_Slot.objects.get(id=user_slot_id)
    slot = user_slot.parentSlot
    group = slot.parentGroup
    if group is None:
        group = slot.parentEvent.parentGroup
    if not group.get_is_organzer(request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/slot/' + str(slot.id))

    if not group.get_is_organzer(request.user):
        group.get_is_organzer(request.user)
        alert = Alert(user=request.user,
                      text="Only organizers can delete volunteer opennings",
                      color=Alert.getRed())
        alert.saveIP(request)
    else:
        user_slot.delete()

        alert = Alert(user=request.user,
                      text="Deleted a volunteer openning",
                      color=Alert.getRed())
        alert.saveIP(request)

    return redirect('/volunteer/slot/' + str(user_slot.parentSlot.id))
Ejemplo n.º 3
0
def editField(request, user_slot_id, field):
    user_slot = User_Slot.objects.get(id=user_slot_id)
    if user_slot.parentSlot.parentGroup is not None:
        group = user_slot.parentSlot.parentGroup
    else:
        group = user_slot.parentSlot.parentEvent.parentGroup
    if not group.get_is_organzer(request.user):
        alert = Alert(user=request.user,
                      text="You must be an organizer to edit extra fields",
                      color=Alert.getRed())
        alert.saveIP(request)
        return redirect('/volunteer/slot/' + str(user_slot.parentSlot.id))
    if group.get_is_organzer(request.user):
        if request.method == 'POST':
            form = FieldForm(request.POST)
            if form.is_valid():
                newVal = form.save()
                user_slot.set_extra(field, newVal)
                user_slot.save()
                return redirect('/volunteer/slot/' +
                                str(user_slot.parentSlot.id))

        else:
            form = FieldForm(initial={"field": user_slot.get_extra()[field]})

        return render(
            request, 'organizer/editField.html', {
                'form': form,
                'user_slot': user_slot,
                'slotField': field,
                'val': user_slot.get_extra()[field]
            })

    return redirect('/volunteer/slot/' + str(user_slot.parentSlot.id))
Ejemplo n.º 4
0
def addUserSlot(request, slot_id):
    slot = Slot.objects.get(id=slot_id)
    group = slot.parentGroup
    if group is None:
        group = slot.parentEvent.parentGroup
    if not group.get_is_organzer(request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/slot/' + str(slot.id))

    if group.get_is_organzer(request.user):
        ans = OrderedDict()
        for i in slot.get_extra():
            if i != '' and i != ' ':
                ans[i] = '-'
        user_slot = User_Slot(parentSlot=slot)
        user_slot.save_extra(ans)
        user_slot.save()

        alert = Alert(user=request.user,
                      text="Added a volunteer opening",
                      color=Alert.getBlue())
        alert.saveIP(request)
    else:
        alert = Alert(user=request.user,
                      text="Only organizers can add volunteer openings",
                      color=Alert.getRed())
        alert.saveIP(request)
    return redirect('/volunteer/slot/' + str(slot_id))
Ejemplo n.º 5
0
def volunteer(request, slot_id):
    # next = request.GET.get('next')
    slot = Slot.objects.get(id=slot_id)
    user_slot = User_Slot.objects.filter(parentSlot=slot,
                                         volunteer__isnull=True).first()
    slots_filled_by_this_user = User_Slot.objects.filter(
        parentSlot=slot, volunteer=request.user).first()

    if slot.parentEvent is not None:
        group = slot.parentEvent.parentGroup
    else:
        group = slot.parentGroup

    if slot.maxVolunteers == 0:  # and slots_filled_by_this_user is None:
        user_slot = User_Slot(parentSlot=slot, accepted="Yes")

    #
    # elif slots_filled_by_this_user is not None:
    # 	alert = Alert(user=request.user, text="Already volunteered", color=Alert.getRed())
    # 	alert.saveIP(request)
    # 	return redirect('/volunteer/slot/' + str(slot_id))
    elif user_slot is None:
        alert = Alert(user=request.user,
                      text="Already at Max Volunteers",
                      color=Alert.getRed())
        alert.saveIP(request)
        return redirect('/volunteer/slot/' + str(slot_id))

    user_slot.volunteer = request.user
    user_slot.accepted = "Yes"
    if slot.get_extra() is not None:
        ans = {}

        for i in slot.get_extra():
            if i != '':
                ans[i] = '-'
        user_slot.extraFields = ans
    user_slot.save()

    name = slot.title

    feed_entry = Feed_Entry(group=group,
                            user=request.user,
                            datetime=get_dt(),
                            description="Volunteered for \"" + name,
                            url="/volunteer/slot/" + str(slot.id),
                            private=slot.private)
    feed_entry.save()

    alert = Alert(user=request.user,
                  text="Volunteered for " + slot.title,
                  color=Alert.getGreen())
    alert.saveIP(request)

    return redirect('/volunteer/slot/' + str(slot.id))
Ejemplo n.º 6
0
def addSingleSlot(request, group_id):
    group = Group.objects.get(id=group_id)
    if not Group.get_is_organzer(group, request.user):
        alert = Alert(user=request.user,
                      text="Only organizers can add single slots",
                      color=Alert.getRed())
        alert.saveIP(request)
        return redirect('/volunteer/slots')

    if request.method == 'GET':
        form = NewSlotForm(user=request.user,
                           parentEvent=None,
                           initial={'private': group.private})
    else:
        form = NewSlotForm(request.POST,
                           user=request.user,
                           parentEvent=None,
                           initial={'private': group.private})
        if form.is_valid():
            slot = form.save(commit=False)
            slot.parentGroup = group
            slot.save()

            ans = OrderedDict()
            for i in slot.get_extra():
                if i != '' and i != ' ':
                    ans[i] = '-'
            for x in range(0, slot.maxVolunteers):
                user_slot = User_Slot(volunteer=None, parentSlot=slot)
                user_slot.save_extra(ans)
                user_slot.save()

            feed_entry = Feed_Entry(group=group,
                                    user=request.user,
                                    datetime=get_dt(),
                                    description="Created single slot \"" +
                                    str(slot.title),
                                    url="/volunteer/slot/" + str(slot.id),
                                    private=False)
            feed_entry.save()

            alert = Alert(user=request.user,
                          text="Created slot " + slot.title,
                          color=Alert.getBlue())
            alert.saveIP(request)

            return redirect('/volunteer/slots/' + str(slot.id))

    return render(request, 'organizer/add_slot.html', {'form': form})
Ejemplo n.º 7
0
def unvolunteer(request, slot_id):
    slot = Slot.objects.get(id=slot_id)
    slots_filled_by_this_user = User_Slot.objects.filter(
        parentSlot=slot, volunteer=request.user).first()
    if slots_filled_by_this_user is None:
        alert = Alert(user=request.user,
                      text="Haven't volunteered yet",
                      color=Alert.getRed())
        alert.saveIP(request)

        return redirect('/volunteer/slot/' + str(slot_id))
    else:
        slots_filled_by_this_user.delete()
        if slot.maxVolunteers is not 0:
            user_slot = User_Slot(parentSlot=slot,
                                  extraFields=slot.get_extra())
            user_slot.save()

        alert = Alert(user=request.user,
                      text="unvolunteered for " + slot.title,
                      color=Alert.getRed())
        alert.saveIP(request)

        return redirect('/volunteer/slot/' + str(slot_id))
Ejemplo n.º 8
0
def pickNewOwner(request, group_id, new_owner_id):
    group = Group.objects.get(id=group_id)
    user = User.objects.get(id=new_owner_id)
    if (group.owner == request.user and group.get_is_organzer(user)):
        group.organizers.remove(user)
        group.owner = user
        group.save()

        alert = Alert(user=request.user,
                      text="Left " + str(group.name),
                      color=Alert.getRed())
        alert.saveIP(request)
    else:
        if (not (group.get_is_organzer(user))):
            alert = Alert(user=request.user,
                          text="The new owner must be a current organizer",
                          color=Alert.getRed())
            alert.saveIP(request)
        else:
            alert = Alert(user=request.user,
                          text="You must be the owner",
                          color=Alert.getRed())
            alert.saveIP(request)
    return redirect('/groups/' + str(group_id))
Ejemplo n.º 9
0
def leave(request, group_id):
    group = Group.objects.get(id=group_id)
    if (group.get_is_organzer(request.user)
            and group.get_is_owner(request.user) == False):
        group.organizers.remove(request.user)
        group.save()
    if (group.get_is_member(request.user)):
        group.volunteers.remove(request.user)
        group.save()
    if (group.get_is_owner(request.user)):
        return render(request, "groups/pickNewOwner.html",
                      {"organizers": group.organizers.all()})

    alert = Alert(user=request.user,
                  text="Left " + str(group.name),
                  color=Alert.getRed())
    alert.saveIP(request)

    return redirect('/groups/' + str(group_id))
Ejemplo n.º 10
0
def deleteSlot(request, slot_id):
    slot = Slot.objects.get(id=slot_id)
    if slot.parentEvent is not None:
        group = slot.parentEvent.parentGroup
    else:
        group = slot.parentGroup

    if not group.get_is_organzer(request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/slot/' + str(slot.id))

    if group.get_is_organzer(request.user):
        if slot.parentEvent is not None:
            name = slot.title
            event = slot.parentEvent
            slot.delete()

            feed_entry = Feed_Entry(group=event.parentGroup,
                                    user=request.user,
                                    datetime=get_dt(),
                                    description="Deleted slot \"" + name +
                                    "\" in event \"" + event.name + "\"",
                                    url="/volunteer/slots",
                                    private=False)

            feed_entry.save()

            alert = Alert(user=request.user,
                          text="Deleted slot " + name,
                          color=Alert.getRed())
            alert.saveIP(request)

            return redirect('/volunteer/event/' + str(event.id))
        else:
            name = slot.title
            group = slot.parentGroup
            slot.delete()

            feed_entry = Feed_Entry(group=slot.parentGroup,
                                    user=request.user,
                                    datetime=get_dt(),
                                    description="Deleted slot \"" + name +
                                    "\" in group \"" + group.name + "\"",
                                    url="/volunteer/slots",
                                    private=False)

            feed_entry.save()

            alert = Alert(user=request.user,
                          text="Deleted slot " + name,
                          color=Alert.getRed())
            alert.saveIP(request)

            return redirect('/groups/' + str(group.id))
    else:
        alert = Alert(user=request.user,
                      text="Only organizers can delete slots",
                      color=Alert.getRed())
        alert.saveIP(request)

        return redirect("/volunteer/slot/" + str(slot.id))
Ejemplo n.º 11
0
def logoutLander(request):
    alert = Alert(text="You logged out", color=Alert.getRed())
    alert.saveIP(request)

    return redirect('/login')