コード例 #1
0
ファイル: views.py プロジェクト: yfjelley/publish
def add_reminder(request, objectid):
    user = auth.get_user(request)
    try:
        u_r = UserReminder.objects.get(user=user, bid=objectid)
        return HttpResponse(u'已存在')
    except ObjectDoesNotExist:
        u_r = UserReminder(user=user, bid=objectid, reminder=1, value=1, status=1)
        u_r.save()
        return HttpResponse(u'已添加')
コード例 #2
0
def add_reminder(request, objectid):
    user = auth.get_user(request)
    try:
        u_r = UserReminder.objects.get(user=user, bid=objectid)
        return HttpResponse(u'已存在')
    except ObjectDoesNotExist:
        u_r = UserReminder(user=user, bid=objectid, reminder=1, value=1, status=1)
        u_r.save()
        return HttpResponse(u'已添加')
コード例 #3
0
ファイル: views.py プロジェクト: yfjelley/publish
def do_reminder(request):
    user = auth.get_user(request)
    days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 31]
    if request.method == 'POST':
        b_id = request.POST.get('bid', None)
        method = request.POST.get('method', None)
        rtype = request.POST.get('type', None)
        if method == 'add':
            try:
                u_r = UserReminder.objects.get(user=user, bid_id=int(b_id), reminder_id=int(rtype))
                return HttpResponse(u'已存在')
            except ObjectDoesNotExist:
                if rtype == u'1' or rtype == u'2' or rtype == u'3':
                    value = 1
                else:
                    value = 0
                u_r = UserReminder(user=user, bid_id=int(b_id), reminder_id=int(rtype), value=value, status=1)
                u_r.save()
                return HttpResponse(u'已添加')
        elif method == 'active':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id)).update(status=1)
                return HttpResponse(u'提醒已打开')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'inactive':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id)).update(status=0)
                return HttpResponse(u'提醒已关闭')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'del':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id))
                u_r.delete()
                return HttpResponse(u'已删除')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'change':
            a = request.POST.getlist('params[]')
            r_u = ReminderUnit.objects.all().order_by('id')
            i = 0
            for r in r_u:
                try:
                    u_r = UserReminder.objects.get(user=user, bid_id=int(b_id), reminder_id=r.id)
                except ObjectDoesNotExist:
                    u_r = UserReminder(user=user, bid_id=int(b_id), reminder_id=r.id)
                if int(a[i]) == 0:
                    u_r.value = 0
                    u_r.status = 1
                else:
                    u_r.value = a[i]
                    u_r.status = 1
                if int(a[i]) != u_r.value:
                    u_r.is_reminded = 0
                u_r.save()
                i += 1
            return HttpResponse(u'修改已保存')
    else:
        reminders = UserReminder.objects.filter(user=user)
        flag = 2
        aa = []
        bb = {}
        if len(reminders) > 0:
            t = reminders[0].bid_id
            for a in reminders:
                if a.bid_id == t:
                    bid = Bid.objects.filter(id=a.bid_id)
                    if not bid.exists():
                        bid = BidHis.objects.filter(id=a.bid_id)

                    if a.reminder_id == 1:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'a': a.value}
                    elif a.reminder_id == 2:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'b': a.value}
                    elif a.reminder_id == 3:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'c': a.value}
                    elif a.reminder_id == 4:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'd': a.value}
                    elif a.reminder_id == 5:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'e': a.value}
                    bb.update(ttt)
                    t = a.bid_id
                else:
                    aa.append(bb)
                    bb = {}
                    bid = Bid.objects.filter(id=a.bid_id)
                    if not bid.exists():
                        bid = BidHis.objects.filter(id=a.bid_id)
                    if a.reminder_id == 1:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'a': a.value}
                    elif a.reminder_id == 2:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'b': a.value}
                    elif a.reminder_id == 3:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'c': a.value}
                    elif a.reminder_id == 4:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'd': a.value}
                    elif a.reminder_id == 5:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'e': a.value}
                    bb.update(ttt)
                    t = a.bid_id
            aa.append(bb)
        return render_to_response("user_reminder.html", {'reminders': aa, 'flag': flag, 'days': days},
                                  context_instance=RequestContext(request))
