Esempio n. 1
0
def post_create_thread(request):
    errors = []
    params = deepValidateAndFetch(request, errors)

    if len(errors) == 0:

        with transaction.atomic():
            thread = Thread(title=params['title'],
                            author=params['author'],
                            section_id=params['section'])

            if params['visibility'] == 'private':
                thread.recipient = params['recipient']

            if params['visibility'] == 'class':
                thread.lesson = params['lesson']

            if params['visibility'] == 'public':
                thread.professor = params['professor']

            thread.save()

            if params['skills_fetched']:
                thread.skills = params['fetched_skills']
                thread.save()

            sendNotification(getWSNotificationForNewThread(thread))

            original_message = Message(
                content=params['content'],
                thread=thread,
                author=params['author'],
                created_date=utc.localize(datetime.now()),
                modified_date=utc.localize(datetime.now()))
            original_message.save()

            sendNotification(getNotificationForNewMessage(original_message))

        return redirect(thread)

    else:
        skills, sections = get_skills(request)
        params['skills'] = skills
        params['sections'] = sections

        if params['skills_fetched']:
            params['selected_skills'] = map(lambda x: x.id,
                                            params['fetched_skills'])
        else:
            params['selected_skills'] = []

        if params['section'] is not None:
            params['selected_section'] = int(params['section'])

        return render(request, "forum/new_thread.haml", {
            "errors": errors,
            "data": params
        })
Esempio n. 2
0
    def reply_to_unanswered_help_request(self, user):
        """ The student who responds is the tutor """
        self.tutor = user
        """ Status shifts to accepted """
        self.state = HelpRequest.ACCEPTED

        """ We create the thread between the two students """
        thread = Thread(title="Aide " + self.student.user.first_name + " par " + user.user.first_name,
                        author=self.student.user, recipient=user.user)
        thread.save()

        thread.skills = Skill.objects.filter(pk__in=self.skill.all())
        thread.save()

        self.thread = thread
        self.save()