Esempio n. 1
0
    def get(self):
        t1 = time.time()
        v = TemplateValues()
        v.pageinfo = TemplateValues()
        v.pageinfo.html = "assignments.html"  # views.assignments
        logging.info(v.pageinfo.html)
        v.pageinfo.title = "Calendar"
        v.params = TemplateValues()
        calendar = Calendar.get_by_key_name("main")
        v.calendar = sorted(pickle.loads(calendar.data))
        v.caption = "Calendar was generated {} at {}.".format({
            True:
            "manually",
            False:
            "automatically"
        }[calendar.manual], calendar.timestamp)
        logging.info(v.caption)
        new_assignments = dbmodels.NewAssignment.all()
        for i, week in enumerate(v.calendar):
            for assignment in new_assignments:
                if assignment.assignment.start_date.date(
                ) <= week[0] <= assignment.assignment.end_date.date(
                ) - datetime.timedelta(days=7):
                    v.calendar[i][1].append(assignment.assignment)
            v.calendar[i][1].sort(
                key=lambda a: (a.project_name, a.start_date, a.end_date))

        path = os.path.join(os.path.dirname(__file__), views.main)
        self.response.headers.add_header("Expires", expdate())
        self.response.out.write(template.render(path, {"v": v}))
Esempio n. 2
0
    def get(self):
        manual = self.request.get("manual") == "1"
        num_months = 6

        now = datetime.datetime.now().date()
        this_week = now - datetime.timedelta(days=now.weekday())
        dmonth = this_week.month + num_months
        if dmonth > 11:
            dyear = this_week.year + 1
            dmonth = dmonth - 11
        else:
            dyear = this_week.year
        logging.info("{} {}".format(dyear,dmonth))
        end_date = datetime.date(year=dyear, month=dmonth, day=1)
        logging.info(end_date)
        assignments = Assignment.gql("WHERE end_date > :1 ORDER BY end_date", now )
        assignments = [ a for a in assignments if a.start_date.date() < end_date ]
        assignments = sorted(assignments, key=lambda a: a.project_name)
        one_week = datetime.timedelta(days=7)
        weeks = []
        while this_week < end_date:
            this_weeks_assignments = [] 
            for a in assignments:
                
                if a.start_date.date() <= this_week <= a.end_date.date() - datetime.timedelta(days=6):
#                    a.weeks_remaining = ((a.end_date.date() - this_week).days + 1)/7
#                    logging.info(a.weeks_remaining)
                    this_weeks_assignments.append(a)

            weeks.append((this_week, this_weeks_assignments))
            this_week += one_week
        logging.info(weeks)
        calendar = Calendar.get_or_insert("main", title="Main Calendar Data")
        calendar.data = pickle.dumps(weeks)
        calendar.timestamp = datetime.datetime.now()
        calendar.manual = manual
        calendar.put()

        #delete all the NewAssignments that are now in the calendar

        db.delete(NewAssignment.all(keys_only=True))
        if manual:
            self.redirect("/settings?status=calgen")
Esempio n. 3
0
    def get(self):
        t1 = time.time()        
        v = TemplateValues()
        v.pageinfo = TemplateValues()
        v.pageinfo.html = "assignments.html"# views.assignments
        logging.info(v.pageinfo.html)
        v.pageinfo.title = "Calendar"
        v.params = TemplateValues()
        calendar = Calendar.get_by_key_name("main")
        v.calendar = sorted(pickle.loads(calendar.data))
        v.caption = "Calendar was generated {} at {}.".format({True: "manually", False: "automatically"}[calendar.manual], calendar.timestamp)
        logging.info(v.caption)
        new_assignments = dbmodels.NewAssignment.all()
        for i, week in enumerate(v.calendar):
            for assignment in new_assignments:
                if assignment.assignment.start_date.date() <= week[0] <=  assignment.assignment.end_date.date() - datetime.timedelta(days=7):
                    v.calendar[i][1].append(assignment.assignment)
            v.calendar[i][1].sort(key=lambda a: (a.project_name, a.start_date,a.end_date))
            

        path = os.path.join(os.path.dirname(__file__), views.main)
        self.response.headers.add_header("Expires", expdate())
        self.response.out.write(template.render(path, { "v" : v }))