def sendBulletin(request): try: bulletin = { 'sender': 'test', 'subject': str(request.POST['subject']), 'content': str(request.POST['message']), 'timestamp': int(time.time()) } Dynamo.initialize().send_bulletin(BulletinSerializer(bulletin).data) return redirect(bulletinBoard) except Exception as e: print("\tERROR\tFailed to create bulletin: " + str(e)) return redirect(error_bulletin)
def send_message(request): try: user = User.objects.get(username=str(request.POST['username'])).username to_send = Message( sender='test', recipient=user, urgency=int(request.POST['urgency']), content=str(request.POST['message']), timestamp=int(time.time()), read=False ) Dynamo.initialize().send_message(MessageSerializer(to_send).data) Dynamo.get_messages_by_recipient(user) return redirect(message_view) except Exception as e: print("\tERROR\tFailed to create message: " + str(e)) return redirect(error_message)
def sendEvent(request): try: starttime = request.POST['starttime'] starttime = time.mktime(datetime.datetime.strptime(starttime, "%Y-%m-%dT%H:%M").timetuple()) endtime = request.POST['endtime'] endtime = time.mktime(datetime.datetime.strptime(endtime, "%Y-%m-%dT%H:%M").timetuple()) event = { 'sender': 'test', 'title': str(request.POST['title']), 'content': str(request.POST['message']), 'location': str(request.POST['location']), 'timestamp': int(time.time()), 'starttime': starttime, 'endtime': endtime, } Dynamo.initialize().send_event(EventSerializer(event).data) return redirect(calendar) except Exception as e: print("\tERROR\tFailed to create event: " + str(e)) return redirect(error_event)
def sendComment(request): try: bulletin_reference = request.POST['bulletinSender'] + ':' + request.POST['bulletinTimestamp'] bulletin = Dynamo.get_bulletin_by_reference(bulletin_reference) comment = { 'sender': 'test', 'content': str(request.POST['message']), 'bulletin_reference': bulletin_reference, 'timestamp': int(time.time()) } Dynamo.initialize().send_comment(comment) comments = Dynamo.get_comments(bulletin) # for comment in comments: # comment["timestamp"] = time.strftime("%a, %d %b %Y %H:%M", time.localtime(comment["timestamp"])) return render(request, 'bulletin.html', {'bulletin': bulletin, 'comment_list':comments}) except Exception as e: print("\tERROR\tFailed to send bulletin comment: " + str(e)) return redirect(error_comment)