def test_topic_to_blockchain(self): self.topic = Topic.objects.create( title='Improve test module', body='implement class that autogenerates users', owner=self.thinker, ) #self.topic.create_snapshot(blockchain=1) self.topic.create_snapshot(blockchain=False) self.topic.save() self.assertEqual( TopicSnapshot.objects.filter(topic=self.topic).count(), 1) self.comment = Comment(topic=self.topic, text=""" - {1.5},{?0.5} for coming up with basic class structure, - {?2.5} for implementation, - {?3.5} for testing. Here is the result so far: https://github.com/wefindx/infty2.0/commit/9f096dc54f94c31eed9558eb32ef0858f51b1aec """, owner=self.doer) self.comment.save() # self.comment.create_snapshot(blockchain=1) self.comment.create_snapshot(blockchain=False) self.assertEqual( CommentSnapshot.objects.filter(comment=self.comment).count(), 1)
def postdiscus(request, id): post = get_object_or_404(Post, id=id) comments = post.comments.filter(post=post) comment = Comment(body=post_text, author=request.user) comment.save() context = {"post": post, "comments": comments} return render(request, "chatroom.html", context)
def create_fake_comments(number=10): Comment.objects.all().delete() for i in range(number): instance = Comment( name=fake.name(), email=fake.email(), content=fake.text() ) instance.save()
def issue_comment_send(request): issue = get_object_or_404(Issue, id=request.POST.get("issue", 0)) text = request.POST.get("comment") comment = Comment() comment.created_by = request.user comment.comment = text comment.issue = issue comment.save() return issue_poll(request)
def __init__(self, object, *args, **kwargs): object_id = object.id content_type = get_content_type_for_model(object) # If there is no instance, make a fake one! if not 'instance' in kwargs: kwargs['instance'] = Comment(object_id=object_id, content_type=content_type) super(CommentForm, self).__init__(*args, **kwargs)
def setUp(self): # Let's say we have currencies: self.hur = Currency(label='hur') self.hur.save() self.eur = Currency(label='eur') self.eur.save() self.usd = Currency(label='usd') self.usd.save() # And some currency prices: self.hprice = HourPriceSnapshot( name='FRED', base=self.usd, data=json.loads(""" {"realtime_start":"2017-07-28","realtime_end":"2017-07-28","observation_start":"1600-01-01","observation_end":"9999-12-31","units":"lin","output_type":1,"file_type":"json","order_by":"observation_date","sort_order":"desc","count":136,"offset":0,"limit":1,"observations":[{"realtime_start":"2017-07-28","realtime_end":"2017-07-28","date":"2017-06-01","value":"26.25"}]}""" ), endpoint= 'https://api.stlouisfed.org/fred/series/observations?series_id=CES0500000003&api_key=0a90ca7b5204b2ed6e998d9f6877187e&limit=1&sort_order=desc&file_type=json', ) self.hprice.save() self.cprice = CurrencyPriceSnapshot( name='FIXER', base=self.eur, data=json.loads(""" {"base":"EUR","date":"2017-07-28","rates":{"AUD":1.4732,"BGN":1.9558,"BRL":3.7015,"CAD":1.4712,"CHF":1.1357,"CNY":7.9087,"CZK":26.048,"DKK":7.4364,"GBP":0.89568,"HKD":9.1613,"HRK":7.412,"HUF":304.93,"IDR":15639.0,"ILS":4.1765,"INR":75.256,"JPY":130.37,"KRW":1317.6,"MXN":20.809,"MYR":5.0229,"NOK":9.3195,"NZD":1.5694,"PHP":59.207,"PLN":4.2493,"RON":4.558,"RUB":69.832,"SEK":9.5355,"SGD":1.5947,"THB":39.146,"TRY":4.1462,"USD":1.1729,"ZAR":15.281}}""" ), endpoint='https://api.fixer.io/latest?base=eur', ) self.cprice.save() # Let's say we have a user 'thinker', 'doer' and 'investor'.. self.thinker = self.make_user('thinker') self.thinker.save() self.doer = self.make_user('doer') self.doer.save() self.investor = self.make_user('investor') self.investor.save() # Let's say thinker writes a topic. self.topic = Topic.objects.create( title='Improve test module', body='implement class that autogenerates users', owner=self.thinker, ) self.topic.save() # Let's say a doer writes a comment with declared hours, # more than available in daily quota day: self.comment = Comment(topic=self.topic, text=""" - {14.5},{?0.5} for coming up with basic class structure, """, owner=self.doer) self.comment.save()
def post(self, request): # pass filled out HTML-Form from View to CommentForm() form = CommentForm(request.POST) if form.is_valid(): # create a Comment DB Entry text = form.cleaned_data['text'] video_id = request.POST['video'] video = Video.objects.get(id=video_id) new_comment = Comment(text=text, user=request.user, video=video) new_comment.save() return HttpResponseRedirect('/video/{}'.format(str(video_id))) return HttpResponse('This is Register view. POST Request.')
def create_comment(request): data = json.loads(request.body) name = data['name'] tree_url = data['tree'] comment = data['comment'] if None in (name, tree_url, comment): return HttpResponse(status=400) associated_tree = get_object_or_404(Location, url=tree_url) newcomment = Comment(name=name, associated_tree=associated_tree, comment=comment) print newcomment newcomment.save() return HttpResponse(status=200)
def Detail(request, pk): post = Post.objects.get(pk=pk) comments = Comment.objects.filter(post=post) form = CommentForm() context = { 'post': post, 'comments': comments, 'form': form, } if request.is_ajax() and request.POST: text = request.POST.get('comment') comment = Comment(text=text, post=post) comment.save() data = {'message': request.POST.get('comment')} return HttpResponse(json.dumps(data), content_type='application/json') return render(request, 'core/detail.html', context)
def make_comment(request,pk): if request.method == 'POST': form = CommentCreateForm(request.POST) if form.is_valid(): # breakpoint() content = form.cleaned_data['content'] book = Book.objects.get(pk=pk) new_comment = Comment(user=request.user,content=content,target_book=book) new_comment.save() return redirect(to='book-detail', pk=pk) else: form = CommentCreateForm() book = Book.objects.get(pk=pk) return render(request, 'core/comment.html', { 'book' : book, 'form' : form, })
def comment_list(request, stock_id=""): ''' comment_list ''' if request.method == 'GET': if not request.user.is_authenticated: return HttpResponse(status=401) response_list = [] for comment_ in Comment.objects.filter(stock=stock_id).iterator(): response_list.append({ 'stock': stock_id, 'time': comment_.time, 'content': comment_.content, 'author': comment_.author.nickname, 'author_id': comment_.author.id, 'id': comment_.id }) return JsonResponse(response_list, safe=False) if request.method == 'POST': if not request.user.is_authenticated: return HttpResponse(status=401) stock = get_object_or_404(Stock, id=stock_id) try: req_data = json.loads(request.body.decode()) comment_content = req_data['content'] comment_author = req_data['author'] except (KeyError, JSONDecodeError): return HttpResponseBadRequest() user = get_user_model().objects.get(nickname=comment_author) comment_ = Comment(stock=stock, content=comment_content, author=user) comment_.save() response_dict = { 'id': comment_.id, 'stock': comment_.stock.id, 'time': comment_.time, 'content': comment_.content, 'author': comment_.author.nickname, 'author_id': comment_.author.id } return JsonResponse(response_dict, status=201) return HttpResponseNotAllowed(['GET', 'POST'])
def newcomment(request, urlCode): """Adds a new comment to the database""" output = "OK" debugvar = 0 try: if (request.method == "POST"): name = request.POST["name"] name = javaScriptEscape(name) message = request.POST["message"] message = javaScriptEscape(message) side = request.POST["side"] side = javaScriptEscape(side) chunk = int(request.POST["chunk"]) line = int(request.POST["line"]) # basic sanity check if (not (side == 'lhs' or side == 'rhs')): output = "ERROR" else: targetPatch = get_object_or_404(Patch, pk=urlCode) print "patch - ", urlCode, " chunknum ", chunk targetChunks = Chunk.objects.filter(patch=targetPatch, chunkNum=chunk) print "Target chunks length - " + str(len(targetChunks)) targetChunk = targetChunks[0] newComment = Comment() newComment.chunk = targetChunk newComment.commentAuthor = name newComment.commentText = message newComment.diffSide = side newComment.commentLine = line newComment.chunkID = chunk newComment.commentID = 0 newComment.save() else: output = "ERROR" except Exception as e: from IPython import Shell Shell.IPShellEmbed() print "exception ", e output = "ERROR" return HttpResponse(output)
def AddNewComment(request, slug): if request.user.is_anonymous(): ComOwner = request.POST.get('ItemOwner') ComOwnerFN = "" ComOwnerState = "non-confirmed" else: for account in request.user.socialaccount_set.all(): ItemOwnerPrvdr = account.provider if ItemOwnerPrvdr == "facebook": ComOwner = account.extra_data['username'] ComOwnerFN = "" ComOwnerState = "confirmed" elif ItemOwnerPrvdr == "twitter": ComOwner = account.extra_data['screen_name'] ComOwnerFN = "" ComOwnerState = "confirmed" elif ItemOwnerPrvdr == "google": ComOwner = account.extra_data['name'] ComOwnerFN = account.extra_data['id'] ComOwnerState = "confirmed" elif ItemOwnerPrvdr == "persona": ComOwner = account.user ComOwnerFN = "" ComOwnerState = "confirmed" else: pass ComContent = request.POST.get('comment') ComPubDate = timezone.now() list = get_object_or_404(List, slug=slug) p = Comment( NewComment=list, ComContent=ComContent, ComOwnerState=ComOwnerState, ComOwner=ComOwner, ComPubDate=ComPubDate, ) p.save() return HttpResponseRedirect(reverse('sopler:list', args=(list.slug, )))
def sendcomment(request): user = request.user form = CommentForm(request.POST) if form.is_valid(): data = form.cleaned_data classname = data['objectclass'] objclass = { 'Mix': Mix, 'Group': Group, 'Tag': Tag, 'Platform': Platform }[classname] obj = objclass.objects.get(id=data['objectid']) comment = Comment(content_object=obj, text=data['text'], user=user) comment.save() return HttpResponseRedirect(comment.get_absolute_url()) else: #2do error message return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def save_comments(data_comments, id_posts): cleaned_comments = [] for obj in data_comments: if not id_posts[obj["postId"]]: continue obj["post"] = id_posts[obj["postId"]] cleaned_comments.append( Comment(name=obj["name"], email=obj["email"], body=obj["body"], post=obj["post"])) response_comments = Comment.objects.bulk_create(cleaned_comments, ignore_conflicts=True) response_comments = remove_unvalid_objects(response_comments) return response_comments
def create_comment(comment, author, post_id): comment = Comment(comment=comment, post_id=post_id, author=author) comment.save() return comment.toJSON()
def list(self, request, *args, **kwargs): # return Response({'something': 'my custom JSON'}) comment = Comment(email='*****@*****.**', content='foo bar') serializer = CommentSerializer(comment) return Response(serializer.data)
def setUp(self): # Let's say we have currencies: self.hur = Currency(label='hur') self.hur.save() self.usd = Currency(label='usd') self.usd.save() self.eur = Currency(label='eur') self.eur.save() self.cny = Currency(label='cny') self.cny.save() self.gbp = Currency(label='gbp') self.gbp.save() # Let's say we have the hour price, and currency prices # collected periodically: # # - HourPriceSnapshot # - CurrencyPriceSnapshot0 self.hprice = HourPriceSnapshot( name='FRED', base=self.usd, data=json.loads(""" {"realtime_start":"2017-07-28","realtime_end":"2017-07-28","observation_start":"1600-01-01","observation_end":"9999-12-31","units":"lin","output_type":1,"file_type":"json","order_by":"observation_date","sort_order":"desc","count":136,"offset":0,"limit":1,"observations":[{"realtime_start":"2017-07-28","realtime_end":"2017-07-28","date":"2017-06-01","value":"26.25"}]}""" ), endpoint= 'https://api.stlouisfed.org/fred/series/observations?series_id=CES0500000003&api_key=0a90ca7b5204b2ed6e998d9f6877187e&limit=1&sort_order=desc&file_type=json', ) self.hprice.save() self.cprice = CurrencyPriceSnapshot( name='FIXER', base=self.eur, data=json.loads(""" {"base":"EUR","date":"2017-07-28","rates":{"AUD":1.4732,"BGN":1.9558,"BRL":3.7015,"CAD":1.4712,"CHF":1.1357,"CNY":7.9087,"CZK":26.048,"DKK":7.4364,"GBP":0.89568,"HKD":9.1613,"HRK":7.412,"HUF":304.93,"IDR":15639.0,"ILS":4.1765,"INR":75.256,"JPY":130.37,"KRW":1317.6,"MXN":20.809,"MYR":5.0229,"NOK":9.3195,"NZD":1.5694,"PHP":59.207,"PLN":4.2493,"RON":4.558,"RUB":69.832,"SEK":9.5355,"SGD":1.5947,"THB":39.146,"TRY":4.1462,"USD":1.1729,"ZAR":15.281}}""" ), endpoint='https://api.fixer.io/latest?base=eur', ) self.cprice.save() # Let's say we have a user 'thinker'.. self.thinker = self.make_user('thinker') self.thinker.save() # ..who writes a post: self.topic = Topic.objects.create( title='Improve test module', body='implement class that autogenerates users', owner=self.thinker, ) self.topic.save() # Then, we have a user 'doer'.. self.doer = self.make_user('doer') self.doer.save() # ..who creates a comment on it, with: self.comment = Comment( topic=self.topic, # 1. time spent inside "{...}" brackets # 2. estimates of future time needed inside "{?...}" # 3. declared work result - the content of comment text=""" - {1.5},{?0.5} for coming up with basic class structure, - {?2.5} for implementation, - {?3.5} for testing. Here is the result so far: https://github.com/wefindx/infty2.0/commit/9f096dc54f94c31eed9558eb32ef0858f51b1aec """, owner=self.doer) self.comment.save() # ...and another comment, with some other amount of time, and result: self.comment2 = Comment(topic=self.topic, text=""" - {?8} for testing. Here is the result so far: https://wiki.mindey.com/shared/screens/7e402349b3c2e3a626b5d25fd.png """, owner=self.doer) self.comment2.save() # Then, investor comes in: self.investor = self.make_user('investor') self.investor.save() # And there is another investor: self.investor2 = self.make_user('investor2') self.investor2.save() # And there is another investor: self.investor3 = self.make_user('investor3') self.investor3.save()
def setUp(self): self.username = "******" self.email = "*****@*****.**" self.password = "******" self.testuser = User.objects.create_user( self.username, self.email, is_superuser=False, is_staff=False) self.testuser.set_password(self.password) self.testuser.save() self.client.force_authenticate(user=User.objects.first()) self.topic = Topic.objects.create( title='Test topic 1', owner=self.testuser, ) self.topic_url = reverse('topic-detail', kwargs={'pk': self.topic.pk}) self.comment = Comment( topic=self.topic, # 1. time spent inside "{...}" brackets # 2. estimates of future time needed inside "{?...}" # 3. declared work result - the content of comment text=""" - {1.5},{?0.5} for coming up with basic class structure, - {?2.5} for implementation, - {?13.5} for testing. Here is the result so far: https://github.com/wefindx/infty2.0/commit/9f096dc54f94c31eed9558eb32ef0858f51b1aec """, owner=self.testuser, ) self.comment.save() self.comment_url = reverse( 'comment-detail', kwargs={ 'pk': self.comment.pk }) self.snapshot = self.comment.create_snapshot() self.usd = Currency(label='usd') self.usd.save() self.hprice = HourPriceSnapshot( name='FRED', base=self.usd, data=json.loads(""" {"realtime_start":"2017-07-28","realtime_end":"2017-07-28","observation_start":"1600-01-01","observation_end":"9999-12-31","units":"lin","output_type":1,"file_type":"json","order_by":"observation_date","sort_order":"desc","count":136,"offset":0,"limit":1,"observations":[{"realtime_start":"2017-07-28","realtime_end":"2017-07-28","date":"2017-06-01","value":"26.25"}]}""" ), endpoint= 'https://api.stlouisfed.org/fred/series/observations?series_id=CES0500000003&api_key=0a90ca7b5204b2ed6e998d9f6877187e&limit=1&sort_order=desc&file_type=json', ) self.hprice.save() self.cprice = CurrencyPriceSnapshot( name='FIXER', base=self.usd, data=json.loads(""" {"base":"EUR","date":"2017-07-28","rates":{"AUD":1.4732,"BGN":1.9558,"BRL":3.7015,"CAD":1.4712,"CHF":1.1357,"CNY":7.9087,"CZK":26.048,"DKK":7.4364,"GBP":0.89568,"HKD":9.1613,"HRK":7.412,"HUF":304.93,"IDR":15639.0,"ILS":4.1765,"INR":75.256,"JPY":130.37,"KRW":1317.6,"MXN":20.809,"MYR":5.0229,"NOK":9.3195,"NZD":1.5694,"PHP":59.207,"PLN":4.2493,"RON":4.558,"RUB":69.832,"SEK":9.5355,"SGD":1.5947,"THB":39.146,"TRY":4.1462,"USD":1.1729,"ZAR":15.281}}""" ), endpoint='https://api.fixer.io/latest?base=eur', ) self.cprice.save() self.transaction = Transaction( comment=self.comment, snapshot=self.snapshot, hour_price=self.hprice, currency_price=self.cprice, payment_amount=Decimal(10), payment_currency=self.usd, payment_recipient=self.testuser, payment_sender=self.testuser, hour_unit_cost=(1)) self.transaction.save()