def api_index(request): """ If request type is GET, returns 404. If request type is POST, stores posted annotation. """ if request.method == 'POST': #Save comment comment_data = json.loads(request.body) submission_file_pk, user_pk = comment_data['uri'].split("+") submission_file = get_object_or_404( SubmissionFile, pk = submission_file_pk) user = get_object_or_404(User, pk = user_pk) comment = Comment( commenter = user, commented_file = submission_file, selected_text = comment_data['quote'], comment = comment_data['text'] ) comment.save() for ranges in comment_data['ranges']: comment_range = CommentRange( comment = comment, start = ranges['start'], end = ranges['end'], startOffset = int(ranges['startOffset']), endOffset = int(ranges['endOffset']), ) comment_range.save() response = HttpResponse(content="", status=303) response["Location"] = "/app/annotator_api/annotations/" + \ str(comment.id) return response else: return HttpResponse(status=404)
def __create_comments(self): self.comment_1 = Comment() self.comment_1.owner = self.user_mnieber self.comment_1.body = "Thanks for the feedback" self.comment_1.review = self.review_yoga_twist self.comment_1.is_draft = False self.comment_1.save() self.comment_2 = Comment() self.comment_2.owner = self.user_anders_om self.comment_2.body = "I see your point" self.comment_2.review = self.review_yoga_twist self.comment_2.reply_to = self.comment_1 self.comment_2.is_draft = False self.comment_2.save()
def __get_or_create_comment( self, global_user, review, reply_to_comment_id ): draft = review.comments.filter( is_draft=True, owner=global_user, review_id=review.id, reply_to_id=reply_to_comment_id ).first() if not draft: draft = Comment() draft.owner = global_user draft.review = review draft.reply_to_id = reply_to_comment_id draft.save() return draft
def generate_comments(chunk, checkstyle_user, batch): xml = run_checkstyle(chunk.file.path) comment_nodes = find_comment_nodes(xml) ignored = 0 comments = [] for node in comment_nodes: if node.getAttribute('source') in ignored_warnings[chunk.class_type]: ignored += 1 else: comments.append( Comment(type='S', text=node.getAttribute('message'), chunk=chunk, batch=batch, author=checkstyle_user, start=node.getAttribute('line'), end=node.getAttribute('line'))) print "checkstyle: on", chunk.name, 'I made', len( comments), 'comments and ignored', ignored, 'minor problems' return comments
def generate_comments(chunk, checkstyle_user, batch, suppress_comment_regexes): xml = run_checkstyle(chunk.file.path) comment_nodes = find_comment_nodes(xml) ignored = 0 comments = [] for node in comment_nodes: message = node.getAttribute('message') line = node.getAttribute('line') checkstyleModule = node.getAttribute('source') if checkstyleModule in ignored_warnings[chunk.class_type] or matchesAny(suppress_comment_regexes, chunk.file.path + ':' + message): ignored += 1 else: comments.append(Comment( type='S', text=message, chunk=chunk, batch=batch, author=checkstyle_user, start=line, end=line)) print "checkstyle: on", chunk.name, 'I made', len(comments), 'comments and ignored', ignored, 'minor problems' return comments
def add(request): name = request.POST['name'] comment = request.POST['comment'] Comment(name=name, comment=comment).save() return HttpResponseRedirect('/review/insert')
def reset_test_database(request): # pragma: no cover """ Loads a database with fake data for testing. """ # Clear Celery tasks discard_all() # Delete Submissions for root, dirs, files in os.walk('submissions'): for f in files: os.unlink(os.path.join(root, f)) for d in dirs: shutil.rmtree(os.path.join(root, d)) # Delete current database Submission.objects.all().delete() SubmissionFile.objects.all().delete() Course.objects.all().delete() Assignment.objects.all().delete() AssignedReview.objects.all().delete() Comment.objects.all().delete() CommentRange.objects.all().delete() EmailPreferences.objects.all().delete() Question.objects.all().delete() Response.objects.all().delete() ### FOR MAURICIOS INDIVIDUAL PROJECT Faq.objects.all().delete() ################ now = timezone.now() just_before = timezone.now() - datetime.timedelta(seconds=10) before = timezone.now() - datetime.timedelta(days=1) long_before = timezone.now() - datetime.timedelta(days=30) just_after = timezone.now() + datetime.timedelta(seconds=30) after = timezone.now() + datetime.timedelta(days=1) long_after = timezone.now() + datetime.timedelta(days=30) #Deal with users if len(User.objects.all()) <= 1: user1 = User(username="******") user1.set_password('user1') user1.save() user2 = User(username="******") user2.set_password('user2') user2.save() user3 = User(username="******") user3.set_password('user3') user3.save() user4 = User(username="******") user4.set_password('user4') user4.save() else: user1 = User.objects.filter(username="******")[0] user2 = User.objects.filter(username="******")[0] user3 = User.objects.filter(username="******")[0] user4 = User.objects.filter(username="******")[0] user1prefs = EmailPreferences(user=user1, on_day_before_due=True, on_due_date=True) user1prefs.save() user2prefs = EmailPreferences(user=user2) user2prefs.save() user3prefs = EmailPreferences(user=user3) user3prefs.save() user4prefs = EmailPreferences(user=user4) user4prefs.save() course = Course(course_name="Test Course", course_code="TEST1000", course_id="201402TEST1000", year=2014, semester='2', institution="UQ") course.save() a1 = Assignment( assignment_id="ass01", name="Assignment 1", create_date=long_before, modified_date=long_before, open_date=long_before, due_date=just_before, description="This is assignment 1. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", description_raw="This is assignment 1. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", allow_multiple_uploads=True, allow_help_centre=True, number_of_peer_reviews=3, review_open_date=just_before, review_due_date=after, weighting=20, test_zip="", dockerfile="", docker_command="", test_required=False ) a1.save() a1.set_async() print "a1 created" a2 = Assignment( assignment_id="ass02", name="Assignment 2", create_date=before, modified_date=before, open_date=before, due_date=just_after, description="This is assignment 2. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", description_raw="This is assignment 2. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", allow_multiple_uploads=True, allow_help_centre=True, number_of_peer_reviews=3, review_open_date=just_after, review_due_date=long_after, weighting=20, test_zip="", dockerfile="", docker_command="", test_required=False ) a2.save() a2.set_async() print "a2 created" a3 = Assignment( assignment_id="ass03", name="Assignment 3", create_date=now, modified_date=now, open_date=just_after, due_date=long_after, description="This is assignment 3. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", description_raw="This is assignment 3. Bacon ipsum dolor sit amet short loin jowl swine, drumstick hamburger meatball prosciutto frankfurter chuck. Shank sausage doner meatball shankle flank, t-bone venison turkey jerky bacon strip steak ribeye chicken pastrami. Capicola ground round corned beef turducken frankfurter. Jowl landjaeger bacon, sausage frankfurter meatball rump bresaola strip steak fatback short loin jerky pancetta turducken.", allow_multiple_uploads=True, allow_help_centre=True, number_of_peer_reviews=3, review_open_date=long_after, review_due_date=long_after, weighting=20, test_zip="testing/test.zip", dockerfile="testing/Dockerfile", docker_command="python /opt/testing/test.py", test_required=False ) a3.save() a3.set_async() print "a3 created" ## Prev assignment w/ review submission0 = Submission( user = user1, assignment = a1, upload_date = before, upload_path = "codereview/test_submission/0/", has_been_submitted = True, unviewed_reviews = 1 ) submission0.save() submission0b = Submission( user = user2, assignment = a1, upload_date = before, upload_path = "codereview/test_submission/0/", has_been_submitted = True, unviewed_reviews = 1 ) submission0b.save() sf0 = SubmissionFile(submission=submission0, file_path="test.py") sf0.save() sf0b = SubmissionFile(submission=submission0b, file_path="test.py") sf0b.save() assigned_review = AssignedReview(assigned_user=user2, assigned_submission=submission0, has_been_reviewed=True) assigned_review.save() assigned_review2 = AssignedReview(assigned_user=user1, assigned_submission=submission0b, has_been_reviewed=False) assigned_review2.save() comment = Comment(commenter=user2, commented_file=sf0, comment="You probably shouldn't hard code the IP address.", selected_text='mpd_client.connect("192.168.1.4", 6600)') comment.save() comment_range = CommentRange(comment=comment, start='', end='',startOffset=195, endOffset=234) comment_range.save() assigned_review3 = AssignedReview(assigned_user=user3, assigned_submission=submission0, has_been_reviewed=True) assigned_review3.save() comment2 = Comment(commenter=user3, commented_file=sf0, comment="This function doesn't cover all possibilities and will return None. You should probably find a better way to implement it.", selected_text='def parse_command(text):') comment2.save() comment_range2 = CommentRange(comment=comment2, start='', end='',startOffset=521, endOffset=725) comment_range2.save() submission1 = Submission( user = user2, assignment = a2, upload_date = just_before, upload_path = "codereview/test_submission/1/", has_been_submitted = True, unviewed_reviews = 0 ) submission1.save() sf1 = SubmissionFile(submission=submission1, file_path="email.py") sf1.save() submission2 = Submission( user = user3, assignment = a2, upload_date = just_before, upload_path = "codereview/test_submission/2/", has_been_submitted = True, unviewed_reviews = 0 ) submission2.save() sf2 = SubmissionFile(submission=submission2, file_path="email.py") sf2.save() submission3 = Submission( user = user4, assignment = a2, upload_date = just_before, upload_path = "codereview/test_submission/3/", has_been_submitted = True, unviewed_reviews = 0 ) submission3.save() sf3 = SubmissionFile(submission=submission3, file_path="email.py") sf3.save() question1 = Question( user = user4, title = "Why is the sky blue?", text = "Tell me why.", text_raw = "Tell me why.", create_date = long_before, modified_date = just_before, ) question1.save() question2 = Question( user = user4, title = "Why did the chicken cross the road?", text = "Bacon ipsum dolor sit amet short loin jowl swine.", text_raw = "Bacon ipsum dolor sit amet short loin jowl swine.", create_date = long_before, modified_date = long_before, ) question2.save() answer1 = Response( user = user2, question = question2, text = "Just because.", text_raw = "Just because.", create_date = before, modified_date = before, ) answer1.save() answer2 = Response( user = user2, question = question2, text = "Egg.", text_raw = "Egg.", create_date = before, modified_date = before, ) answer2.save() ## FOR MAURICIOS INDIVIDUAL PROJECT faq1 = Faq( title="This is a frequently asked question.", text = "Stop asking it dummy!", text_raw = "Stop asking it dummy!", ) faq1.save() ####### return redirect('index')
class Command(BaseCommand): help = \ 'Populates the database with example suggestions' def add_arguments(self, parser): pass def __migrate(self): if settings.DATABASES['default']['NAME'] == ":memory:": management.call_command('migrate', '--run-syncdb') else: management.call_command('migrate', '--run-syncdb') management.call_command( 'makemigrations', 'goal', 'suggestion', 'review') management.call_command('migrate', '--fake-initial') def __make_global_user(self, username, password, first_name, last_name): user = User.objects.get_or_create(username=username)[0] user.set_password(password) user.first_name = first_name user.last_name = last_name user.save() global_user = GlobalUser() global_user.user = user global_user.save() return global_user def __create_superuser(self): management.call_command( 'createsuperuser', '--noinput', username='******', email='*****@*****.**' ) self.user_mnieber = self.__make_global_user( 'mnieber', '***REMOVED***', 'Maarten', 'Nieber') def __create_users(self): self.user_anders_om = self.__make_global_user( "andersom", "***REMOVED***", "Anders", "Om") self.user_marie_houana = self.__make_global_user( "mhouana", "***REMOVED***", "Maria", "Houana") def __create_goal(self): self.become_a_yogi = Goal() self.become_a_yogi.owner = self.user_marie_houana self.become_a_yogi.title = "Become a yogi" self.become_a_yogi.is_draft = False self.become_a_yogi.save() def __create_members(self): self.yogi_mnieber = Member() self.yogi_mnieber.global_user = self.user_mnieber self.yogi_mnieber.goal = self.become_a_yogi self.yogi_mnieber.save() self.yogi_anders_om = Member() self.yogi_anders_om.global_user = self.user_anders_om self.yogi_anders_om.goal = self.become_a_yogi self.yogi_anders_om.save() self.yogi_marie_houana = Member() self.yogi_marie_houana.global_user = self.user_marie_houana self.yogi_marie_houana.goal = self.become_a_yogi self.yogi_marie_houana.save() def __create_suggestions(self): self.yoga_bend = Suggestion() self.yoga_bend.goal = self.become_a_yogi self.yoga_bend.owner = self.user_mnieber self.yoga_bend.is_draft = False self.yoga_bend.image = "suggestions/KroukTom-710x300-crop.jpg" self.yoga_bend.slug = "bend-backwards" self.yoga_bend.save() yoga_bend = Revision() yoga_bend.title = "Bend backwards" yoga_bend.description = yoga_bend_content yoga_bend.suggestion = self.yoga_bend yoga_bend.save() self.yoga_meditate = Suggestion() self.yoga_meditate.goal = self.become_a_yogi self.yoga_meditate.owner = self.user_mnieber self.yoga_meditate.is_draft = False self.yoga_meditate.image = "suggestions/Yoga_Nidra.jpg" self.yoga_meditate.slug = "meditate-often" self.yoga_meditate.save() yoga_meditate = Revision() yoga_meditate.title = "Meditate often" yoga_meditate.description = yoga_meditate_content yoga_meditate.suggestion = self.yoga_meditate yoga_meditate.save() self.yoga_twist = Suggestion() self.yoga_twist.goal = self.become_a_yogi self.yoga_twist.owner = self.user_anders_om self.yoga_twist.is_draft = False self.yoga_twist.image = "suggestions/MC_AM06_00_sized2.jpg" self.yoga_twist.slug = "keep-twisting" self.yoga_twist.save() self.rev_yoga_twist = Revision() self.rev_yoga_twist.title = "Keep twisting" self.rev_yoga_twist.description = yoga_twist_content self.rev_yoga_twist.suggestion = self.yoga_twist self.rev_yoga_twist.save() time.sleep(1) self.rev_yoga_twist_2 = Revision() self.rev_yoga_twist_2.title = "Keep twisting" self.rev_yoga_twist_2.description = yoga_twist_2_content self.rev_yoga_twist_2.suggestion = self.yoga_twist self.rev_yoga_twist_2.save() self.yoga_acrobatics = Suggestion() self.yoga_acrobatics.goal = self.become_a_yogi self.yoga_acrobatics.owner = self.user_marie_houana self.yoga_acrobatics.is_draft = False self.yoga_acrobatics.image = "suggestions/yoga-acrobats.jpg" self.yoga_acrobatics.slug = "yoga-acrobatics" self.yoga_acrobatics.save() yoga_acrobatics = Revision() yoga_acrobatics.title = "Acrobatics" yoga_acrobatics.description = yoga_acrobatics_content yoga_acrobatics.suggestion = self.yoga_acrobatics yoga_acrobatics.save() def __create_reviews(self): self.review_yoga_twist = Review() self.review_yoga_twist.owner = self.user_marie_houana self.review_yoga_twist.revision = self.rev_yoga_twist self.review_yoga_twist.rating = 2.5 self.review_yoga_twist.description = "Not bad!" self.review_yoga_twist.is_draft = False self.review_yoga_twist.save() self.review_yoga_twist_2 = Review() self.review_yoga_twist_2.owner = self.user_mnieber self.review_yoga_twist_2.revision = self.rev_yoga_twist_2 self.review_yoga_twist_2.rating = 4 self.review_yoga_twist_2.description = "Good, good, good" self.review_yoga_twist_2.is_draft = False self.review_yoga_twist_2.save() def __create_comments(self): self.comment_1 = Comment() self.comment_1.owner = self.user_mnieber self.comment_1.body = "Thanks for the feedback" self.comment_1.review = self.review_yoga_twist self.comment_1.is_draft = False self.comment_1.save() self.comment_2 = Comment() self.comment_2.owner = self.user_anders_om self.comment_2.body = "I see your point" self.comment_2.review = self.review_yoga_twist self.comment_2.reply_to = self.comment_1 self.comment_2.is_draft = False self.comment_2.save() def handle(self, *args, **options): management.call_command('initdb') self.__migrate() self.__create_superuser() self.__create_users() self.__create_goal() self.__create_members() self.__create_suggestions() self.__create_reviews() self.__create_comments()
class Command(BaseCommand): help = ( 'Populates the database with example suggestions' ) def add_arguments(self, parser): pass def __migrate(self): if settings.DATABASES['default']['NAME'] == ":memory:": management.call_command('migrate', '--run-syncdb') else: management.call_command('migrate', '--run-syncdb') management.call_command( 'makemigrations', 'goal', 'suggestion', 'review') management.call_command('migrate', '--fake-initial') def __make_global_user(self, username, password, first_name, last_name): user = User.objects.get_or_create(username=username)[0] user.set_password(password) user.first_name = first_name user.last_name = last_name user.save() global_user = GlobalUser() global_user.user = user global_user.save() return global_user def __create_superuser(self): management.call_command( 'createsuperuser', '--noinput', username='******', email='*****@*****.**' ) self.user_mnieber = self.__make_global_user( 'mnieber', '***REMOVED***', 'Maarten', 'Nieber') def __create_users(self): self.user_anders_om = self.__make_global_user( "andersom", "***REMOVED***", "Anders", "Om") self.user_marie_houana = self.__make_global_user( "mhouana", "***REMOVED***", "Maria", "Houana") def __create_goal(self): self.become_a_yogi = Goal() self.become_a_yogi.owner = self.user_marie_houana self.become_a_yogi.title = "Become a yogi" self.become_a_yogi.is_draft = False self.become_a_yogi.save() def __create_members(self): self.yogi_mnieber = Member() self.yogi_mnieber.global_user = self.user_mnieber self.yogi_mnieber.goal = self.become_a_yogi self.yogi_mnieber.save() self.yogi_anders_om = Member() self.yogi_anders_om.global_user = self.user_anders_om self.yogi_anders_om.goal = self.become_a_yogi self.yogi_anders_om.save() self.yogi_marie_houana = Member() self.yogi_marie_houana.global_user = self.user_marie_houana self.yogi_marie_houana.goal = self.become_a_yogi self.yogi_marie_houana.save() def __create_suggestions(self): self.yoga_bend = Suggestion() self.yoga_bend.goal = self.become_a_yogi self.yoga_bend.owner = self.user_mnieber self.yoga_bend.is_draft = False self.yoga_bend.image = "suggestions/KroukTom-710x300-crop.jpg" self.yoga_bend.slug = "bend-backwards" self.yoga_bend.save() yoga_bend = Revision() yoga_bend.title = "Bend backwards" yoga_bend.description = yoga_bend_content yoga_bend.suggestion = self.yoga_bend yoga_bend.save() self.yoga_meditate = Suggestion() self.yoga_meditate.goal = self.become_a_yogi self.yoga_meditate.owner = self.user_mnieber self.yoga_meditate.is_draft = False self.yoga_meditate.image = "suggestions/Yoga_Nidra.jpg" self.yoga_meditate.slug = "meditate-often" self.yoga_meditate.save() yoga_meditate = Revision() yoga_meditate.title = "Meditate often" yoga_meditate.description = yoga_meditate_content yoga_meditate.suggestion = self.yoga_meditate yoga_meditate.save() self.yoga_twist = Suggestion() self.yoga_twist.goal = self.become_a_yogi self.yoga_twist.owner = self.user_anders_om self.yoga_twist.is_draft = False self.yoga_twist.image = "suggestions/MC_AM06_00_sized2.jpg" self.yoga_twist.slug = "keep-twisting" self.yoga_twist.save() self.rev_yoga_twist = Revision() self.rev_yoga_twist.title = "Keep twisting" self.rev_yoga_twist.description = yoga_twist_content self.rev_yoga_twist.suggestion = self.yoga_twist self.rev_yoga_twist.save() time.sleep(1) self.rev_yoga_twist_2 = Revision() self.rev_yoga_twist_2.title = "Keep twisting" self.rev_yoga_twist_2.description = yoga_twist_2_content self.rev_yoga_twist_2.suggestion = self.yoga_twist self.rev_yoga_twist_2.save() self.yoga_acrobatics = Suggestion() self.yoga_acrobatics.goal = self.become_a_yogi self.yoga_acrobatics.owner = self.user_marie_houana self.yoga_acrobatics.is_draft = False self.yoga_acrobatics.image = "suggestions/yoga-acrobats.jpg" self.yoga_acrobatics.slug = "yoga-acrobatics" self.yoga_acrobatics.save() yoga_acrobatics = Revision() yoga_acrobatics.title = "Acrobatics" yoga_acrobatics.description = yoga_acrobatics_content yoga_acrobatics.suggestion = self.yoga_acrobatics yoga_acrobatics.save() def __create_reviews(self): self.review_yoga_twist = Review() self.review_yoga_twist.owner = self.user_marie_houana self.review_yoga_twist.revision = self.rev_yoga_twist self.review_yoga_twist.rating = 2.5 self.review_yoga_twist.description = "Not bad!" self.review_yoga_twist.is_draft = False self.review_yoga_twist.save() self.review_yoga_twist_2 = Review() self.review_yoga_twist_2.owner = self.user_mnieber self.review_yoga_twist_2.revision = self.rev_yoga_twist_2 self.review_yoga_twist_2.rating = 4 self.review_yoga_twist_2.description = "Good, good, good" self.review_yoga_twist_2.is_draft = False self.review_yoga_twist_2.save() def __create_comments(self): self.comment_1 = Comment() self.comment_1.owner = self.user_mnieber self.comment_1.body = "Thanks for the feedback" self.comment_1.review = self.review_yoga_twist self.comment_1.is_draft = False self.comment_1.save() self.comment_2 = Comment() self.comment_2.owner = self.user_anders_om self.comment_2.body = "I see your point" self.comment_2.review = self.review_yoga_twist self.comment_2.reply_to = self.comment_1 self.comment_2.is_draft = False self.comment_2.save() def handle(self, *args, **options): management.call_command('initdb') self.__migrate() self.__create_superuser() self.__create_users() self.__create_goal() self.__create_members() self.__create_suggestions() self.__create_reviews() self.__create_comments()