def create(self, request, *args, **kwargs): user = request.user if not user.is_superuser: return JsonResponse(R.build(msg="权限不足")) now_time = datetime.datetime.now() data = request.data notice_data = data['notice_content'] title = data["title"] if not notice_data: return JsonResponse({"code": 400, "message": "公告内容不能为空"}) if not title: return JsonResponse({"code": 400, "message": "公告标题不能为空"}) if "update_notice" in data and data["update_notice"] == True: notice_id = data['notice_id'] update_noticeinfo = Notice.objects.filter(notice_id=notice_id, is_public=False).first() update_noticeinfo.update_date = now_time update_noticeinfo.notice_content = json.dumps(notice_data) update_noticeinfo.title = title update_noticeinfo.save() return JsonResponse({"code": 200, "msg": "公告修改成功"}) else: notice_info = Notice(notice_id=str(uuid.uuid4()), title=title, notice_content=json.dumps(notice_data), create_date=now_time) notice_info.save() return JsonResponse({"code": 200, "msg": "提交成功"})
def add(request): if request.POST: noticeid = request.POST.get('noticeid', None) notice_name = request.POST.get('notice_name', None) notice_area = request.POST.get('notice_area', None) notice_type = request.POST.get('notice_type', None) flag = request.POST.get('flag', None) desc = request.POST.get('desc', None) notice_content = request.POST.get('notice_content', None) '''验证重复公告编号''' notices = Notice.objects.filter(noticeid__iexact=noticeid) if notices: return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','noticeindex'), "callbackType":request.POST.get('callbackType',None), "message":u'公告编号已经存在不能添加'}), mimetype='application/json') '''验证重复公告名称''' notices = Notice.objects.filter(notice_name__iexact=notice_name) if notices: return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','noticeindex'), "callbackType":request.POST.get('callbackType',None), "message":u'公告名称已经存在不能添加'}), mimetype='application/json') notice = Notice(noticeid=noticeid, notice_name=notice_name, notice_area=notice_area, notice_type=notice_type, flag=flag, desc=desc, notice_content=notice_content) try: notice.save() return HttpResponse(simplejson.dumps({"statusCode":200, "navTabId":request.POST.get('navTabId','noticeindex'), "callbackType":request.POST.get('callbackType','closeCurrent'), "message":u'添加成功'}), mimetype='application/json') except Exception, e: print e return HttpResponse(simplejson.dumps({"statusCode":302, "navTabId":request.POST.get('navTabId','noticeindex'), "callbackType":request.POST.get('callbackType',None), "message":u'添加失败'}), mimetype='application/json')
def save(self): id_ = self.cleaned_data.get('id') title = self.cleaned_data.get('title') description = self.cleaned_data.get('description') priority = self.cleaned_data.get('priority') expiration_date = self.cleaned_data.get('expiration_date') designation = self.cleaned_data.get('designation') notify_users = self.cleaned_data.get('notify_users') if id_ is not None and id_ != -1: notice = Notice.objects.get(pk=id_) notice.title = title notice.description = description notice.priority = priority notice.expiration_date = expiration_date notice.posted_by_id = designation created = False else: notice = Notice(title=title, description=description, priority=priority, expiration_date=expiration_date, posted_by_id=designation) notify_users = True created = True notice.save() if notify_users: notice.refresh_from_db() notice_signals.notice_done.send(Notice, instance=notice, created=created) return notice
def post_application_notice(sender, instance=None, created=False, **kwargs): entity = instance if created: event = Notice(sender=entity.sender, receiver=entity.receiver, event=entity, type=2) event.save() push(entity.receiver.username, {'type': 2})
def create_notice(image_path, date_str, title, part): _date = date(*map(int, date_str.split('-'))) _notice = Notice(part=part, date=_date, detail_image_url=upload_image(image_path, title, part), title=title) _notice.save() print(_notice.id, _notice.title) print('成功上传:', _notice.title)
def post_comment_notice(sender, instance=None, created=False, **kwargs): entity = instance if created: event = Notice(sender=entity.owner, receiver=entity.passage.owner, event=entity, type=0) event.save() push(entity.passage.owner.username, {'type': 0})
def franchise_new(request, notice=None): error_list = [] initial = {} if request.method == 'POST': data = request.POST files = request.FILES title = data.get('title') content = data.get('content') photo = files.get('photo') board = data.get('board') # 유효성 검사 if len(title) == 0: error_list.append('title을 1글자 이상 입력해주세요.') if re.match(r'^[\da-zA-Z\s]+$', content): error_list.append('한글을 입력해주세요.') if not error_list: # 저장 시도 if notice is None: notice = Notice() notice.title = title notice.content = content if photo: notice.photo.save(photo.name, photo, save=False) try: notice.save() except Exception as e: error_list.append(e) else: # return redirect(item) # item.get_absolute_url 호출됨 return redirect('notice:franchise_list') initial = { 'title': title, 'content': content, 'photo': photo, 'board': board, } else: if notice is not None: initial = { 'title': notice.title, 'content': notice.content, 'photo': notice.photo, 'board': notice.board, } return render(request, 'notice/franchise_form.html', { 'error_list': error_list, 'initial': initial, })
def post_like_notice(sender, instance=None, created=False, **kwargs): entity = instance if created: event = Notice(sender=entity.owner, receiver=entity.passage.owner, event=entity, type=4) event.save() # 消息推送 # 推送对象为消息接受者,推送内容为消息类型 push(entity.passage.owner.username, {'type': 4})
def post(self, request): data = request.form content = data['content'] title = data['title'] genre = data['genre'] mesg = self.valid_data(content, title, genre) if mesg: return r(mesg) notice = Notice(content=content, title=title, genre=genre, image=request.FILES.get('img')) notice.save() return r('OK')
def add(request): if request.POST: noticeid = request.POST.get('noticeid', None) notice_name = request.POST.get('notice_name', None) notice_area = request.POST.get('notice_area', None) notice_type = request.POST.get('notice_type', None) flag = request.POST.get('flag', None) desc = request.POST.get('desc', None) notice_content = request.POST.get('notice_content', None) '''验证重复公告编号''' notices = Notice.objects.filter(noticeid__iexact=noticeid) if notices: return HttpResponse(simplejson.dumps({ "statusCode": 302, "navTabId": request.POST.get('navTabId', 'noticeindex'), "callbackType": request.POST.get('callbackType', None), "message": u'公告编号已经存在不能添加' }), mimetype='application/json') '''验证重复公告名称''' notices = Notice.objects.filter(notice_name__iexact=notice_name) if notices: return HttpResponse(simplejson.dumps({ "statusCode": 302, "navTabId": request.POST.get('navTabId', 'noticeindex'), "callbackType": request.POST.get('callbackType', None), "message": u'公告名称已经存在不能添加' }), mimetype='application/json') notice = Notice(noticeid=noticeid, notice_name=notice_name, notice_area=notice_area, notice_type=notice_type, flag=flag, desc=desc, notice_content=notice_content) try: notice.save() return HttpResponse(simplejson.dumps({ "statusCode": 200, "navTabId": request.POST.get('navTabId', 'noticeindex'), "callbackType": request.POST.get('callbackType', 'closeCurrent'), "message": u'添加成功' }), mimetype='application/json') except Exception, e: print e return HttpResponse(simplejson.dumps({ "statusCode": 302, "navTabId": request.POST.get('navTabId', 'noticeindex'), "callbackType": request.POST.get('callbackType', None), "message": u'添加失败' }), mimetype='application/json')
def user_follow_notice(sender, instance=None, created=False, **kwargs): entity = instance if created: event = Notice(sender=entity.fans, receiver=entity.follows, event=entity, type=1) event.save() push(entity.follows.username, {'type': 1})