Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
def edit_profile(request):
    profile = request.user.profile
    if request.POST:
        form = EditProfileForm(request.POST, profile=profile)
        form2 = EditUserForm(request.POST, instance=request.user)
        if form.is_valid() and form2.is_valid():
            data = form.save(commit=False)
            profile.bio = data['bio']
            profile.slotName = data['slotName']
            profile.eventName = data['eventName']
            profile.save()
            form2.save()

            alert = Alert(user=request.user,
                          text="Profile updated",
                          color=Alert.getYellow())
            alert.saveIP(request)

            return redirect('/accounts/profile/')
    form = EditProfileForm(
        initial={
            'bio': profile.bio,
            'slotName': profile.slotName,
            'eventName': profile.eventName
        })
    form2 = EditUserForm(instance=request.user)

    return render(request, 'accounts/edit_profile.html', {
        "form": form,
        'profile': profile,
        "form2": form2
    })
Ejemplo n.º 6
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.º 7
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.º 8
0
def edit_password(request):
    user = request.user
    form = PasswordChangeForm(user=request.user, data=request.POST)
    if request.POST:
        if form.is_valid():
            form.save()
            update_session_auth_hash(request, user)
            alert = Alert(user=request.user,
                          text="Password updated",
                          color=Alert.getYellow())
            alert.saveIP(request)

            return redirect('/accounts/profile')

    return render(request, 'accounts/edit_password.html', {"form": form})
Ejemplo n.º 9
0
def signin(request, user_slot_id):
    next = request.GET.get('next')

    user_slot = User_Slot.objects.get(id=user_slot_id)

    group = user_slot.parentSlot.get_group()

    if (user_slot.volunteer != None and group.get_is_organzer(request.user)):
        user_slot.signin = get_dt()
        user_slot.save()

        alert = Alert(user=request.user,
                      text="Signed in " + user_slot.volunteer.username,
                      color=Alert.getYellow())
        alert.saveIP(request)
    return redirect(next)
Ejemplo n.º 10
0
def update(request, group_id):
    group = Group.objects.get(id=group_id)
    owner = group.owner
    if request.user.is_authenticated():
        form = EditGroupForm(request.POST, id=group_id)
        if form.is_valid():
            data = form.save(commit=False)
            group.name = data['name']
            group.tagline = data['tagline']
            group.description = data['description']
            group.email = data['email']
            group.website = data['website']
            group.location = data['location']
            group.address = data['address']
            group.city = data['city']
            group.state = data['state']
            group.zip_code = data['zip_code']
            group.approvalNeeded = data['approvalNeeded']
            group.private = data['private']

            group.save()

            alert = Alert(user=request.user,
                          text="Updated group " + group.name,
                          color=Alert.getBlue())
            alert.saveIP(request)

            return redirect("/groups/" + str(group.id))

    form = EditGroupForm(id=group_id,
                         initial={
                             'name': group.name,
                             'tagline': group.tagline,
                             'description': group.description,
                             'email': group.email,
                             'website': group.website,
                             'location': group.location,
                             'address': group.address,
                             'city': group.city,
                             'state': group.state,
                             'zip_code': group.zip_code,
                             'approvalNeeded': group.approvalNeeded,
                             'private': group.private
                         })

    return render(request, 'groups/edit_group.html', {'form': form})
