def new(request): if request.method == 'GET': return render(request, 'boards/new.html') elif request.method == 'POST': title = request.POST.get('title') content = request.POST.get('content') id = request.POST.get('id') if id: board = Board.objects.get(id=id) board.title = title board.content = content image = request.FILES.get('image') board.image = image board.save() return redirect('boards:detail', board.id) image = request.FILES.get('image') board = Board( title=title, content=content, image=image, ) board.save() # print(Board.objects.all()) # return render(request, 'boards/create.html', context) return redirect('boards:detail', board.id)
def test_board_name_date(self): """ Create and test a board for correct name and active date """ board = Board(name="Test Board", post_code=PostCodeDistrict.objects.get(pk=1)) board.save() self.assertEqual(board.name, 'Test Board') self.assertEqual(board.date_active, date.today())
class BoardAPIViewTest(TestCase): """Test suite for the Board API views.""" def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() # self.client.force_authenticate(self.user) def test_api_can_create_a_new_board(self): response = self.client.post('/api/v1/boards/', { "title": "Test Board 2", "created_by": self.user.id }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['id'], self.board.pk + 1) def test_api_can_update_a_board(self): response = self.client.put('/api/v1/boards/{0}/'.format(self.board.pk), {"title": "Test Board Updated"}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['title'], 'Test Board Updated') def test_api_can_delete_a_board(self): old_count = Board.objects.count() response = self.client.delete('/api/v1/boards/{0}/'.format( self.board.pk)) new_count = Board.objects.count() self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertNotEqual(old_count, new_count)
def mutate(root, info, **kwargs): ok = True board = Board( name=kwargs.get('name'), description=kwargs.get('description'), ) board.save() return CreateBoard(ok=ok, board=board)
def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.column = Column(board=self.board, title='Backlog', position=1) self.column.save()
def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save()
def create(request): # create if request.method == 'POST': title = request.POST.get('title') # 글 제목 content = request.POST.get('content') # 글 내용 board = Board(title=title, content=content) board.save() return redirect('boards:detail', board.pk) # new else: return render(request, 'boards/create.html')
def form_valid(self, form): """ Handle board form data. """ board = Board( author=current_user.id, desk_id=self.user.desk_owner.id, title=form.title.data, sequence=Board.get_next_sequence(self.user), prefix=form.prefix.data, sticker_sequence=1 ) db.session.add(board)
def create_default_boards(user): board = Board.new(user, "Welcome") basic_list = List.objects.create(title="Basic", board=board) advanced_list = List.objects.create(title="Advanced", board=board) ListEntry.objects.create( title="Add new list items to this list", description="""You can add new list items to any list by pressing the \"Add new lists\" button""", parent_list=basic_list, ) ListEntry.objects.create( title="Add members to a list item", description="""You can add members to a list item. Try it!""", parent_list=basic_list, ) ListEntry.objects.create( title="Create a new list", description="""You can create new lists in this board. Try it!""", parent_list=advanced_list, )
def new(request): # GET if request.method == 'GET': return render(request, 'boards/new.html') # POST else: title = request.POST.get('title') content = request.POST.get('content') image = request.FILES.get('image') board = Board(title=title, content=content, image=image) board.save() # get인지 post인지 확인 # print(request.method) return redirect('boards:detail', board.id)
class LabelAPIViewTest(TestCase): """Test suite for the Label API views.""" def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save() # self.client.force_authenticate(self.user) def test_api_can_create_a_new_label(self): response = self.client.post( '/api/v1/boards/{board_pk}/labels/'.format(board_pk=self.board.pk), { "title": "Green Label", "color": "#00FF00" }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['id'], self.label.pk + 1) def test_api_can_update_a_label(self): response = self.client.put( '/api/v1/boards/{board_pk}/labels/{label_pk}/'.format( board_pk=self.board.pk, label_pk=self.label.pk), { "title": "Blue Label", "color": "#0000FF" }) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['title'], 'Blue Label') self.assertEqual(response.data['color'], '#0000FF') def test_api_can_delete_a_label(self): old_count = Label.objects.count() response = self.client.delete( '/api/v1/boards/{board_pk}/labels/{label_pk}/'.format( board_pk=self.board.pk, label_pk=self.label.pk), ) new_count = Label.objects.count() self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertNotEqual(old_count, new_count)
def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.column = Column(board=self.board, title='Backlog', position=1) self.column.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save() self.label2 = Label(board=self.board, title='Green Label', color='#00FF00') self.label2.save() self.card = Card(board=self.board, title='Test Card', description='Test Card description', created_by=self.user) self.card.save()
class ColumnAPIViewTest(TestCase): """Test suite for the Column API views.""" def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.column = Column(board=self.board, title='Backlog', position=1) self.column.save() # self.client.force_authenticate(self.user) def test_api_can_create_a_new_column(self): response = self.client.post( '/api/v1/boards/{board_pk}/columns/'.format( board_pk=self.board.pk), { "title": "In Progress", "position": 2 }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['id'], self.column.pk + 1) # TODO // Column tests should use the position def test_api_can_update_a_column(self): response = self.client.put( '/api/v1/boards/{board_pk}/columns/{position}/'.format( board_pk=self.board.pk, position=1), { "title": "Selected for Development", }) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['title'], 'Selected for Development') def test_api_can_delete_a_column(self): old_count = Column.objects.count() response = self.client.delete( '/api/v1/boards/{board_pk}/columns/{position}/'.format( board_pk=self.board.pk, position=1), ) new_count = Column.objects.count() self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertNotEqual(old_count, new_count)
def test_book_create(self): board_count = Board.objects.count() intersection_count = Intersection.objects.count() path_count = Path.objects.count() terrain_count = Terrain.objects.count() board = Board.create() print board board.save() self.assertEquals(board_count + 1, Board.objects.count()) self.assertEquals(intersection_count + 54, Intersection.objects.count()) self.assertEquals(path_count + 70, Path.objects.count()) self.assertEquals(terrain_count + 19, Terrain.objects.count())
def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save() self.label2 = Label(board=self.board, title='Green Label', color='#00FF00') self.label2.save() self.card = Card(board=self.board, title='Test Card', description='Test Card description', created_by=self.user) self.card.save() self.comment = Comment(card=self.card, message='Test message.', created_by=self.user) self.comment.save()
def setUp(self): self.app = create_app('test') self.app_context = self.app.app_context() self.app_context.push() db.create_all() self.client = self.app.test_client() user = Profile(email='*****@*****.**', username='******', password='******', display_name='u1', motivation_quote='u1') db.session.add(user) db.session.commit() desk = Desk(author=user.id, owner_id=user.id, desk_slug='test') db.session.add(desk) db.session.commit() board = Board(author=user.id, desk_id=desk.id, title='test', sequence=1, prefix='test') db.session.add(board) db.session.commit() label = Label(color='#fff', css_class='OPEN', status='OPEN') db.session.add(label) db.session.commit() sticker = Sticker(author=user.id, board_id=board.id, caption='test', description='test', label_id=label.id, sequence=1) db.session.add(sticker) db.session.commit() self.client.post( url_for('bp_authentication.login', username='******', password='******'))
def setUp(self): board_objects_list = [] for i in range(10): board_objects_list.append( Board(name=i, slug=i, description="unique objects")) Board.objects.bulk_create(objs=board_objects_list)
updated_by = models.ForeignKey(User, null=True, related_name='+') #Migrating the Models python manage.py makemigrations #you can run the following command to inspect the SQL instructions that will be executed in the database python manage.py sqlmigrate boards 0001 #apply the migration we generated to the database python manage.py migrate #You can start a Python shell with our project loaded using the manage.py utility python manage.py shell #importing the Board class from boards.models import Board #create a new board object, we can do the following board = Board(name='Django', description='This is a board about Django.') #To persist this object in the database, we have to call the save method board.save() #You can access the rest of the fields as Python attributes board.name #To update a value we could do board.description = 'Django discussion board.' board.save() #We can use the objects to list all existing boards in the database Board.objects.all() #exit the interactive console exit() #The __str__ method is a String representation of an object. We can use the board name to represent it.
with open('data/1.json') as json_data: j = json.loads(json_data.read()) json_data.close() for row in j['rows']: cell = row['cell'] print cell board = Board() soup = BeautifulSoup(cell[1]) try: address = soup.find('img')['alt'].split(' +',1)[0] except Exception as e: print 'no address' else: board.address = address try: dirty_coords = soup('img')[1]['alt'] except: print 'no coords'
class CommentAPIViewSet(TestCase): """Test suite for the Comment API views.""" def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save() self.label2 = Label(board=self.board, title='Green Label', color='#00FF00') self.label2.save() self.card = Card(board=self.board, title='Test Card', description='Test Card description', created_by=self.user) self.card.save() self.comment = Comment(card=self.card, message='Test message.', created_by=self.user) self.comment.save() # self.client.force_authenticate(self.user) def test_api_can_create_a_new_comment(self): response = self.client.post( '/api/v1/boards/{board_pk}/cards/{card_pk}/comments/'.format( board_pk=self.board.pk, card_pk=self.card.pk), { "message": "Test Message 2.", "created_by": self.user.pk, }, format='json' # Explicit format: otherwise list is sent as str() ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['id'], self.comment.pk + 1) def test_api_can_update_a_comment(self): response = self.client.put( '/api/v1/boards/{board_pk}/cards/{card_pk}/comments/{comment_pk}/'. format(board_pk=self.board.pk, card_pk=self.card.pk, comment_pk=self.comment.pk), { "message": "Test Message 2 edited.", "updated_at": "2017-12-17 06:26:53", "updated_by": self.user.pk }) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['message'], 'Test Message 2 edited.') self.assertEqual(response.data['updated_at'], "2017-12-17T06:26:53Z") self.assertEqual(response.data['updated_by'], self.user.pk) def test_api_can_delete_a_comment(self): old_count = Comment.objects.count() response = self.client.delete( '/api/v1/boards/{board_pk}/cards/{card_pk}/comments/{comment_pk}/'. format(board_pk=self.board.pk, card_pk=self.card.pk, comment_pk=self.comment.pk), ) new_count = Comment.objects.count() self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertNotEqual(old_count, new_count)
def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save()
def delete(self, request, pk, format=None): Board = self.get_object(pk) Board.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def create(self, validated_data): board = Board(owner_id=validated_data['user'], name=validated_data['name']) board.save()
''' Author: huangjy Date: 2020-11-22 08:59:39 LastEditors: huangjy LastEditTime: 2020-11-22 10:02:18 Description: models api 学习和使用 ''' from boards.models import Board #创建对象 board = Board(name='java', description='java is good language') #保存对象 board.save() #访问字段的值 board.id board.name board.description #更新字段 board.description = "This is effective java" board.description #每个Django模型都带有一个特殊的属性; 我们称之为模型管理器(Model Manager) 可通过objects 访问 #通过objects 创建新对象 board = Board.objects.create(name="Python", description="General discussion about Python") #>>> Board.objects.all() # <QuerySet [<Board: Board object (1)>, <Board: Board object (2)>, <Board: Board object (3)>]> #未实现 Board 的__str__ 方法。__str__方法是对象的字符串表示形式 # 定义之后展示 #<QuerySet [<Board: 板块id:1, 板块名称:Django>, <Board: 板块id:2, 板块名称:java>, <Board: 板块id:3, 板块名称:Python>]>
class CardAPIViewSet(TestCase): """Test suite for the Card API views.""" def setUp(self): self.client = APIClient() self.user = setup_user() self.user.save() self.board = Board(title='Test Board', created_by=self.user) self.board.save() self.column = Column(board=self.board, title='Backlog', position=1) self.column.save() self.label = Label(board=self.board, title='Red Label', color='#FF0000') self.label.save() self.label2 = Label(board=self.board, title='Green Label', color='#00FF00') self.label2.save() self.card = Card(board=self.board, title='Test Card', description='Test Card description', created_by=self.user) self.card.save() # self.client.force_authenticate(self.user) def test_api_can_create_a_new_card(self): response = self.client.post( '/api/v1/boards/{board_pk}/cards/'.format(board_pk=self.board.pk), { "column": None, "title": "Test Card", "description": "Test Card description.", "created_by": self.user.pk, "labels": [self.label.pk, self.label2.pk] }, format='json' # Explicit format: otherwise list is sent as str() ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.data['id'], self.card.pk + 1) def test_api_can_update_a_card(self): response = self.client.put( '/api/v1/boards/{board_pk}/cards/{card_pk}/'.format( board_pk=self.board.pk, card_pk=self.card.pk), { "title": "Edited Test Card", "description": "Test Card description updated.", }) print(response.data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['title'], 'Edited Test Card') self.assertEqual(response.data['description'], 'Test Card description updated.') def test_api_can_delete_a_card(self): old_count = Card.objects.count() response = self.client.delete( '/api/v1/boards/{board_pk}/cards/{card_pk}/'.format( board_pk=self.board.pk, card_pk=self.card.pk), ) new_count = Card.objects.count() self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT) self.assertNotEqual(old_count, new_count)
sys.path.append(base_dir) os.environ['DJANGO_SETTINGS_MODULE'] = 'ndnuconnect.settings' django.setup() # User model from accounts.models import User # Tutor model from tutor_match.models import Department, Subject, Tutor, Schedule, Student # Board model from boards.models import Board, Topic, Post # Job model from job_find.models import Job # Creating boards try: board1 = Board(name='Announcements', description='Announce upcoming events at NDNU') board1.save() board2 = Board(name='Homework', description='Get help for homework.') board2.save() board3 = Board(name='Random', description='Random board') board3.save() print("The boards have been created.") except: print("Boards exist") # Creating a user and jobs try: user1 = User.objects.create_user("*****@*****.**", "workerpassword", first_name="John",
def new_board(request): title = request.POST['board_title'] board = Board.new(request.user, title) return redirect("board", board.id)