Example #1
0
def number_increase(request, auth):
    if request.method == 'POST':

        received_data = request.body
        received_dict = ast.literal_eval(received_data)
        received_auth = int(received_dict['auth'])

        if (0<=received_auth<12 or received_auth==100):
            try:

                temp_Notice = Notice.objects.all()
                # print(temp_Notice)

                num = temp_Notice[len(temp_Notice)-1]
                max_num = int(num.number)
                # print(type(max_num))
                sending_num = max_num+1
                # print(sending_num)
                new_info = Notice(number=sending_num)
                # print(new_info)
                new_info.save()

                return HttpResponse(json.dumps({'response':'success',
                                                'increased':sending_num}))
            except Exception as e:
                print(str(e))
                return HttpResponse(json.dumps({'response':'fail'}))

        else:
            print('author is not approved')
            return HttpResponse('Approval denied')
    else:
        return HttpResponse({'request is not in POST form'})
 def create_notice(self):
     notice = Notice(
         recipient=self.user1,
         sender=self.user1,
         message='test message for notice',
         notice_type = NoticeType.objects.latest('pk'),
         on_site=True)
     notice.save()
     return notice
Example #3
0
    def test_push(self):
        target = "dddd"
        content = "gggg"

        notice = Notice.push(self.user, self.notice_type, target, content)
        notice1 = Notice.push(self.user, self.notice_type, target, content)
        self.assertEqual(notice, notice1)

        notice.delete()
Example #4
0
 def test_push(self):
     target = "dddd"
     content = "gggg"
     
     notice = Notice.push(self.user, self.notice_type, target, content)
     notice1 = Notice.push(self.user, self.notice_type, target, content)
     self.assertEqual(notice, notice1)
     
     notice.delete()
Example #5
0
    def test_send_to_email(self):
        target = "dddd"
        content = "gggg"
        self.notice_type.flags = 3
        self.notice_type.save()
        notice = Notice.push(self.user, self.notice_type, target, content)

        Notice.send_to_email(self.user)

        new_notice = Notice.objects.get(id=notice.id)
        self.assertEqual(new_notice.sent_device, 2)

        self.notice_type.flags = 1
        self.notice_type.save()
        notice.delete()
Example #6
0
 def test_send_to_email(self):
     target = "dddd"
     content = "gggg"
     self.notice_type.flags = 3
     self.notice_type.save()
     notice = Notice.push(self.user, self.notice_type, target, content)
     
     Notice.send_to_email(self.user)
     
     new_notice = Notice.objects.get(id=notice.id)
     self.assertEqual(new_notice.sent_device, 2)
     
     self.notice_type.flags = 1
     self.notice_type.save()
     notice.delete()
Example #7
0
 def test_home(self):
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com",
                          content=u"ggg")
     url = reverse("notification.views.home")
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     notice.delete()
Example #8
0
 def test_update_notice(self):
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11",
                          content=u"ggg", reminder_value=1)
     views.update_notice(notice)
     result = notice.reminder_value
     self.assertEqual(result, 2, "update_notice_above run fail")
     notice.delete()
Example #9
0
    def test_unread(self):
        notice = Notice.push(self.user, self.notice_type,
                             "http://www.baidu.com", "ffgg")
        notices = Notice.objects.unread(self.user, NoticeSetting.DEVICE_WEB)
        self.assertEqual(len(notices), 1)

        notice.delete()
Example #10
0
 def test_initialize_notice(self):
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11",
                          content=u"ggg")
     views.initialize_notice(notice)
     result = int(time.mktime(notice.last_reminder_time.timetuple()))
     except_result = int(time.mktime(datetime.datetime.now().timetuple()))
     self.assertEqual(result, except_result, "initialize_notice run fail")
     notice.delete()
Example #11
0
 def test_update_notice_below(self):
     """test update_notice_above, normal operation, the reminder_value is below 365, noting unusual
     """
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="11",
                          content=u"ggg", reminder_value=1)
     views.update_notice(notice)
     result = notice.reminder_value
     self.assertEqual(result, 2, "update_notice_below run fail")
     notice.delete()
Example #12
0
 def test_get_reminder_flag(self):   
     """test get_reminder_flag, normal operation, the last_reminder_time is not None, noting unusual
     """
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com",
                          content=u"ggg", last_reminder_time=datetime.datetime.now())
     result = views.get_reminder_flag(notice, 3600*24)
     except_result = 1
     self.assertEqual(result, except_result, "get_reminder_flag run fail")
     notice.delete()
Example #13
0
 def test_unread_and_unsend_with_sent(self):
     notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg", sent_device=2)
     notices = Notice.objects.unread_and_unsend(self.user, NoticeSetting.DEVICE_WEB)
     self.assertEqual(len(notices), 1)
     
     notices = Notice.objects.unread_and_unsend(self.user, NoticeSetting.DEVICE_EMAIL)
     self.assertEqual(len(notices), 0)
     
     notice.delete()
