reg/views.py
changeset 8 e2699e042129
parent 6 057498d12450
child 9 e29ecb7819e7
equal deleted inserted replaced
7:af9ab5ad2786 8:e2699e042129
    73         else:
    73         else:
    74             return render_to_response('register.html', {'form':form})
    74             return render_to_response('register.html', {'form':form})
    75     else:
    75     else:
    76         form = reg_forms.RegisterForm()
    76         form = reg_forms.RegisterForm()
    77         return render_to_response('register.html', {'form':form})
    77         return render_to_response('register.html', {'form':form})
       
    78 
       
    79 def create_event(request):
       
    80     """ see if the user is a staff and only then let him do it.
       
    81     """
       
    82 
       
    83     user = request.user
       
    84     if user.is_authenticated() and user.is_staff:
       
    85         if request.method ==  "POST":
       
    86             form = reg_forms.EventCreateForm(request.POST)
       
    87             if form.is_valid():
       
    88                 data = form.cleaned_data
       
    89                 new_event = reg_events.create_event(title=data['title'],
       
    90                                                     description=data['description'],
       
    91                                                     start_date=data['start_date'],
       
    92                                                     stop_date=data['stop_date'],
       
    93                                                     created_by=user,
       
    94                                                    )
       
    95                 event_url = "/reg/event/view/%s"%(new_event.key)
       
    96                 return redirect(event_url)
       
    97             else:
       
    98                 return render_to_response('event_create.html', {'form':form})
       
    99         else:
       
   100             form = reg_forms.EventCreateForm()
       
   101             return render_to_response('event_create.html', {'form':form})
       
   102     else:
       
   103         return redirect('/reg')
       
   104 
       
   105 def view_event(request, key):
       
   106     """ get the event by its key and display it.
       
   107     """
       
   108 
       
   109     user = request.user
       
   110     is_guest = False if user.is_authenticated() else True
       
   111 
       
   112     try:
       
   113         event = Event.objects.get(key__iexact=key)
       
   114     except Event.DoesNotExist:
       
   115         return HttpResponse("F off")
       
   116 
       
   117     return HttpResponse(str(event))
       
   118