Beispiel #1
0
 async def handle_get_activity_info(self, message):
     data = {
         'name':
         self.activity.name,
         'start_time':
         utc_to_local(
             self.activity.start_time).strftime("%Y-%m-%d %H:%M:%S")
         if self.activity.start_time else "未开始",
         'end_time':
         utc_to_local(self.activity.end_time).strftime("%Y-%m-%d %H:%M:%S")
         if self.activity.end_time else "未结束",
         'invite_code':
         id_to_invite_code(self.activity.id)
     }
     return json.dumps({'action': 'activity-info', 'content': data})
Beispiel #2
0
def get_activities(request):
    activities = _get_activities(request)
    json_str = [{
        'id':
        i.id,
        'name':
        i.name,
        'start_time':
        utc_to_local(i.start_time).strftime("%Y-%m-%d %H:%M:%S")
        if i.start_time is not None else "未开始",
        'end_time':
        utc_to_local(i.end_time).strftime("%Y-%m-%d %H:%M:%S")
        if i.start_time is not None else "未结束",
    } for i in activities]
    return HttpResponse(json.dumps(json_str), content_type='application/json')
def danmu_manage(request):
    activity = _get_activity(request, True)
    if isinstance(activity, HttpResponse):
        return activity

    activities = _get_activities(request)

    danmu_times = models.Danmu.objects.filter(activity=activity).only('time')
    danmu_time_range = {}
    for danmu_time in danmu_times:
        minute = danmu_time.time.minute
        minute = minute // 10
        key = utc_to_local(
            danmu_time.time).strftime("%Y-%m-%d %H:") + str(minute) + '0'
        if key not in danmu_time_range:
            danmu_time_range[key] = 1
        else:
            danmu_time_range[key] += 1

    return render(
        request, 'pages/usercenter/danmu_list.html', {
            'danmu_time_range': json.dumps(danmu_time_range),
            'activity': activity,
            'activities': activities
        })
Beispiel #4
0
def get_danmu(request):
    activity = _get_activity(request)
    if isinstance(activity, HttpResponse):
        return activity

    start = int(request.GET.get('start', 0))
    danmus = models.Danmu.objects.filter(activity=activity)
    danmus_count = danmus.count()
    length = int(request.GET.get('length', danmus_count))
    end = min(start + length, danmus_count)
    danmus = danmus.order_by("-id")[start:end]
    participants_dict = dict([
        (k['openid'], k['nickname'])
        for k in activity.participants.values('openid', 'nickname')
    ])

    danmu_list = [{
        'id': d.id,
        'openid': d.sender.openid,
        'nickName': participants_dict[d.sender.openid],
        'text': d.text,
        'time': utc_to_local(d.time).strftime("%Y-%m-%d %H:%M:%S")
    } for d in danmus]

    return HttpResponse(json.dumps({
        'draw': request.GET.get('draw', 0),
        'recordsTotal': danmus_count,
        'recordsFiltered': danmus_count,
        'data': danmu_list
    }),
                        content_type='application/json')
 def test_get_activities(self):
     client = self.client
     r = client.get('/get-activities', data={'activity': 1})
     i = models.Activity.objects.get(id=1)
     expect = json.dumps([{
         'id':
         i.id,
         'name':
         i.name,
         'start_time':
         utc_to_local(i.start_time).strftime("%Y-%m-%d %H:%M:%S")
         if i.start_time is not None else "未开始",
         'end_time':
         utc_to_local(i.end_time).strftime("%Y-%m-%d %H:%M:%S")
         if i.start_time is not None else "未结束",
     }])
     self.assertEqual(r.content.decode(), expect)