コード例 #4
0
def do_reminder(request):
    user = auth.get_user(request)
    days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
            30, 31]
    if request.method == 'POST':
        b_id = request.POST.get('bid', None)
        method = request.POST.get('method', None)
        rtype = request.POST.get('type', None)
        if method == 'add':
            try:
                u_r = UserReminder.objects.get(user=user, bid_id=int(b_id), reminder_id=int(rtype))
                return HttpResponse(u'已存在')
            except ObjectDoesNotExist:
                if rtype == u'1' or rtype == u'2' or rtype == u'3':
                    value = 1
                else:
                    value = 0
                u_r = UserReminder(user=user, bid_id=int(b_id), reminder_id=int(rtype), value=value, status=1)
                u_r.save()
                return HttpResponse(u'已添加')
        elif method == 'active':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id)).update(status=1)
                return HttpResponse(u'提醒已打开')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'inactive':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id)).update(status=0)
                return HttpResponse(u'提醒已关闭')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'del':
            try:
                u_r = UserReminder.objects.filter(user=user, bid_id=int(b_id))
                u_r.delete()
                return HttpResponse(u'已删除')
            except ObjectDoesNotExist:
                return HttpResponse(u'不存在')
        elif method == 'change':
            a = request.POST.getlist('params[]')
            r_u = ReminderUnit.objects.all().order_by('id')
            i = 0
            for r in r_u:
                try:
                    u_r = UserReminder.objects.get(user=user, bid_id=int(b_id), reminder_id=r.id)
                except ObjectDoesNotExist:
                    u_r = UserReminder(user=user, bid_id=int(b_id), reminder_id=r.id)
                if int(a[i]) == 0:
                    u_r.value = 0
                    u_r.status = 1
                else:
                    u_r.value = a[i]
                    u_r.status = 1
                if int(a[i]) != u_r.value:
                    u_r.is_reminded = 0
                u_r.save()
                i += 1
            return HttpResponse(u'修改已保存')
    else:
        reminders = UserReminder.objects.filter(user=user)
        flag = 2
        aa = []
        bb = {}
        if len(reminders) > 0:
            t = reminders[0].bid_id
            for a in reminders:
                if a.bid_id == t:
                    bid = Bid.objects.filter(id=a.bid_id)
                    if not bid.exists():
                        bid = BidHis.objects.filter(id=a.bid_id)

                    if a.reminder_id == 1:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'a': a.value}
                    elif a.reminder_id == 2:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'b': a.value}
                    elif a.reminder_id == 3:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'c': a.value}
                    elif a.reminder_id == 4:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'd': a.value}
                    elif a.reminder_id == 5:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'e': a.value}
                    bb.update(ttt)
                    t = a.bid_id
                else:
                    aa.append(bb)
                    bb = {}
                    bid = Bid.objects.filter(id=a.bid_id)
                    if not bid.exists():
                        bid = BidHis.objects.filter(id=a.bid_id)
                    if a.reminder_id == 1:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'a': a.value}
                    elif a.reminder_id == 2:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'b': a.value}
                    elif a.reminder_id == 3:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'c': a.value}
                    elif a.reminder_id == 4:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'd': a.value}
                    elif a.reminder_id == 5:
                        ttt = {'bid_id': a.bid_id, 'bid_name': bid[0].name, 'status': a.status, 'e': a.value}
                    bb.update(ttt)
                    t = a.bid_id
            aa.append(bb)
        return render_to_response("user_reminder.html", {'reminders': aa, 'flag': flag, 'days': days},
                                  context_instance=RequestContext(request))