示例#1
0
文件: views.py 项目: clvrobj/ninemit
def get_timelists(request):
    """
    output all timelist belong to user
    """
    if request.is_ajax():
        try:
            uinfo = get_user_info(request)
            from timelist import get_timelists_by_user
            tls = get_timelists_by_user(uinfo)
            ret = []
            if request.user.is_authenticated():
                for tl in tls:
                    data = {'id':tl.id, 'name':tl.name, 'desc':tl.desc, 'color_id':tl.color_id, 'is_public':tl.is_public}
                    if tl.owner != request.user:
                        data['is_on'] = True
                        data['is_editable'] = False
                        is_home = uinfo.get('is_home')
                        if is_home:
                            data['owner'] = [tl.owner.id, tl.owner.name]
                        is_subscribed = False
                        if request.user.tlistsubscribe_set.filter(timelist=tl):
                            is_subscribed = True
                        data['is_subscribed'] = is_subscribed
                    else:
                        data['is_on'] = tl.is_on
                        data['is_editable'] = True
                    ret.append(data)
            else:
                for tl in tls:
                    # all timelist is on for anyone
                    data = {'id':tl.id, 'name':tl.name, 'desc':tl.desc, 'is_on':True, 'color_id':tl.color_id, 'is_editable': False}
                    ret.append(data)
            return JsonResponse({'timelists': ret})
        except PermissionDenied:
            return JsonResponse({'ret':'Permission Denied'})
示例#2
0
文件: views.py 项目: clvrobj/ninemit
def get_tlistpanel_open(request):
    if request.is_ajax():
        try:
            uinfo = get_user_info(request)
            profile = uinfo['user'].get_profile()
            return JsonResponse({'is_open': profile.is_tlistpanel_open})
        except PermissionDenied:
            return JsonResponse({'ret':'Permission Denied'})
示例#3
0
文件: views.py 项目: clvrobj/ninemit
def get_timer_detail(request, timer_id):
    if request.is_ajax():
        try:
            user_id = get_user_info(request).get('user').id
            t = timer.get_timer(user_id, int(timer_id))
            ret = format_timer_str(t)
            return JsonResponse({'valid':True, 'data':ret})
        except Timer.DoesNotExist, ValueError:
            return JsonResponse({'ret':'index is wrong', 'valid':False})
示例#4
0
文件: views.py 项目: clvrobj/ninemit
def set_order(request):
    if request.is_ajax():
        try:
            id = request.POST.get('id')
            prior_id = request.POST.get('prior_id')
            uinfo = get_user_info(request)
            from timelist import set_order
            set_order(uinfo['user'], id, prior_id)
            return JsonResponse({'valid': True, 'ret':'OK'})
        except PermissionDenied:
            return JsonResponse({'valid': False,'ret':'Permission Denied'})
示例#5
0
文件: views.py 项目: clvrobj/ninemit
def get_cur(request):
    """
    Get current timer
    """
    if request.is_ajax():
        try:
            uinfo = get_user_info(request)
            tl_id = request.GET.get('tl_id')
            if tl_id:
                t = timer.get_timelist_current_timer(request.user, int(tl_id))
            else:
                t = timer.get_current_timer(uinfo)
            if not t:
                return JsonResponse({'ret':'no cur timer'});
            return JsonResponse({'ret':'ok', 'valid':True,
                                 'data':format_timer_str(t)})
        except PermissionDenied:
            return JsonResponse({'ret':'Permission Denied'})
示例#6
0
文件: views.py 项目: clvrobj/ninemit
def load_timers(request):
    """get bundle of timers from ajax request"""
    if request.is_ajax():
        try:
            reqdata = request.GET
            start = reqdata.get('start')
            end = reqdata.get('end')
            tz = reqdata.get('tz')
            tl_id = reqdata.get('tl_id')
            start = parseStr2utc(start, tz)
            end = parseStr2utc(end, tz)
            if tl_id:
                ts = timer.get_timelist_timers(request.user, int(tl_id), start, end)
            else:
                uinfo = get_user_info(request)
                ts = timer.get_timers(uinfo, start, end)
            # first is the time range info
            retts = [[start.strftime(timer.TIME_FORMAT),
                      end.strftime(timer.TIME_FORMAT)]]
            for t in ts:
                retts.append(format_timer_str(t))
            return JsonResponse(retts)
        except PermissionDenied:
            return JsonResponse({'ret':'Permission Denied'})