Esempio n. 1
0
def edit_org(request, org_id):
  authenticate(request, VALID_FACTORS)
  username = request.META['REMOTE_USER']
  user = SinUser.objects.get(username__exact = username)

  if org_id != '':
    o = request.user.signator_set.get(id = org_id)
  else:
    if user.attended_signator_training == False:
      # We really need a better error message
      http = '<p>According to our records, you are not a trained signator yet. If you have attended signator training, know it may take up to 48 hours for that to be reflected. After that time, you are free to pester the finance people on senate, until they pester the webmasters enough to add you as signators. In the meantime, <a href="http://sin.reed.edu/webapps/organization-manager/">return to the previous page</a>.</p>'
      return HttpResponse(http)
      #raise Http401
    o = Organization()
    o.name = ""
    o.signator = request.user
    o.location = ""
    o.phone_number = ""
    o.email = request.user.email
    o.website = ""
    o.description = ""
    o.public_post_ok = True
  
  template_args = {
    'user' : request.user,
    'org' : o
  }
  
  return render_to_response('organizations/edit_org.html', template_args, context_instance=RequestContext(request))
Esempio n. 2
0
def save_org(request, org_id):
  authenticate(request, VALID_FACTORS)
  
  if request.method != "POST":
    raise Http401
  
  post_dict = request.POST
  
  name = post_dict['name']
  
  def org_with_name_exists_redirect(n):
    try:
      Organization.objects.get(name = n)
      template_args = {
        'title' : 'Error!',
        'message' : "An organization with the name `%s` already exists. Please choose another name." % n,
        'redirect' : '/webapps/organization-manager/my_organizations/'
        }
      return render_to_response('generic/alert-redirect.phtml',template_args, context_instance=RequestContext(request))
    except Organization.DoesNotExist:
      return None
  
  if (org_id != ''):
    try:
      organization = request.user.signator_set.get(id = org_id)
    except Organization.DoesNotExist:
      test = org_with_name_exists_redirect(name)
      if test != None:
        return test
      organization = Organization()
  else:
    test = org_with_name_exists_redirect(name)
    if test != None:
      return test
    organization = Organization()
  
  organization.signator = request.user
  
  for n in post_dict:
    if n in VALID_POST_FIELDS:
      organization.__setattr__(n,post_dict[n])
  organization.public_post_ok = ('on' == post_dict.get('public_post_ok','off'))
  
  organization.save()
  
  return HttpResponsePermanentRedirect('/webapps/organizations/my_organizations/')