Ejemplo n.º 1
0
def createUser(request, redirectURL='/admin/accounts/'):
    if request.method == 'POST':
        form = UserFormAdmin(request.POST, request.FILES)
        if form.is_valid():
            (user, password) = form.save()
            if request.FILES.get('picture', False):
                (filename,
                 content) = handle_uploaded_picture(request.FILES['picture'],
                                                    MAX_IMG_SIZE,
                                                    THUMB_IMG_SIZE)
                userprofile = user.profile
                userprofile.picture.delete()
                userprofile.picture.save(filename[0], content[0])
                userprofile.picture_thumb.delete()
                userprofile.picture_thumb.save(filename[1], content[1])
                userprofile.save()
            user.save()
            #emailPassword(user.email, password)
            mail_send([user.email], password, 'mail/password_reset')
            return HttpResponseRedirect(redirectURL)
    else:
        form = UserFormAdmin()
    return render_to_response('accounts/customadmin/create.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def deactivateEvent(request, event_id, redirectURL='/admin/events/requests/'):
    ''' Deactivate Event object '''
    event = get_object_or_404(Event, pk=event_id)
    if request.method == 'POST':  # form submitted
        if request.POST['confirm'] == u'Yes':
            event.is_published = False
            event.is_declined = False
            ps = event.get_assigned_proctors_can_email()
            proctors = [u.email for u in ps] if ps else []
            if proctors:
                mail_send(proctors,
                          event,
                          'mail/proctor_event_removed',
                          calendar=True,
                          calendarCancel=True)
            event.event_assigned_proctors.clear()
            recipients = [event.event_contact_email]
            mail_send(recipients, event, 'mail/requester_removed_request')
            event.save()
        return HttpResponseRedirect(redirectURL)
    return render_to_response('events/customadmin/confirm.html', {
        'mode': 'deactivate',
        'event_id': event_id,
        'event': event
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
 def save(self):
   fd = self.cleaned_data
   cs = ContactSubmission(fd['subject'], fd['message'], fd['name'], fd['phone'], fd['email'])
   mail_send([CONTACT_FORM_EMAIL], cs, 'mail/contact_form')
   if fd['cc_myself'] and fd['email']:
     mail_send([fd['email']], cs, 'mail/contact_form')
   return cs
Ejemplo n.º 4
0
def newEvent(request, redirectURL='/admin/events/requests/'):
    if request.method == 'POST':
        form = EventFormAdmin(request.POST)
        if form.is_valid():
            # form passed validation, and objects in form.cleaned_data dict.
            fd = form.cleaned_data
            try:
                event = Event(
                    event_title=fd['event_title'],
                    event_date=fd['event_date'],
                    event_duration=fd['event_duration'],
                    event_audience=fd['event_audience'],
                    event_visitors=fd['event_visitors'],
                    event_component_vizwall=fd['event_component_vizwall'],
                    event_component_3dtv=fd['event_component_3dtv'],
                    event_component_omni=fd['event_component_omni'],
                    event_component_hd2=fd['event_component_hd2'],
                    event_component_smart=fd['event_component_smart'],
                    event_assistance=fd['event_assistance'],
                    event_contact_name=fd['event_contact_name'],
                    event_contact_dept=fd['event_contact_dept'],
                    event_contact_exec=fd['event_contact_exec'],
                    event_contact_phone=fd['event_contact_phone'],
                    event_contact_email=fd['event_contact_email'],
                    event_details=fd['event_details'],
                    event_is_published=fd['event_is_published'],
                    event_is_declined=fd['event_is_declined'])
                #event_assigned_proctors=fd['event_assigned_proctors'])
                # conflicts are checked upon form validation method so no checking here!
                event.save(
                )  # have to save the event before assigning the proctors in order for the manytomany relationship to be created.
                assignedProctors = event.assign_proctors_byID(fd['proctors'])
                event.save()  # save again to make the final call
                ps = event.get_assigned_proctors_can_email()
                proctors = [u.email for u in ps] if ps else []
                if proctors:
                    mail_send(proctors,
                              event,
                              'mail/proctor_new_assignment',
                              calendar=True)
                # don't send mail to schedulers! they already know!
                # send mail confirmation to requester
                recipients = [event.event_contact_email]
                mail_send(recipients,
                          event,
                          'mail/requester_confirm_request',
                          calendar=True)
            except:
                # Something bad happened, apologize and tell them to contact us.
                return render_to_response(
                    'events/customadmin/eventrequest.html', {'form': form},
                    context_instance=RequestContext(request))
            # eveything suceeded, lets redirect to pending events page
            return HttpResponseRedirect(redirectURL)
    else:
        # they need to fill the form out
        form = EventForm()
    return render_to_response('events/eventrequest.html', {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
 def save(self):
     fd = self.cleaned_data
     cs = ContactSubmission(fd['subject'], fd['message'], fd['name'],
                            fd['phone'], fd['email'])
     mail_send([CONTACT_FORM_EMAIL], cs, 'mail/contact_form')
     if fd['cc_myself'] and fd['email']:
         mail_send([fd['email']], cs, 'mail/contact_form')
     return cs
Ejemplo n.º 6
0
def activateUser(request, user_id, redirectURL='/admin/accounts/'):
  user = get_object_or_404(User, pk=user_id)
  user.is_active = True
  password = User.objects.make_random_password(length=15)
  user.set_password(password)
  userprofile = user.get_profile()
  userprofile.last_update_profile = datetime.datetime.now()
  userprofile.save()
  user.save()
  mail_send([user.email], password, 'mail/password_reset')
  return HttpResponseRedirect(redirectURL)
Ejemplo n.º 7
0
def activateUser(request, user_id, redirectURL='/admin/accounts/'):
    user = get_object_or_404(User, pk=user_id)
    user.is_active = True
    password = User.objects.make_random_password(length=15)
    user.set_password(password)
    userprofile = user.get_profile()
    userprofile.last_update_profile = datetime.datetime.now()
    userprofile.save()
    user.save()
    mail_send([user.email], password, 'mail/password_reset')
    return HttpResponseRedirect(redirectURL)
Ejemplo n.º 8
0
def editUser(request, user_id, redirectURL='/admin/accounts/'):
    user = get_object_or_404(User, pk=user_id)
    userprofile = user.get_profile()
    if request.method == 'POST':
        form = UserFormAdmin(request.POST, request.FILES)
        if form.is_valid():
            (user, userprofile) = form.update_user(user_id)
            if form.cleaned_data[
                    'reset_password'] == True and form.cleaned_data[
                        'is_active'] == True:
                password = form.do_reset_password(user_id)
                email = form.cleaned_data['email']
                mail_send([email], password, 'mail/password_reset')
            if request.FILES.get('picture', False):
                (filename,
                 content) = handle_uploaded_picture(request.FILES['picture'],
                                                    MAX_IMG_SIZE,
                                                    THUMB_IMG_SIZE)
                userprofile.picture.delete()
                userprofile.picture.save(filename[0], content[0])
                userprofile.picture_thumb.delete()
                userprofile.picture_thumb.save(filename[1], content[1])
            userprofile.save()
            user.save()
            return HttpResponseRedirect(redirectURL)
    data = {
        'username': user.username,
        'email': user.email,
        'firstname': user.first_name,
        'lastname': user.last_name,
        'is_active': user.is_active,
        'is_staff': user.is_staff,
        'is_superuser': user.is_superuser,
        'is_leadership_team': userprofile.is_leadership_team,
        'is_vizlab_staff': userprofile.is_vizlab_staff,
        'is_demo_presenter': userprofile.demo_presenter,
        'is_scheduler': userprofile.is_scheduler,
        'is_event_emails_only': userprofile.extra_get_event_emails,
        'is_force_no_emails': userprofile.force_no_emails,
        'formal_prefix': userprofile.formal_name,
        'faculty_webpage': userprofile.faculty_webpage,
        'staff_position_number': userprofile.staff_position,
        'faculty_position': userprofile.staff_faculty_position,
        'rank_order': userprofile.rank_order,
        'picture': userprofile.picture,
        'reset_password': False
    }
    form = UserFormAdmin(data)
    return render_to_response('accounts/customadmin/edit.html', {
        'form': form,
        'user_id': user_id,
        'redirectURL': redirectURL
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def declineEvent(request, event_id, redirectURL='/admin/events/requests/'):
  ''' Removed 'Declined' Status of event and allows it to show back up in pending events'''
  event = get_object_or_404(Event, pk=event_id)
  event.event_is_declined = True
  event.event_is_published = False
  ps = event.get_assigned_proctors()
  proctors = [u.email for u in ps] if proctors else None
  if proctors: mail_send(proctors, event, 'mail/proctor_event_removed', calendar=True, calendarCancel=True)
  event.event_assigned_proctors.clear()
  mail_send([event.event_contact_email], event, 'mail/requester_deny_request')
  event.save()
  return HttpResponseRedirect(redirectURL)
Ejemplo n.º 10
0
def requestConfirm(request, event_id, redirectURL='/admin/events/requests/'):
  ''' Publish Event object '''
  event = get_object_or_404(Event, pk=event_id)
  event.event_is_published = True
  event.event_is_declined = False
  ps = event.get_assigned_proctors_can_email()
  proctors = [u.email for u in ps] if ps else []
  if proctors: mail_send(proctors, event, 'mail/proctor_event_removed', calendar=True)
  recipients = [event.event_contact_email]
  mail_send(recipients, event, 'mail/requester_confirm_request')
  event.save()
  return HttpResponseRedirect(redirectURL)
Ejemplo n.º 11
0
def requestConfirm(request, event_id, redirectURL='/admin/events/requests/'):
    ''' Publish Event object '''
    event = get_object_or_404(Event, pk=event_id)
    event.event_is_published = True
    event.event_is_declined = False
    ps = event.get_assigned_proctors_can_email()
    proctors = [u.email for u in ps] if ps else []
    if proctors:
        mail_send(proctors, event, 'mail/proctor_event_removed', calendar=True)
    recipients = [event.event_contact_email]
    mail_send(recipients, event, 'mail/requester_confirm_request')
    event.save()
    return HttpResponseRedirect(redirectURL)
 def handle_noargs(self, **options):
   n = datetime.datetime.now()
   t = n + datetime.timedelta(days=1)
   events = Event.objects.all().filter(
         event_date__gte=datetime.date(n.year, n.month, n.day),
         event_date__lte=datetime.date(t.year, t.month, t.day),
         event_is_published=True, event_is_declined=False)
   if events:
     for event in events:
       ps = event.get_assigned_proctors_can_email()
       if ps:
         proctors = [u.email for u in ps]
         mail_send(ps, event, 'mail/proctor_reminder')
Ejemplo n.º 13
0
def editEvent(request, event_id, redirectURL='/admin/events/'):
  event = get_object_or_404(Event, pk=event_id)
  if request.method == 'POST': # form submitted
    form = EventFormAdmin(request.POST, instance=event, event_id=event_id) # repopulate form with edited data
    if form.is_valid(): # valid edits
      fd = form.cleaned_data
      event.event_last_modified = datetime.datetime.now()
      event.event_title = fd['event_title']
      event.event_date = fd['event_date']
      event.event_duration=fd['event_duration']
      event.event_audience=fd['event_audience']
      event.event_visitors=fd['event_visitors']
      event.event_component_vizwall=fd['event_component_vizwall']
      event.event_component_3dtv=fd['event_component_3dtv']
      event.event_component_omni=fd['event_component_omni']
      event.event_component_hd2=fd['event_component_hd2']
      event.event_component_smart=fd['event_component_smart']
      event.event_assistance=fd['event_assistance']
      event.event_contact_name=fd['event_contact_name']
      event.event_contact_dept=fd['event_contact_dept']
      event.event_contact_exec=fd['event_contact_exec']
      event.event_contact_phone=fd['event_contact_phone']
      event.event_contact_email=fd['event_contact_email']
      event.event_details=fd['event_details']
      event.event_is_published=fd['event_is_published']
      event.event_is_declined=fd['event_is_declined']
      #event.event_assigned_proctors=fd['event_assigned_proctors']
      #event.save()
      ps = event.get_assigned_proctors_can_email()
      oldProctors = [u.email for u in ps] if ps else []
      aps = event.assign_proctors_byID(fd['proctors'])
      assignedProctors = [u.email for u in aps] if aps else []
      event.save()
      proctorsRemoved = []
      proctorsAdded = []
      # send email to proctors being added that event is added
      if assignedProctors:
        for p in assignedProctors:
          if p not in oldProctors:
            proctorsAdded.append(p)
      if proctorsAdded: mail_send(proctorsAdded, event, 'mail/proctor_new_assignment', calendar=True)
      # send email to proctors being removed that event is cancelled
      if oldProctors:
        for p in oldProctors:
          if p not in assignedProctors:
            proctorsRemoved.append(p)
      if proctorsRemoved: mail_send(proctorsRemoved, event, 'mail/proctor_event_removed', calendar=True, calendarCancel=False)
      return HttpResponseRedirect(redirectURL)
  else:
    form = EventFormAdmin(instance=event, event_id=event_id)
  return render_to_response('events/customadmin/event_edit.html', {'form': form, 'event': event, 'event_id': event_id, 'req_date': event.event_req_date, 'last_mod_date': event.event_last_modified}, context_instance=RequestContext(request))
Ejemplo n.º 14
0
def deleteEvent(request, event_id, redirectURL='/admin/events/requests/'):
  ''' Delete Event object '''
  event = get_object_or_404(Event, pk=event_id)
  if request.method == 'POST': # form submitted
    if request.POST['confirm'] == u'Yes':
      ps = event.get_assigned_proctors_can_email()
      proctors = [u.email for u in ps] if ps else []
      if proctors: mail_send(proctors, event, 'mail/proctor_event_removed', calendar=True, calendarCancel=True)
      event.event_assigned_proctors.clear()
      recipients = [event.event_contact_email]
      mail_send(recipients, event, 'mail/requester_removed_request')
      event.delete() # deletes! no backups!
    return HttpResponseRedirect(redirectURL)
  return render_to_response('events/customadmin/confirm.html', {'mode': 'delete', 'event_id': event_id, 'event': event}, context_instance=RequestContext(request))
 def handle_noargs(self, **options):
     n = datetime.datetime.now()
     t = n + datetime.timedelta(days=1)
     events = Event.objects.all().filter(
         event_date__gte=datetime.date(n.year, n.month, n.day),
         event_date__lte=datetime.date(t.year, t.month, t.day),
         event_is_published=True,
         event_is_declined=False)
     if events:
         for event in events:
             ps = event.get_assigned_proctors_can_email()
             if ps:
                 proctors = [u.email for u in ps]
                 mail_send(ps, event, 'mail/proctor_reminder')
Ejemplo n.º 16
0
def requestEvent(request):
    if request.method == 'POST':  # if form has been submitted...
        form = EventForm(request.POST)
        if form.is_valid():
            # form passed validation, and objects in form.cleaned_data dict.
            fd = form.cleaned_data
            try:
                event = Event(
                    event_title=fd['event_title'],
                    event_date=fd['event_date'],
                    event_duration=fd['event_duration'],
                    event_audience=fd['event_audience'],
                    event_visitors=fd['event_visitors'],
                    event_component_vizwall=fd['event_component_vizwall'],
                    event_component_3dtv=fd['event_component_3dtv'],
                    event_component_omni=fd['event_component_omni'],
                    event_component_hd2=fd['event_component_hd2'],
                    event_component_smart=fd['event_component_smart'],
                    event_assistance=fd['event_assistance'],
                    event_contact_name=fd['event_contact_name'],
                    event_contact_dept=fd['event_contact_dept'],
                    event_contact_exec=fd['event_contact_exec'],
                    event_contact_phone=fd['event_contact_phone'],
                    event_contact_email=fd['event_contact_email'],
                    event_details=fd['event_details'])
                # conflicts are checked upon form validation method so no checking here!
                event.save()
                # send mail to schedulers about new event
                schedulers = [
                    u.user.email for u in UserProfile.objects.all().filter(
                        is_scheduler=True, force_no_emails=False)
                ]
                mail_send(schedulers, event, 'mail/sched_new_request')
                # send mail confirmation to requester
                recipients = [event.event_contact_email]
                mail_send(recipients, event, 'mail/requester_new_request')
            except:
                # Something bad happened, apologize and tell them to contact us.
                return render_to_response(
                    'events/eventrequest.html', {'form': form},
                    context_instance=RequestContext(request))
            # eveything suceeded, lets redirect for confirmation!
            return HttpResponseRedirect('/events/request/confirm/')
    else:
        # they need to fill the form out
        form = EventForm()
    return render_to_response('events/eventrequest.html', {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 17
0
def newEvent(request, redirectURL='/admin/events/requests/'):
  if request.method == 'POST':
    form = EventFormAdmin(request.POST)
    if form.is_valid():
      # form passed validation, and objects in form.cleaned_data dict.
      fd = form.cleaned_data
      try:
        event = Event(event_title=fd['event_title'], event_date=fd['event_date'],
                  event_duration=fd['event_duration'],
                  event_audience=fd['event_audience'],
                  event_visitors=fd['event_visitors'],
                  event_component_vizwall=fd['event_component_vizwall'],
                  event_component_3dtv=fd['event_component_3dtv'],
                  event_component_omni=fd['event_component_omni'],
                  event_component_hd2=fd['event_component_hd2'],
                  event_component_smart=fd['event_component_smart'],
                  event_assistance=fd['event_assistance'],
                  event_contact_name=fd['event_contact_name'],
                  event_contact_dept=fd['event_contact_dept'],
                  event_contact_exec=fd['event_contact_exec'],
                  event_contact_phone=fd['event_contact_phone'],
                  event_contact_email=fd['event_contact_email'],
                  event_details=fd['event_details'],
                  event_is_published=fd['event_is_published'],
                  event_is_declined=fd['event_is_declined'])
                  #event_assigned_proctors=fd['event_assigned_proctors'])
        # conflicts are checked upon form validation method so no checking here!
        event.save() # have to save the event before assigning the proctors in order for the manytomany relationship to be created.
        assignedProctors = event.assign_proctors_byID(fd['proctors'])
        event.save() # save again to make the final call
        ps = event.get_assigned_proctors_can_email()
        proctors = [u.email for u in ps] if ps else []
        if proctors: mail_send(proctors, event, 'mail/proctor_new_assignment', calendar=True)
        # don't send mail to schedulers! they already know!
        # send mail confirmation to requester
        recipients = [event.event_contact_email]
        mail_send(recipients, event, 'mail/requester_confirm_request', calendar=True)
      except:
        # Something bad happened, apologize and tell them to contact us.
        return render_to_response('events/customadmin/eventrequest.html', {'form': form}, context_instance=RequestContext(request))
      # eveything suceeded, lets redirect to pending events page
      return HttpResponseRedirect(redirectURL)
  else:
    # they need to fill the form out
    form = EventForm()
  return render_to_response('events/eventrequest.html', {'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 18
0
def declineEvent(request, event_id, redirectURL='/admin/events/requests/'):
    ''' Removed 'Declined' Status of event and allows it to show back up in pending events'''
    event = get_object_or_404(Event, pk=event_id)
    event.event_is_declined = True
    event.event_is_published = False
    ps = event.get_assigned_proctors()
    proctors = [u.email for u in ps] if proctors else None
    if proctors:
        mail_send(proctors,
                  event,
                  'mail/proctor_event_removed',
                  calendar=True,
                  calendarCancel=True)
    event.event_assigned_proctors.clear()
    mail_send([event.event_contact_email], event,
              'mail/requester_deny_request')
    event.save()
    return HttpResponseRedirect(redirectURL)
Ejemplo n.º 19
0
def editUser(request, user_id, redirectURL='/admin/accounts/'):
  user = get_object_or_404(User, pk=user_id)
  userprofile = user.get_profile()
  if request.method == 'POST':
    form = UserFormAdmin(request.POST, request.FILES)
    if form.is_valid():
      (user, userprofile) = form.update_user(user_id)
      if form.cleaned_data['reset_password'] == True and form.cleaned_data['is_active'] == True:
        password = form.do_reset_password(user_id)
        email = form.cleaned_data['email']
        mail_send([email], password, 'mail/password_reset')
      if request.FILES.get('picture', False):
        (filename, content) = handle_uploaded_picture(request.FILES['picture'], MAX_IMG_SIZE, THUMB_IMG_SIZE)
        userprofile.picture.delete()
        userprofile.picture.save(filename[0], content[0])
        userprofile.picture_thumb.delete()
        userprofile.picture_thumb.save(filename[1], content[1])
      userprofile.save()
      user.save()
      return HttpResponseRedirect(redirectURL)
  data = {'username': user.username,
          'email': user.email,
          'firstname': user.first_name,
          'lastname': user.last_name,
          'is_active': user.is_active,
          'is_staff': user.is_staff,
          'is_superuser': user.is_superuser,
          'is_leadership_team': userprofile.is_leadership_team,
          'is_vizlab_staff': userprofile.is_vizlab_staff,
          'is_demo_presenter': userprofile.demo_presenter,
          'is_scheduler': userprofile.is_scheduler,
          'is_event_emails_only': userprofile.extra_get_event_emails,
          'is_force_no_emails': userprofile.force_no_emails,
          'formal_prefix': userprofile.formal_name,
          'faculty_webpage': userprofile.faculty_webpage,
          'staff_position_number': userprofile.staff_position,
          'faculty_position': userprofile.staff_faculty_position,
          'rank_order': userprofile.rank_order,
          'picture': userprofile.picture,
          'reset_password': False}
  form = UserFormAdmin(data)
  return render_to_response('accounts/customadmin/edit.html', {'form': form, 'user_id': user_id, 'redirectURL': redirectURL}, context_instance=RequestContext(request))
Ejemplo n.º 20
0
def createUser(request, redirectURL='/admin/accounts/'):
  if request.method == 'POST':
    form = UserFormAdmin(request.POST, request.FILES)
    if form.is_valid():
      (user, password) = form.save()
      if request.FILES.get('picture', False):
        (filename, content) = handle_uploaded_picture(request.FILES['picture'], MAX_IMG_SIZE, THUMB_IMG_SIZE)
        userprofile = user.profile
        userprofile.picture.delete()
        userprofile.picture.save(filename[0], content[0])
        userprofile.picture_thumb.delete()
        userprofile.picture_thumb.save(filename[1], content[1])
        userprofile.save()
      user.save()
      #emailPassword(user.email, password)
      mail_send([user.email], password, 'mail/password_reset')
      return HttpResponseRedirect(redirectURL)
  else:
    form = UserFormAdmin()
  return render_to_response('accounts/customadmin/create.html', {'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 21
0
def requestEvent(request):
  if request.method == 'POST': # if form has been submitted...
   form = EventForm(request.POST)
   if form.is_valid():
    # form passed validation, and objects in form.cleaned_data dict.
    fd = form.cleaned_data
    try:
      event = Event(event_title=fd['event_title'], event_date=fd['event_date'],
                event_duration=fd['event_duration'],
                event_audience=fd['event_audience'],
                event_visitors=fd['event_visitors'],
                event_component_vizwall=fd['event_component_vizwall'],
                event_component_3dtv=fd['event_component_3dtv'],
                event_component_omni=fd['event_component_omni'],
                event_component_hd2=fd['event_component_hd2'],
                event_component_smart=fd['event_component_smart'],
                event_assistance=fd['event_assistance'],
                event_contact_name=fd['event_contact_name'],
                event_contact_dept=fd['event_contact_dept'],
                event_contact_exec=fd['event_contact_exec'],
                event_contact_phone=fd['event_contact_phone'],
                event_contact_email=fd['event_contact_email'],
                event_details=fd['event_details'])
      # conflicts are checked upon form validation method so no checking here!
      event.save()
      # send mail to schedulers about new event
      schedulers = [u.user.email for u in UserProfile.objects.all().filter(is_scheduler=True,force_no_emails=False)]
      mail_send(schedulers, event, 'mail/sched_new_request')
      # send mail confirmation to requester
      recipients = [event.event_contact_email]
      mail_send(recipients, event, 'mail/requester_new_request')
    except:
      # Something bad happened, apologize and tell them to contact us.
      return render_to_response('events/eventrequest.html', {'form': form}, context_instance=RequestContext(request))
    # eveything suceeded, lets redirect for confirmation!
    return HttpResponseRedirect('/events/request/confirm/')
  else:
    # they need to fill the form out
    form = EventForm()
  return render_to_response('events/eventrequest.html', {'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 22
0
def editEvent(request, event_id, redirectURL='/admin/events/'):
    event = get_object_or_404(Event, pk=event_id)
    if request.method == 'POST':  # form submitted
        form = EventFormAdmin(
            request.POST, instance=event,
            event_id=event_id)  # repopulate form with edited data
        if form.is_valid():  # valid edits
            fd = form.cleaned_data
            event.event_last_modified = datetime.datetime.now()
            event.event_title = fd['event_title']
            event.event_date = fd['event_date']
            event.event_duration = fd['event_duration']
            event.event_audience = fd['event_audience']
            event.event_visitors = fd['event_visitors']
            event.event_component_vizwall = fd['event_component_vizwall']
            event.event_component_3dtv = fd['event_component_3dtv']
            event.event_component_omni = fd['event_component_omni']
            event.event_component_hd2 = fd['event_component_hd2']
            event.event_component_smart = fd['event_component_smart']
            event.event_assistance = fd['event_assistance']
            event.event_contact_name = fd['event_contact_name']
            event.event_contact_dept = fd['event_contact_dept']
            event.event_contact_exec = fd['event_contact_exec']
            event.event_contact_phone = fd['event_contact_phone']
            event.event_contact_email = fd['event_contact_email']
            event.event_details = fd['event_details']
            event.event_is_published = fd['event_is_published']
            event.event_is_declined = fd['event_is_declined']
            #event.event_assigned_proctors=fd['event_assigned_proctors']
            #event.save()
            ps = event.get_assigned_proctors_can_email()
            oldProctors = [u.email for u in ps] if ps else []
            aps = event.assign_proctors_byID(fd['proctors'])
            assignedProctors = [u.email for u in aps] if aps else []
            event.save()
            proctorsRemoved = []
            proctorsAdded = []
            # send email to proctors being added that event is added
            if assignedProctors:
                for p in assignedProctors:
                    if p not in oldProctors:
                        proctorsAdded.append(p)
            if proctorsAdded:
                mail_send(proctorsAdded,
                          event,
                          'mail/proctor_new_assignment',
                          calendar=True)
            # send email to proctors being removed that event is cancelled
            if oldProctors:
                for p in oldProctors:
                    if p not in assignedProctors:
                        proctorsRemoved.append(p)
            if proctorsRemoved:
                mail_send(proctorsRemoved,
                          event,
                          'mail/proctor_event_removed',
                          calendar=True,
                          calendarCancel=False)
            return HttpResponseRedirect(redirectURL)
    else:
        form = EventFormAdmin(instance=event, event_id=event_id)
    return render_to_response('events/customadmin/event_edit.html', {
        'form': form,
        'event': event,
        'event_id': event_id,
        'req_date': event.event_req_date,
        'last_mod_date': event.event_last_modified
    },
                              context_instance=RequestContext(request))