Exemplo n.º 1
0
    def post_create(self):

        dict = self.request.POST
        dict['created_by'] = self.request.session.user._get_id()
        dict['house_id'] = self.request.session.user.house_id

        if self.request.route.name == 'tasks':

            rt = RepeatedTask.create(dict)

            hse = house.House.get_by_id(self.request.session.user.house_id)
            hse.add_house_event(user_id = self.request.session.user._get_id(),
                            desc = 'created a task named {0}'.format(dict['name']),
                            points = 0,
                            reference=rt.key)

            return self.json_response(json.dumps({'success':'Task created','redirect':'/tasks'}))
        elif self.request.route.name == 'standing':
            st = StandingTask()
            dict = shg_utils.encapsulate_dict(self.request.POST,StandingTask)
            st.populate(**dict)
            st.put()

            self.request.session.user.house.add_house_event(
            user_id=self.request.session.user._get_id(),
            desc="created standing task '"+ st.name + "'",
            points=0,
            reference=None)



            return self.json_response(json.dumps({'success':'Task created','redirect':'/standing'}))
Exemplo n.º 2
0
    def list(self):
        if self.request.session.user is None:
            return self.generic_error(title='Not logged in',message='Please login to access that page')
        house_id = self.request.session.user.house_id
        if not house_id:
            return self.generic_error(title='Registration not complete',message='You must complete your Sharehouse setup prior to continuing...')

        if self.request.route.name == 'tasks':
            task_objects = RepeatedTask.query().filter(RepeatedTask.house_id == house_id,RepeatedTask.disabled==False).fetch()

            lik=[]
            liks =[]
            hses=[]
            cmpls=[]

            for t in task_objects:
                lik.append(request_last_instance_key(t))
                liks.append(request_last_instance_keys(t))
                hses.append(request_hse(t))

            for (t,li,lis) in zip(task_objects,lik,liks):
                t._last_instance_key = li.get_result()
                t._instance_keys = lis.get_result()

            for t in task_objects:
                cmpls.append(request_completions(t))

            for (t,c,h) in zip(task_objects,cmpls,hses):
                t._house = h.get_result()
                t._task_completions = {t._last_instance_key:c.get_result()}

            tasks = []

            for t in task_objects:
                hc = t.housemates_completed()
                tc = 0
                if t.shared_task:
                    if t.shared_all_reqd:
                        tc = len(t.house.users)
                    else:
                        tc = t.shared_number
                else:
                    tc=1

                task = {'user_has_completed':t.is_task_complete(user_id=self.request.session.user._get_id()),
                        'current_due_dt':t.current_due_dt(),
                        'id':t.key.id(),
                        'points':t.points,
                        'name':t.name,
                        'is_completable':t.is_completable(),
                        'been_completed':t.is_task_complete(),
                        'describe_repeat':t.describe_repeat(),
                        'shared_task':t.shared_task,
                        'shared_desc':t.shared_desc,
                        'doesnt_expire':t.doesnt_expire,
                        'no_reminder':t.no_reminder,
                        'reminders':t.reminders,
                        'desc':t.desc,
                        'completions':len(hc),
                        'total_completions': tc
                        }
                hc = t.housemates_completed()

                if task['is_completable'] is False:
                    task['human_cf'] = t.human_relative_time(t.completable_from())
                if task['doesnt_expire'] is True:
                    task['human_neu'] = t.human_relative_time(t.next_expiry_utc())
                else:
                    task['human_ndu'] = t.human_relative_time(t.next_due_utc())

                task['human_nru'] = t.human_relative_time(t.next_reminder_utc())

                task['human_cdd'] = t.human_date(task['current_due_dt'])

                tasks.append(task)

            if tasks:
                tasks = sorted(tasks,key=lambda k:k['current_due_dt'] if k['current_due_dt'] != None else pytz.UTC.localize(datetime(2100,1,1)) )

            return self.render_template('tasks.html',{'tasks':tasks})
        elif self.request.route.name =='standing':

            tasks = StandingTask.query().filter(StandingTask.house_id == house_id,StandingTask.disabled==False).fetch()

            return self.render_template('standing_tasks.html',{'tasks':tasks})