コード例 #1
0
ファイル: views.py プロジェクト: bxm156/ServicePad
def create(request):
    """
    Create a event
    """
    if request.POST:
        new_data = request.POST.copy()
        event_form = CreateEventForm(new_data)
        if event_form.is_valid():
            #Create the event and save the values to it
            event = Event(owner=request.user)
            new_event_form = CreateEventForm(new_data,instance=event)
            new_event = new_event_form.save()
            return redirect(new_event)
        else:
            return render(request,'create_event.djhtml',
                       {'form':event_form,
                        'errors':event_form.errors})
    event_form = CreateEventForm()
    return render(request,'create_event.djhtml',
                       {'form':event_form})
コード例 #2
0
ファイル: views.py プロジェクト: bxm156/ServicePad
def admin(request,event_id):
    event = get_object_or_404(Event,pk=event_id)
    
    #Get ServiceEnrollments that have not yet been approved
    """
   SELECT `service_serviceenrollment`.`id`, `service_serviceenrollment`.`event_id`, `auth_user`.`first_name`,
   `auth_user`.`first_name`, `auth_user`.`last_name`, `service_serviceenrollment`.`user_id`,
   `service_serviceenrollment`.`team_id`, `team_team`.`name`, `service_serviceenrollment`.`start`,
   `service_serviceenrollment`.`end` FROM `service_serviceenrollment`
   INNER JOIN `auth_user` ON (`service_serviceenrollment`.`user_id` = `auth_user`.`id`)
   LEFT OUTER JOIN `team_team` ON (`service_serviceenrollment`.`team_id` = `team_team`.`id`)
   WHERE (`service_serviceenrollment`.`start` > 2012-12-10 05:33:15  AND `service_serviceenrollment`.`event_id` = 1  
   AND `service_serviceenrollment`.`approved` = 0 )
    """
    pending_approval = ServiceEnrollment.objects.filter(event=event,start__gt=datetime.now(),approved=0).values('id','event_id','user__first_name',
                    'user__first_name','user__last_name','user_id','team_id','team__name','start','end')
    print pending_approval.query.__str__()
    
    #Get approved ServiceEnrollments that are not in the past
    """
    SELECT `events_event`.`owner_id`, T4.`first_name`, T4.`last_name`, `service_serviceenrollment`.`team_id`,
    `team_team`.`name`, `service_serviceenrollment`.`start`, `service_serviceenrollment`.`end`
    FROM `service_serviceenrollment` INNER JOIN `events_event` ON (`service_serviceenrollment`.`event_id` = `events_event`.`id`)
    INNER JOIN `auth_user` T4 ON (`service_serviceenrollment`.`user_id` = T4.`id`)
    LEFT OUTER JOIN `team_team` ON (`service_serviceenrollment`.`team_id` = `team_team`.`id`)
    WHERE (`service_serviceenrollment`.`end` > 2012-12-10 05:33:15  AND `service_serviceenrollment`.`event_id` = 1 
    AND `service_serviceenrollment`.`approved` = 1 )
    """
    approved = ServiceEnrollment.objects.filter(event=event,end__gt=datetime.now(),approved=1).values('event__owner_id','user__first_name','user__last_name','team_id','team__name','start','end')
    print approved.query.__str__()
    
    #Get a list of past enrollments to review
    """
    SELECT `service_serviceenrollment`.`id`, `auth_user`.`first_name`, `auth_user`.`last_name`, 
    `service_serviceenrollment`.`team_id`, `team_team`.`name`, `service_serviceenrollment`.`start`, 
    `service_serviceenrollment`.`end` FROM `service_serviceenrollment` 
    INNER JOIN `auth_user` ON (`service_serviceenrollment`.`user_id` = `auth_user`.`id`) 
    LEFT OUTER JOIN `team_team` ON (`service_serviceenrollment`.`team_id` = `team_team`.`id`) 
    WHERE (`service_serviceenrollment`.`event_id` = 1  AND `service_serviceenrollment`.`end` < 2012-12-10 05:33:15  
    AND `service_serviceenrollment`.`approved` = 1 )
    """
    to_review = ServiceEnrollment.objects.filter(event=event,end__lt=datetime.now(),approved=1).values('id','user__first_name','user__last_name','team_id','team__name','start','end')
    print to_review.query.__str__()
    
    context = {'pending_approval':pending_approval,
               'approved':approved,
               'to_review':to_review,
    }
    if request.method == "POST":
        if "edit_event" in request.POST:
            edit_event_form = CreateEventForm(request.POST.copy(),instance=event,prefix='event')
            if edit_event_form.is_valid():
                edit_event_form.save()
                context.update({'event_update_success':True})
        else:
            edit_event_form = CreateEventForm(instance=event,prefix='event')
        if "add_skill" in request.POST:
            needs_skill_form = NeedsSkillForm(request.POST.copy(),instance=NeedsSkill(event=event),prefix='skill')
            if needs_skill_form.is_valid():
                needs_skill_form.save()
        needs_skill_form = NeedsSkillForm(prefix='skill')
    else:
        edit_event_form = CreateEventForm(instance=event,prefix='event')
        needs_skill_form = NeedsSkillForm(prefix='skill')
    #Gets the skills need by the event
    """
    SELECT `events_needsskill`.`id`, `events_needsskill`.`event_id`, `events_needsskill`.`skill_id`,
    `events_needsskill`.`min_proficiency_level` FROM `events_needsskill` WHERE `events_needsskill`.`event_id` = 1 
    """
    needed_skills = NeedsSkill.objects.filter(event=event)
    print needed_skills.query.__str__()

    context.update({'event':event,'edit_event_form':edit_event_form,
                    'needs_skill_form':needs_skill_form,
                    'needed_skills':needed_skills,
                    'proficiency':PROFICIENCY})
    return render(request,'admin_event.djhtml',context)