コード例 #1
0
ファイル: admin.py プロジェクト: NTP1996/OnlineJudge
 def post(self, request):
     """
     发布公告
     """
     data = request.data
     announcement = Announcement.objects.create(title=data["title"],
                                                content=data["content"],
                                                created_by=request.user,
                                                visible=data["visible"])
     return self.success(AnnouncementSerializer(announcement).data)
コード例 #2
0
ファイル: viadmin.py プロジェクト: xchf/ICQBPMSSOJ
 def post(self, request):
     """
     发布通知信息,增加
     :param request: 请求
     :return: 返回序列化数据
     """
     data = request.data
     announcement = Announcement.objects.create(
         title=data["title"],
         content=data["content"],
         created_by=request.user,
         visible=data["visible"],
     )
     return self.success(AnnouncementSerializer(announcement).data)
コード例 #3
0
 def get(self, request):
     """
     get announcement list / get one announcement
     """
     announcement_id = request.GET.get("id")
     if announcement_id:
         try:
             announcement = Announcement.objects.get(id=announcement_id)
             return self.success(AnnouncementSerializer(announcement).data)
         except Announcement.DoesNotExist:
             return self.error("Announcement does not exist")
     announcement = Announcement.objects.all().order_by("-create_time")
     if request.GET.get("visible") == "true":
         announcement = announcement.filter(visible=True)
     return self.success(self.paginate_data(request, announcement, AnnouncementSerializer))
コード例 #4
0
ファイル: admin.py プロジェクト: NTP1996/OnlineJudge
    def put(self, request):
        """
        编辑公告
        """
        data = request.data
        try:
            announcement = Announcement.objects.get(id=data.pop("id"))
        except Announcement.DoesNotExist:
            return self.error("Announcement does not exist")

        for k, v in data.items():
            setattr(announcement, k, v)
        announcement.save()

        return self.success(AnnouncementSerializer(announcement).data)
コード例 #5
0
ファイル: admin.py プロジェクト: Gumbeat/Olymp
    def put(self, request):
        """
        edit announcement
        """
        data = request.data
        try:
            announcement = Announcement.objects.get(id=data.pop("id"))
        except Announcement.DoesNotExist:
            return self.error("Соревнование не существует")

        for k, v in data.items():
            setattr(announcement, k, v)
        announcement.save()

        return self.success(AnnouncementSerializer(announcement).data)
コード例 #6
0
ファイル: viadmin.py プロジェクト: xchf/ICQBPMSSOJ
 def get(self, request):
     """
     获取announcement list 或者 get one announcement,获取数据
     :param request: 请求
     :return: 序列化数据
     """
     announcement_id = request.GET.get("id")
     if announcement_id:
         try:
             announcement = Announcement.objects.get(id=announcement_id)
             return self.success(AnnouncementSerializer(announcement).data)
         except Announcement.DoesNotExist:
             return self.error("Announcement does not exist")
     # 根据创建的时间将通知查询出来,使用条件查询,将可见的通知分页显示
     announcement = Announcement.objects.all().order_by("-create_time")
     if request.GET.get("visible") == "true":
         announcement = announcement.filter(visible=True)
     return self.success(
         self.paginate_data(request, announcement, AnnouncementSerializer))
コード例 #7
0
def getAnnounceJSON(request):
    now = datetime.datetime.now()
    announces = AnnouncementModel.objects.filter(start_time__lte=now, end_time__gt=now, is_active=True)
    json_obj =  AnnouncementSerializer(announces, many=True)
    return JsonResponse(json_obj.data, safe=False)