def unseen_notices_count(request):
    """
    return the count of unseen notices for current user
    """
    if request.user.is_authenticated():
        qs = Notice.unseen_count_for(request.user)
        return {'unseen_notices_count': qs}
    else:
        return {}
def unseen_notices(request):
    """
    return a list of unseen notices for current user
    """
    if request.user.is_authenticated():
        qs = Notice.notices_for(request.user, unseen=True)
        return {'unseen_notices': qs}
    else:
        return {}
Example #16
0
 def test_get_reasons(self):
     notices = []
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="9",
                          content=u"ggg",add_datetime='2013-10-28 15:48:18')
     notices.append(notice)
     init_reasons = []
     result = views.get_reasons(init_reasons,  notices)
     except_result = [u"<span class='text-muted'>2013-10-28 15:48:18</span> <a href='/notification/go/9/' target='_blank'>ggg</a>"]
     self.assertEqual(result, except_result,"get_reasons run fail")
     notice.delete()
Example #17
0
    def test_go(self):
        notice = Notice.push(user=self.user,
                             notice_type=self.notice_type,
                             target="http://www.baidu.com",
                             content=u"ggg")
        url = reverse("notification.views.go", args=[notice.id])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 302)

        notice.delete()
Example #18
0
 def test_clear(self):
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com",
                          content=u"ggg")
     url = reverse("notification.views.clear")
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     notices = Notice.objects.unread_of_email(self.user)
     self.assertEqual(len(notices), 0)
     
     notice.delete()
Example #19
0
 def test_my(self):
     notice = Notice.push(user=self.user, notice_type=self.notice_type, target="http://www.baidu.com",
                          content=u"ggg")
     url = reverse("notification.views.my")
     resp = self.client.get(url)
     self.assertEqual(resp.status_code, 200)
     
     result = simplejson.loads(resp.content)
     self.assertTrue(result["is_ok"])
     
     notice.delete()
Example #20
0
    def test_clear(self):
        notice = Notice.push(user=self.user,
                             notice_type=self.notice_type,
                             target="http://www.baidu.com",
                             content=u"ggg")
        url = reverse("notification.views.clear")
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)

        notices = Notice.objects.unread_of_email(self.user)
        self.assertEqual(len(notices), 0)

        notice.delete()
Example #21
0
    def test_my(self):
        notice = Notice.push(user=self.user,
                             notice_type=self.notice_type,
                             target="http://www.baidu.com",
                             content=u"ggg")
        url = reverse("notification.views.my")
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)

        result = simplejson.loads(resp.content)
        self.assertTrue(result["is_ok"])

        notice.delete()
Example #22
0
    def test_unread_and_unsend_with_sent(self):
        notice = Notice.push(self.user,
                             self.notice_type,
                             "http://www.baidu.com",
                             "ffgg",
                             sent_device=2)
        notices = Notice.objects.unread_and_unsend(self.user,
                                                   NoticeSetting.DEVICE_WEB)
        self.assertEqual(len(notices), 1)

        notices = Notice.objects.unread_and_unsend(self.user,
                                                   NoticeSetting.DEVICE_EMAIL)
        self.assertEqual(len(notices), 0)

        notice.delete()
Example #23
0
def message_created(sender, instance, created, **kwargs):
    '''Notify the recipient that a new private message has been received.'''
    if created:
        target = reverse('ppmsg.views.view_detail', args=(instance.sender.username,))
        notice_type = NoticeType.create(label="private message", display=u"新私信", description=u"新私信")
        Notice.push(user=instance.recipient, notice_type=notice_type, target=target, content=instance.sender.username + u"给您发来新的私信")
Example #24
0
    def test_notice_is_could_send(self):
        notice = Notice.push(self.user, self.notice_type,
                             "http://www.baidu.com", "ffgg")
        self.assertTrue(notice.is_could_send(NoticeSetting.DEVICE_WEB))

        notice.delete()
Example #25
0
 def test_unread_with_read(self):
     notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg", is_read=True)
     notices = Notice.objects.unread(self.user, NoticeSetting.DEVICE_WEB)
     self.assertEqual(len(notices), 0)
     
     notice.delete()
Example #26
0
 def test_notice_is_could_send(self):
     notice = Notice.push(self.user, self.notice_type, "http://www.baidu.com", "ffgg")
     self.assertTrue(notice.is_could_send(NoticeSetting.DEVICE_WEB))
     
     notice.delete()
Example #27
0
 def get_queryset(self):
     """
     return notice list for the current user
     """
     return Notice.notices_for(self.request.user)