Exemplo n.º 1
0
def create_question(request):
    if request.method == 'POST':
        form = CreateQuestion(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            question = cd['question']
            tags = cd ['tags']
            question_tlt = cd['question_title'] 
            q = Question(question_text=question, question_title=question_tlt,pub_date=timezone.now(), creator=request.user, tags_list=tags)
            q.save()
            
            for t in tags.split(','):
                if len(t) > 0:
                    try:
                        print "Text : " + t
                        print len(t)
                        my_tag = Tags.objects.get(tag_text=t)
                    except (KeyError, Tags.DoesNotExist):
                        tag_create = Tags(tag_text=t)
                        tag_create.save()
                        q.tags.add(tag_create)
                    else:
                        q.tags.add(my_tag)
            
            return HttpResponseRedirect('/forum/')
    else:
        form = CreateQuestion()
    return render(request, 'forum/create_question.html', {'form': form})
Exemplo n.º 2
0
def test_question_form(user):
    from forum.forms import QuestionForm
    from forum.models import Question

    instance = Question()
    instance.course = mommy.make('Course', slug='dbsql')
    instance.user = user

    data = {
        'title': 'Test Title',
        'text': 'asljf asdfhuas dfasdflashfdlusafdlsafdlsa filasdflisalfdiayslfdnsalfdyaslifd',
    }

    form = QuestionForm(instance=instance, data=data)
    assert form.is_valid() is True, form.errors
    form.save()
    assert Question.objects.filter(slug='test-title').exists()

    data = {
        'title': '',
        'text': 'asljf asdfhuas dfasdflashfdlusafdlsafdlsa filasdflisalfdiayslfdnsalfdyaslifd',
    }
    form = QuestionForm(data=data)
    assert form.is_valid() is False

    data = {
        'title': 'Test Title',
        'text': '',
    }
    form = QuestionForm(data=data)
    assert form.is_valid() is False
Exemplo n.º 3
0
    def process_data(self, **data):
        processed_data = self.create_revision_data(True, **data)
        if 'added_at' in data:
            processed_data['added_at'] = data['added_at']

        question = Question(author=self.user, **processed_data)
        question.save()
        self.node = question
Exemplo n.º 4
0
    def process_data(self, **data):
        processed_data = self.create_revision_data(True, **data)
        if 'added_at' in data:
            processed_data['added_at'] = data['added_at']

        question = Question(author=self.user, **processed_data)
        question.save()
        self.node = question

        messages.info(REQUEST_HOLDER.request, self.describe(self.user))
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     new_question = Question()
     course = get_object_or_404(Course, slug=self.kwargs['course_slug'])
     new_question.course = course
     new_question.user = request.user
     form = QuestionForm(instance=new_question, **self.get_form_kwargs())
     if form.is_valid():
         form.save()
         self.success_url = reverse_lazy('forum_question', kwargs={'slug': new_question.slug})
         return self.form_valid(form)
     else:
         return self.form_invalid(form)
Exemplo n.º 6
0
    def test_basic_addition(self):
        user = User.objects.all()[0]
        point = Point()
        point.fromuser = user
        point.save()

        question = Question();
        question.user = user
        question.title = "hi"
        question.slug = 'something'
        question.text = 'else'
        question.save()
        question.points.add(point)
        question.save()
        
        self.assertEquals(1, question.total_points())
Exemplo n.º 7
0
    def process_data(self, **data):
        processed_data = self.create_revision_data(True, **data)
        if 'added_at' in data:
            processed_data['added_at'] = data['added_at']

        question = Question(author=self.user, **processed_data)
        question.save()
        self.node = question

        makers = list(data['maker'])

        # Add makers
        for maker in data['maker']:
            if not (PromiseMaker.objects.filter(maker=maker,promise=question).exists()):
                temp = PromiseMaker(maker=maker,promise=question)
                temp.save()

        # Delete removed makers
        for pm in PromiseMaker.objects.filter(promise=question):
            if not (pm.maker in makers):
                maker.delete()
Exemplo n.º 8
0
def add_question(request):
    group_id = request.POST.get('group_id', False);
    #attempt to create question using parameters from POST
    try:
        q = Question(
            question_text=request.POST['question'], 
			body = request.POST['body'],
			pub_date=timezone.now(),
			user=request.user,
			subject=request.POST['subject']
            )
        if group_id:
            q.group = Group.objects.get(pk=group_id)
    except(KeyError, Question.DoesNotExist):
        return render(request, 'forum/index', {'error_message': "Question must not be empty!"})
    else:
	#allow for insertion of HTML in questions
        q.body = q.body.replace("\n", "<br/>")
        q.body = q.body.replace(" ", "&nbsp;")
        q.save()
        if group_id:
            return HttpResponseRedirect(reverse('groups:detail', args=(group_id)))
        return HttpResponseRedirect(reverse('forum:index'))
Exemplo n.º 9
0
    def test_user_points(self):
        josh = User.objects.all()[0]

        question = Question();
        question.user = josh
        question.title = "hi"
        question.slug = 'something'
        question.text = 'else'
        question.save()

        point = Point()
        point.fromuser = josh
        point.save()
        question.points.add(point)

        user = User()
        user.save()
        point = Point()
        point.fromuser = user
        point.save()
        question.points.add(point)

        self.assertEquals(2, userPoint(josh))
Exemplo n.º 10
0
    def test_add_point_to_question(self):
        self.client.login(username='josh', password='asxdfv')
        user = User.objects.all()[0]

        question = Question();
        question.user = user
        question.title = "hi"
        question.slug = 'something'
        question.text = 'else'
        question.save()

        response = self.client.post('/ajax/forum/upvote_question.json', {'question_pk': question.pk})
        json_response = json.loads(response.content)
        self.assertTrue(json_response['success'])
        self.assertTrue(json_response['data']['delta'], 1)
        self.assertEquals(1, Question.objects.all().count())
        
        response = self.client.post('/ajax/forum/upvote_question.json', {'question_pk': question.pk})
        json_response = json.loads(response.content)
        self.assertTrue(json_response['success'])
        self.assertTrue(json_response['data']['delta'], -1)
        print Point.objects.all()
        self.assertEquals(0, Point.objects.all().count())
Exemplo n.º 11
0
 def process_data(self, **data):
     question = Question(author=self.user, **self.create_revision_data(True, **data))
     question.save()
     self.node = question
Exemplo n.º 12
0
from forum.models import Question
from django.conf import settings
from djangosphinx.manager import SphinxSearch

from djangosphinx.models import SphinxSearch

Question.add_to_class("search", SphinxSearch(index=" ".join(settings.SPHINX_SEARCH_INDICES), mode="SPH_MATCH_ALL"))
Exemplo n.º 13
0
### -*- coding: utf-8 -*- ##

from django.db import models
from django.utils.translation import ugettext_lazy as _

from muaccounts.models import MUAccount
from forum.models import Question, Answer

Question.add_to_class('muaccount', models.ForeignKey(MUAccount, related_name="questions"))
Question.add_to_class('bounty_points', models.PositiveIntegerField(_('bounty points'), default=0))

class PointAward(models.Model):
    date = models.DateTimeField(auto_now_add=True)
    answer = models.OneToOneField(Answer, related_name='point_award')
    points = models.PositiveIntegerField(default=0)
    
    class Meta:
        ordering = ('-date',)
Exemplo n.º 14
0
from forum.models import Question
from django.conf import settings

from djangosphinx.models import SphinxSearch

Question.add_to_class('search', SphinxSearch(
                                   index=' '.join(settings.SPHINX_SEARCH_INDICES),
                                   mode='SPH_MATCH_BOOLEAN',
                                )
                      )