<commit_before>from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse
from mainmodels.models import Category, Course, CourseInCategory
from django.contrib.auth.models import User
# Create your views here.
def createCourse(req):
    if req.method == 'POST':
        try:
            courseName = req.POST['courseName']
            courseCategory = req.POST['courseCategory']
            courseDesc = req.POST['courseDesc']
            courseThumbnail = req.FILES['courseThumbnail']
            coursePrice = req.POST['coursePrice']
            owner = User.objects.get(username='nut')

            newCourse = Course(courseName=courseName, courseDesc=courseDesc,courseThumbnail=courseThumbnail, owner=owner, coursePrice=coursePrice, isDelete=False)
            newCourse.save()

            category = Category.objects.get(categoryID=courseCategory)
            newCourseCategory = CourseInCategory(category=category, course=newCourse)
            newCourseCategory.save()

            return render(req, 'course/createCourse.html', {'courseCategory':courseCategory, 'success': True, 'message': 'Create course successfully.'})
        except:
            return render(req, 'course/createCourse.html', {'courseCategory':courseCategory, 'success': False, 'message': 'Create course failed.'})
    else:
        courseCategory = Category.objects.all()
        return render(req, 'course/createCourse.html', {'courseCategory':courseCategory})
<commit_msg>Remove fixed owner and make loged in user instead<commit_after>from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse
from mainmodels.models import Category, Course, CourseInCategory
# Create your views here.
def createCourse(req):
    if req.method == 'POST':
        try:
            courseName = req.POST['courseName']
            courseCategory = req.POST['courseCategory']
            courseDesc = req.POST['courseDesc']
            courseThumbnail = req.FILES['courseThumbnail']
            coursePrice = req.POST['coursePrice']
            owner = req.user

            newCourse = Course(courseName=courseName, courseDesc=courseDesc,courseThumbnail=courseThumbnail, owner=owner, coursePrice=coursePrice, isDelete=False)
            newCourse.save()

            category = Category.objects.get(categoryID=courseCategory)
            newCourseCategory = CourseInCategory(category=category, course=newCourse)
            newCourseCategory.save()

            return render(req, 'course/createCourse.html', {'courseCategory':courseCategory, 'success': True, 'message': 'Create course successfully.'})
        except:
            return render(req, 'course/createCourse.html', {'courseCategory':courseCategory, 'success': False, 'message': 'Create course failed.'})
    else:
        courseCategory = Category.objects.all()
        return render(req, 'course/createCourse.html', {'courseCategory':courseCategory})

{'fraction_non_alphanumeric': 0.10738482384823848, 'fraction_numerical': 0.0020325203252032522, 'mean_word_length': 3.564142194744977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3986386', 'n_tokens_mistral': 766, 'n_tokens_neox': 735, 'n_words': 170}