Ejemplo n.º 11
0
def editEvent(request, event_id):
    event = Event.objects.get(id=event_id)
    group = event.parentGroup
    if not Group.get_is_organzer(group, request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/event/' + str(event.id))

    if request.method == 'POST':
        form = UpdateEventForm(request.POST, id=event_id)
        if form.is_valid():
            data = form.save(commit=False)
            event.name = data['title']
            event.description = data['description']
            event.location = data['location']
            event.address = data['address']
            event.city = data['city']
            event.state = data['state']
            event.zip_code = data['zip_code']
            event.start = data['start']
            event.end = data['end']
            event.private = data['private']

            event.save()

            alert = Alert(user=request.user,
                          text="Updated Event " + event.name,
                          color=Alert.getBlue())
            alert.saveIP(request)

            return redirect('eventView', event_id)

    form = UpdateEventForm(id=event_id,
                           initial={
                               'title': event.name,
                               'description': event.description,
                               'location': event.location,
                               'address': event.address,
                               'city': event.city,
                               'state': event.state,
                               'zip_code': event.zip_code,
                               'start': event.start.strftime("%Y-%m-%dT%H:%M"),
                               'end': event.end.strftime("%Y-%m-%dT%H:%M"),
                               'private': event.private
                           })

    return render(request, 'organizer/edit_event.html', {'form': form})
Ejemplo n.º 12
0
def signup(request):
    # Checks if the user is sending their data (POST) or getting the form (GET)
    if (request.method == 'POST'):
        form = SignupForm(request.POST)
        # Makes sure the user filled out the form correctly as dictated by forms.py
        if form.is_valid():
            user = form.save(commit=False)
            # Sets the user to deactive until they confirm email
            user.is_active = False
            # Saves the user to the server
            user.save()
            # Gets the current domain in order to send the email
            current_site = get_current_site(request)
            # Sends the user an email based on the email template and the info passed in here
            message = render_to_string(
                'emails/activate_account.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            mail_subject = 'Activate your Sapphire Account!'
            to_email = form.cleaned_data.get('email')
            email = EmailMultiAlternatives(mail_subject,
                                           message,
                                           to=[to_email])
            email.content_subtype = 'html'
            email.mixed_subtype = 'related'
            fp = open('static/img/logos.ico/ms-icon-70x70.png', 'rb')
            logo = MIMEImage(fp.read())
            logo.add_header('Content-ID', '<logo>')
            email.attach(logo)
            email.send()

            alert = Alert(
                user=user,
                text=
                "Click on the link sent to your email to confirm your account",
                color=Alert.getYellow())
            alert.saveIP(request)
            return redirect('/login')
            #return render(request, 'accounts/please_confirm.html')
    else:
        form = SignupForm()

    return render(request, 'accounts/signup.html', {'form': form})
Ejemplo n.º 13
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.º 14
0
def signout(request, user_slot_id):
    next = request.GET.get('next')
    user_slot = User_Slot.objects.get(id=user_slot_id)

    if (user_slot.parentSlot.parentEvent != None):
        group = user_slot.parentSlot.parentEvent.parentGroup
    else:
        group = user_slot.parentSlot.parentGroup

    if (user_slot.volunteer != None and group.get_is_organzer(request.user)):
        user_slot.signout = get_dt()
        user_slot.save()
        user_slot.updateDeltaTimes()

        alert = Alert(user=request.user,
                      text="Signed out " + user_slot.volunteer.username,
                      color=Alert.getYellow())
        alert.saveIP(request)

    return redirect(next)
Ejemplo n.º 15
0
def add(request):
    if request.user.is_authenticated():
        if request.method == 'GET':
            form = NewGroupForm(owner=request.user)
        else:
            form = NewGroupForm(request.POST, owner=request.user)
            if form.is_valid():
                group = form.save(commit=False)
                group.save()

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

                return redirect("/groups/" + str(group.id))

        return render(request, 'groups/add_group.html', {'form': form})

    else:
        return redirect('login')
Ejemplo n.º 16
0
def promote(request, group_id, user_id):
    group = Group.objects.get(pk=group_id)
    user = User.objects.get(pk=user_id)
    if request.user == group.owner:
        if user == group.owner:
            alert = Alert(user=request.user,
                          text="You cannot alter the owner's permissions",
                          color=Alert.getYellow())
            alert.saveIP(request)
            return redirect('/groups/' + str(group_id))
        if user in group.pendingUsers.all():
            group.pendingUsers.remove(user)
            group.volunteers.add(user)
            alert = Alert(user=request.user,
                          text=user.username + " is now a volunteer",
                          color=Alert.getYellow())
            alert.saveIP(request)
            return redirect('/groups/' + str(group_id))
        if user in group.volunteers.all():
            group.volunteers.remove(user)
            group.organizers.add(user)
            alert = Alert(user=request.user,
                          text=user.username + " is now an organizer",
                          color=Alert.getYellow())
            alert.saveIP(request)
            return redirect('/groups/' + str(group_id))
        return redirect('/groups/' + str(group_id))
    else:
        return render(request, 'not_authorized.html')
Ejemplo n.º 17
0
def signup_foruser(request, group_id, user_slot_id):
    # Checks if the user is sending their data (POST) or getting the form (GET)
    if (request.method == 'POST'):
        form = SignupForm(request.POST)
        # Makes sure the user filled out the form correctly as dictated by forms.py
        if form.is_valid():
            user = form.save(commit=False)
            # Sets the user to deactive until they confirm email
            user.is_active = False
            # Saves the user to the server
            user.save()
            # Gets the current domain in order to send the email
            current_site = get_current_site(request)
            # Sends the user an email based on the email template and the info passed in here
            message = render_to_string(
                'emails/activate_account.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            mail_subject = 'Activate your Sapphire account (named by Armaan Goel).'
            to_email = form.cleaned_data.get('email')
            email = EmailMessage(mail_subject, message, to=[to_email])
            email.send()

            alert = Alert(
                user=user,
                text=
                "Click on the link sent to your email to confirm your account",
                color=Alert.getYellow())
            alert.saveIP(request)
            return redirect('/login')
            #return render(request, 'accounts/please_confirm.html')
    else:
        form = SignupForm()

    return render(request, 'accounts/signup.html', {'form': form})
Ejemplo n.º 18
0
def join(request, group_id):
    group = Group.objects.get(id=group_id)
    if (group.get_is_member(request.user) == False):
        if (group.approvalNeeded):
            group.pendingUsers.add(request.user)
            group.save()

            alert = Alert(user=request.user,
                          text="Requested to join " + str(group.name) +
                          ", wating for organizer approval",
                          color=Alert.getGreen())
            alert.saveIP(request)

        else:
            group.volunteers.add(request.user)
            group.save()

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

    return redirect('/groups/' + str(group_id))
Ejemplo n.º 19
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.º 20
0
def addEvent(request, group_id):
    group = Group.objects.get(id=group_id)
    if not Group.get_is_organzer(group, request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/events')

    if request.method == 'POST':
        form = NewEventForm(request.POST,
                            user=request.user,
                            parentGroup=group,
                            initial={'private': group.private})
        if form.is_valid():
            event = form.save(commit=False)
            event.save()

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

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

            return redirect('/volunteer/events')
    else:
        form = NewEventForm(user=request.user,
                            parentGroup=group,
                            initial={'private': group.private})
    # Filter this by single slot events in the future
    return render(request, 'organizer/add_event.html', {'form': form})
Ejemplo n.º 21
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.º 22
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.º 23
0
def volunteerForUser(request, slot_id, user_id):
    thisUser = User.objects.get(id=user_id)
    # next = request.GET.get('next')
    slot = Slot.objects.get(id=slot_id)
    group = slot.get_group()

    if group.get_is_organzer(request.user):
        user_slot = User_Slot.objects.filter(parentSlot=slot,
                                             volunteer__isnull=True).first()
        slots_filled_by_this_user = User_Slot.objects.filter(
            parentSlot=slot, volunteer=thisUser).first()
        # This stops people from signing up twice
        # if slots_filled_by_this_user is not None:
        # 	alert = Alert(user=thisUser, text="Already volunteered", color=Alert.getRed())
        # 	alert.saveIP(request)
        #	return redirect('/volunteer/slot/' + str(slot_id))
        if user_slot is None:
            addUserSlot(request, slot_id)
            user_slot = User_Slot.objects.filter(
                parentSlot=slot, volunteer__isnull=True).first()

        user_slot.volunteer = thisUser
        user_slot.accepted = "No"
        user_slot.save()

        name = slot.title

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

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

        current_site = get_current_site(request)

        # Sends the user an email based on the email template and the info passed in here
        message = render_to_string(
            'emails/volentold.html', {
                'user': thisUser,
                'domain': current_site.domain,
                'slot': slot,
                'group': group,
            })

        mail_subject = 'You have been added to a slot'
        to_email = thisUser.email
        email = EmailMultiAlternatives(mail_subject, message, to=[to_email])
        email.content_subtype = 'html'
        email.mixed_subtype = 'related'
        fp = open('static/img/logos.ico/ms-icon-70x70.png', 'rb')
        logo = MIMEImage(fp.read())
        logo.add_header('Content-ID', '<logo>')
        email.attach(logo)
        email.send()

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

    return redirect('/login')
Ejemplo n.º 25
0
def slot(request, slot_id):
    slot = Slot.objects.get(id=slot_id)
    event = slot.parentEvent
    private = slot.private

    if (slot.parentEvent != None):
        is_organizer = Group.get_is_organzer(slot.parentEvent.parentGroup,
                                             request.user)
    else:
        is_organizer = Group.get_is_organzer(slot.parentGroup, request.user)

    user_slots = User_Slot.objects.filter(parentSlot=slot)
    is_volunteered = not (User_Slot.objects.filter(
        parentSlot=slot, volunteer=request.user).first() == None)
    pendingAccept = False
    if is_volunteered:
        for user_slot in User_Slot.objects.filter(parentSlot=slot,
                                                  volunteer=request.user):
            if user_slot.accepted == "No":
                pendingAccept = True
                break

    volunteer = request.user
    specific_user_slot = User_Slot.objects.filter(
        parentSlot=slot, volunteer=request.user).first()

    hasV = User_Slot.objects.filter(parentSlot=slot, volunteer__isnull=False)
    noV = User_Slot.objects.filter(parentSlot=slot, volunteer__isnull=True)

    if (len(User_Slot.objects.filter(parentSlot=slot)) != 0):
        percentFilled = int(
            len(
                User_Slot.objects.filter(parentSlot=slot).exclude(
                    volunteer=None)) /
            len(User_Slot.objects.filter(parentSlot=slot)) * 100)
    else:
        percentFilled = 0

    for i in hasV:
        i.prep_html()

    if pendingAccept:
        alert = Alert(
            user=request.user,
            text="You have been requested to volunteer for this slot",
            color=Alert.getBlue())
        alert.saveIP(request)

    return render(
        request, 'volunteer/slot.html', {
            'slot':
            slot,
            'user_slots':
            hasV,
            'event':
            event,
            'empty_slot':
            noV,
            'full':
            User_Slot.objects.filter(parentSlot=slot,
                                     volunteer__isnull=True).first(),
            'is_organizer':
            is_organizer,
            'percentFilled':
            percentFilled,
            'is_volunteered':
            is_volunteered,
            'offer':
            pendingAccept,
            'private':
            private,
            'specific_user_slot':
            specific_user_slot,
            'extra': (list(user_slots[0].get_extra().keys()) if
                      (len(user_slots) > 0) else []),
            'single': (slot.parentEvent == None)
        })
Ejemplo n.º 26
0
def addSlot(request, event_id):
    parentEvent = Event.objects.get(pk=event_id)
    group = parentEvent.parentGroup
    if not Group.get_is_organzer(group, request.user):
        Alert.not_permitted(request)
        return redirect('/volunteer/event/' + str(event.id))

    parentEvent = Event.objects.get(pk=event_id)

    if (request.method == 'GET'):
        form = NewSlotForm(user=request.user,
                           parentEvent=parentEvent,
                           initial={
                               'private':
                               parentEvent.private,
                               'start':
                               parentEvent.start.strftime("%Y-%m-%dT%H:%M"),
                               'end':
                               parentEvent.end.strftime("%Y-%m-%dT%H:%M")
                           })
    else:
        # This line assumes the contents of the GET side of the if statement have already run (they should have) but its kinda janky
        form = NewSlotForm(request.POST,
                           user=request.user,
                           parentEvent=parentEvent,
                           initial={
                               'private':
                               parentEvent.private,
                               'start':
                               parentEvent.start.strftime("%Y-%m-%dT%H:%M"),
                               'end':
                               parentEvent.end.strftime("%Y-%m-%dT%H:%M")
                           })
        if form.is_valid():
            slot = form.save(commit=False)
            slot.save()

            ans = OrderedDict()
            for i in slot.get_extra():
                if i != '' and i != ' ':
                    ans[i] = '-'
            print('ans for add is', ans)
            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 slot \"" +
                                    str(slot.title) + "\" in event \"" +
                                    str(slot.parentEvent.name) + "\"",
                                    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('eventView', parentEvent.id)

    return render(request, 'organizer/add_slot.html', {'form': form})
Ejemplo n.º 27
0
def editSlot(request, slot_id):
    slot = Slot.objects.get(id=slot_id)
    parentEvent = slot.parentEvent
    group = slot.parentGroup
    if (group == 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 request.method == 'POST':
        form = UpdateSlotForm(request.POST, id=slot_id)
        if form.is_valid():
            data = form.save(commit=False)
            slot.start = data['start']
            slot.end = data['end']
            slot.title = data['title']
            slot.description = data['description']
            slot.location = data['location']
            slot.paymentPerHour = data['paymentPerHour']
            slot.extraFields = data['extraFields'].replace(' ', '')
            slot.private = data['private']

            unlimited = data['unlimited']
            if (unlimited):
                slot.maxVolunteers = 0
            else:
                slot.maxVolunteers = 1

            slot.save()

            newFields = slot.get_extra()
            for user in User_Slot.objects.filter(parentSlot=slot):
                ans = OrderedDict()
                for a in newFields:
                    if a != '':
                        val = ''
                        if a in list(user.get_extra().keys()):
                            val = user.get_extra()[a]

                        if val != '' and val != ' ':
                            ans[a] = val
                        else:
                            ans[a] = '-'
                        print(ans)
                user.save_extra(ans)
                user.save()

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

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

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

    form = UpdateSlotForm(id=slot_id,
                          initial={
                              'title': slot.title,
                              'description': slot.description,
                              'location': slot.location,
                              'start': slot.start.strftime("%Y-%m-%dT%H:%M"),
                              'end': slot.end.strftime("%Y-%m-%dT%H:%M"),
                              'paymentPerHour': slot.paymentPerHour,
                              'extraFields': slot.extraFields,
                              'private': slot.private,
                              'unlimited': (slot.maxVolunteers == 0)
                          })

    return render(request, 'organizer/edit_slot.html', {'form': form})