示例#1
0
def KalendarCreate(first_day_class, days_in_cycle):
    Kalendar.objects.all().delete()
    day=date(first_day_class.year, 8, 1)
    last_day=date(first_day_class.year+1, 6, 30)
    
    while day < first_day_class:
        holiday=Day_No.objects.get(day_name='H')
        if day.weekday() < 5:
            k=Kalendar(date=day, day_no=holiday)
            k.save()
        day=day + timedelta(days=1)

    i=1
    while day <= last_day:
        if day.weekday()<5:
            k=Kalendar(date=day, day_no=Day_No.objects.get(day_name=str(i)))
            k.save()
            if i==days_in_cycle:
                i=1
            else:
                i=i+1
        day=day + timedelta(days=1)
    
    while day <= date(first_day_class.year+1, 7, 31):
        if day.weekday() < 5:
            k=Kalendar(date=day, day_no=Day_No.objects.get(day_name='H'))
            k.save()
        day=day + timedelta(days=1)
示例#2
0
 	def form_valid(self, form, **kwargs):
		
		last_day=date(int(self.request.POST['last_day_year']),int(self.request.POST['last_day_month']),int(self.request.POST['last_day_day']))
		first_day_school=date(int(self.request.POST['first_day_school_year']),int(self.request.POST['first_day_school_month']),int(self.request.POST['first_day_school_day']))
		first_day=date(int(self.request.POST['first_day_year']),int(self.request.POST['first_day_month']),int(self.request.POST['first_day_day']))
		
		Kalendar.objects.all().delete()

		change_day=first_day
		
		while change_day < first_day_school:
			if change_day.weekday() < 5:
				k=Kalendar(date=change_day,day_no='H')
				k.save()
			change_day=change_day + timedelta(days=1)
		
		i=1
		while change_day <= last_day:
			if change_day.weekday() < 5:
				k=Kalendar(date=change_day,day_no=str(i))
				k.save()
				if i==5:
					i=1
				else:
					i=i+1
					
			change_day=change_day + timedelta(days=1)
 		
 		return HttpResponseRedirect('/initialize')
示例#3
0
 	def form_valid(self, form, **kwargs):
		
		class_url=self.kwargs['class_url']
		class_db=Classes.objects.get(classes=class_url)
		
		first_day=date(int(self.request.POST['first_day_year']),int(self.request.POST['first_day_month']),int(self.request.POST['first_day_day']))
		last_day=date(int(self.request.POST['last_day_year']),int(self.request.POST['last_day_month']),int(self.request.POST['last_day_day']))
		first_day_school=date(int(self.request.POST['first_day_school_year']),int(self.request.POST['first_day_school_month']),int(self.request.POST['first_day_school_day']))
		
		
		Kalendar.objects.all().delete()

		change_day=first_day
		
		while change_day < first_day_school:
			if change_day.weekday() < 5:
				k=Kalendar(date=change_day,day_no='H')
				k.save()
			change_day=change_day + timedelta(days=1)
		
		i=1
		while change_day <= last_day:
			if change_day.weekday() < 5:
				k=Kalendar(date=change_day,day_no=str(i))
				k.save()
				if i==5:
					i=1
				else:
					i=i+1
					
			change_day=change_day + timedelta(days=1)
 		
 		return HttpResponseRedirect(reverse_lazy('kal-list-view', args=(self.kwargs['class_url'], first_day.year,first_day.month,)))
示例#4
0
    def form_valid(self, form):
    
	    klass=self.kwargs['class_url']
	    kal_type=self.kwargs['kal_type']
	    
	    new_kalendar_object=form.save(commit=False)
	    new_day_no=new_kalendar_object.day_no
	    date_to_change=new_kalendar_object.date
	    kal_to_change=Kalendar.objects.get(date=date_to_change)
	    id_to_change=kal_to_change.id
	    
	    ##make first change to kalendar
	    
	    ##change from # to H
	    if (kal_to_change.day_no != 'H') and (new_day_no == 'H'):
	        pre_day_no=kal_to_change.day_no
	        changed_day=Kalendar(id=id_to_change, date=kal_to_change.date, day_no=new_day_no)
	        changed_day.save()
	        new_day_no=pre_day_no
	    
	    ##change from # to #
	    elif (kal_to_change.day_no != 'H') and (new_day_no != 'H'):
	        changed_day=Kalendar(id=id_to_change, date=kal_to_change.date, day_no=new_day_no)
	        changed_day.save()
	        
	        if new_day_no == '5':
	            new_day_no = '1'
	        else:
	            new_day_no = str(int(new_day_no)+1)
	        
	    ##change from H to #
	    elif (kal_to_change.day_no == 'H') and (new_day_no != 'H'):
	        changed_day=Kalendar(id=id_to_change, date=kal_to_change.date, day_no=new_day_no)
	        changed_day.save()
	        if new_day_no == '5':
	            new_day_no = '1'
	        else:
	            new_day_no = str(int(new_day_no)+1)
	            
	    ##change from H to H
	    elif (kal_to_change.day_no == 'H') and (new_day_no == 'H'):
	        changed_day=Kalendar(id=id_to_change, date=kal_to_change.date, day_no=new_day_no)
	        changed_day.save()
	        new_day_no=False
	        
	    ##rest of kalendar
	    if new_day_no:
	        for	k in Kalendar.objects.filter(date__gt=date_to_change).iterator():
	            ##check if day being changed is H
	            if k.day_no == 'H':
	                ##makes no changes
	                pass
	            
	            ##if a day 1 to 5 changes the day number and then updates new day to the next day number
	            elif k.day_no != 'H':
	                changed_day=Kalendar(id=k.id, date=k.date, day_no=new_day_no)
	                changed_day.save()
	                
	                if new_day_no == '5':
	                    new_day_no = '1'
	                else:
	                    new_day_no = str(int(new_day_no)+1)
	    return HttpResponseRedirect(reverse('kalendar_view', args=(klass, kal_type, new_kalendar_object.date.year,new_kalendar_object.date.month)))