def test_str(self): """Ensure that an Announcement object's string representation is simply its title. """ announcement = Announcement(title='Title') announcement.save() self.assertEqual(announcement.title, str(announcement))
def create(self, request, *args, **kwargs): # custom parameters post_req = self.cleaned_data(request=request) # validate data enter v = Validator(announcements_schema()) v.allow_unknown = True if not v.validate(post_req): return Response({"message": v.errors}, status=status.HTTP_400_BAD_REQUEST) # add announcement announcement = Announcement( title=post_req['title'], description=post_req['description'], date=post_req['date'] if post_req.get('date', None) else datetime.datetime.now(), release_time=post_req['release_time'] if post_req.get( 'release_time', None) else datetime.datetime.now(), has_date=post_req.get('has_date', False), image=request.data.get('image') if request.data.get('image') else "", creator_id=self.request.user.id) announcement.save() AnnouncementViewSet.last_announcement_date = get_last_announcement_publish_date( ) AnnouncementViewSet.near_next_announcement_date = get_near_next_announcement_publish_date( ) # add files for announcement self.save_file(announcement, request) # add announcement receiver self.add_announcement_receiver(announcement, post_req) return Response(status=status.HTTP_201_CREATED)
def project_created(name, authors, description, url): """Creates a new Announcement indicating that a new Project was created. Args: name: the name of the project authors: a list of the project's authors description: a description of the project url: the relative url for the project's individual detail page """ announcement = Announcement(title='New Project!', body=[{ 'element': 'h3', 'content': name }, { 'element': 'h6', 'content': ', '.join(authors) }, { 'element': 'p', 'content': description }, { 'element': 'hr' }, { 'element': 'a', 'href': url, 'content': 'Read More' }]) announcement.save()
def test_list_action_valid_count_less_than_num_in_db(self): """Ensure that specifying a valid count does not cause any issues. """ e = Announcement( title='Second Announcement', body=[{'element': 'hr'}] ) e.save() url = reverse('announcement-list') response = self.client.get(f'{url}?count=1') self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(1, len(response.data))
def event_created(event_type, start): """Creates a new Announcement indicating that a new Event was created. Args: event_type: the type of Event that was created start: the start date and time of the event """ announcement = Announcement(title='New Event!', body=[{ 'element': 'p', 'content': render_to_string('event/created_body.txt', context={ 'type': event_type, 'start': start }) }]) announcement.save()
def announcements(request): if request.POST: form = request.POST body = form['Body'] from_number = form['From'] account_sid = form['AccountSid'] if from_number in APPROVED_NUMBERS and \ account_sid == os.environ['TWILIO_SID']: a = Announcement() a.message = body a.time = datetime.datetime.now() a.save() device = FCMDevice.objects.all() device.send_message(message=a.message) return success_data_jsonify({}) else: all_announcements = Announcement.objects.all() announcement_array = [] for announcement in all_announcements: announcement_array.append(announcement.dictionary_representation()) return success_data_jsonify(announcement_array)