def club_detail(request, club = None): club = get_object_or_404(Club, Slug = club) if request.method == 'POST': form = ManagerForm(request.POST) if form.is_valid() and check_manager_status(request, club): remove = form.cleaned_data['Remove'] user = form.cleaned_data['User'] if remove: club.Managers.remove(user) messages.success(request, '%s was removed as a manager for %s.' % (user.username, club.Name)) else: club.Managers.add(user) messages.success(request, '%s was added as a manager for %s.' % (user.username, club.Name)) return HttpResponseRedirect(club.get_absolute_url()) else: form = ManagerForm() info_dict = { 'club':club, 'template_name':'Dojo/Club_object_detail.html', 'manager_form':form } return render_to_response('Dojo/Club_object_detail.html', info_dict, context_instance = RequestContext(request))
def practice_detail(request, club = None, id = None): club = get_object_or_404(Club, Slug = club) practice = Practice.objects.get(id = int(id)) request.session['last_page'] = request.path if request.method == 'POST': form = PracticeForm(request.POST) if form.is_valid() and check_manager_status(request, club): person = form.cleaned_data.get('Person', None) if person is None and len(form.cleaned_data['New_person']) > 0: person, isnew = Person.objects.get_or_create(Name = form.cleaned_data['New_person']) person.save() mr = MemberRecord(Person = person, Club = club, DateOccured = practice.Date) mr.save() rr = RankRecord(Rank = 'White', Person = person, DateOccured = practice.Date) rr.save() messages.success(request, '%s was added succeessfuly to %s as a White belt.' % (person.Name, club.Name)) if person is not None: pr, new_r = PracticeRecord.objects.get_or_create(Practice = practice, DateOccured = practice.Date, Person = person) if new_r: messages.success(request, '%s was added succeessfuly to this practice.' % person.Name) if not person.memberrecord_set.filter(Club = club).exists(): mr = MemberRecord(Person = person, Club = club, DateOccured = practice.Date) mr.save() if not person.memberrecord_set.filter(Club = club).latest().is_active: prevmr = person.memberrecord_set.filter(Club = club).latest() days_gone = (prevmr.DateOccured - practice.Date).days mr = MemberRecord(Person = person, Club = club, DateOccured = practice.Date) mr.save() messages.success(request, '%s came back after %i days of inactivity!' % (person.Name, abs(days_gone))) tech = form.cleaned_data.get('Technique', None) if tech is None and len(form.cleaned_data['New_technique']) > 0: print 'form', form.cleaned_data['New_technique'] is None tech, isnew = Technique.objects.get_or_create(Name = form.cleaned_data['New_technique']) if tech: practice.technique_set.add(tech) messages.success(request, 'Sucessfully added the %s Technique' % tech.Name) return HttpResponseRedirect(practice.get_absolute_url()) else: form = PracticeForm() print 'made in get' info_dict = { 'form':form, 'club':club, 'practice':practice } print info_dict return render_to_response('Dojo/Practice_object_detail.html', info_dict, context_instance = RequestContext(request))