Example #1
0
def check_club(request, club = None):
    club = get_object_or_404(Club, Slug = club)
    members = set(club.Members.all())
    
    for practice in club.practice_set.order_by('Date'):
        for pr in practice.practicerecord_set.all():
            if pr.Person not in members:
                mr = MemberRecord(Person = pr.Person, 
                                    DateOccured = practice.Date,
                                    Club = club)
                mr.save()
                messages.success(request, '%s was added succeessfuly to the club.' % pr.Person.Name)
    update_player_active_qset(club.Members.all(), club, request = request)
    
    return HttpResponseRedirect(club.get_absolute_url())
Example #2
0
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))