예제 #1
0
    def setUp(self):
        self.offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
        self.offering.set_discussion(True)
        self.offering.save()
        members = Member.objects.filter(offering=self.offering).exclude(
            role='DROP').exclude(person__userid__isnull=True)
        members = list(members)

        # create a bunch of discussion
        for i in range(25):
            t = DiscussionTopic(offering=self.offering,
                                title='Topic ' + str(i),
                                content='Content ' + str(i),
                                author=random.choice(members))
            t.save()
            m = DiscussionMessage(topic=t,
                                  content='**Content** A' + str(i),
                                  author=random.choice(members))
            m.save()
            m = DiscussionMessage(topic=t,
                                  content='//Content// B' + str(i),
                                  author=random.choice(members))
            m.save()

        self.topic = t
        self.message = m
예제 #2
0
def create_topic(request, course_slug):
    """
    Form to create a new discussion topic
    """
    course, view = _get_course_and_view(request, course_slug)
    if view is None:
        # course is an HttpResponse in this case
        return course
    if request.method == 'POST':
        creole = DiscussionTopic(offering=course).get_creole()
        form = discussion_topic_form_factory(view,
                                             data=request.POST,
                                             creole=creole)
        if form.is_valid():
            topic = form.save(commit=False)
            topic.offering = course
            topic.author = _get_member(request.user.username, view,
                                       course_slug)
            topic.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Discussion topic created successfully.')
            return HttpResponseRedirect(
                reverse('discuss.views.view_topic',
                        kwargs={
                            'course_slug': course_slug,
                            'topic_slug': topic.slug
                        }))
    else:
        form = discussion_topic_form_factory(view, creole=None)
    return render(request, 'discuss/create_topic.html', {
        'course': course,
        'form': form
    })
예제 #3
0
 def setUp(self):
     self.offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
     self.offering.set_discussion(True)
     self.offering.save()
     members = Member.objects.filter(offering=self.offering).exclude(role='DROP').exclude(person__userid__isnull=True)
     members = list(members)
     
     # create a bunch of discussion
     for i in range(25):
         t = DiscussionTopic(offering=self.offering, title='Topic '+str(i), content='Content '+str(i),
                             author=random.choice(members))
         t.save()
         m = DiscussionMessage(topic=t, content='**Content** A'+str(i), author=random.choice(members))
         m.save()
         m = DiscussionMessage(topic=t, content='//Content// B'+str(i), author=random.choice(members))
         m.save()
     
     self.topic = t
     self.message = m
예제 #4
0
def create_discussion():
    """
    Test data for discussion
    """
    from discuss.models import DiscussionTopic, DiscussionMessage
    offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
    members = list(Member.objects.filter(offering=offering, role='STUD'))
    random.shuffle(members)

    m = members.pop()
    t1 = DiscussionTopic(offering=offering, title='Discussion One', author=m,
                         content='//Hello classmates//.\n\nWe have **many** things to discuss.')
    t1.set_markup('creole')
    t1.save()

    m = members.pop()
    t2 = DiscussionTopic(offering=offering, title='Discussion Two', author=m,
                         content="I *really* can't figure out if \\\\(x+1=y\\\\).")
    t2.set_markup('markdown')
    t2.set_math(True)
    t2.save()

    m = members.pop()
    m1 = DiscussionMessage(topic=t1, content='Hello, friend.', author=m)
    m1.save()

    m = members.pop()
    m2 = DiscussionMessage(topic=t1, author=m, content='''Run this program:\n```python\nfor i in range(2):\n    print(i)\n````''')
    m2.set_markup('markdown')
    m2.save()

    return itertools.chain(
        DiscussionTopic.objects.all(),
        DiscussionMessage.objects.all()
    )