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))
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))
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})
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})
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))
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))
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})
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})