Beispiel #1
0
    def test_vocabulary_render_one(self):
        request = HttpRequest()
        request.course = self.sample_course

        vocabulary = Vocabulary.objects.get(name="shapes")
        detail = VocabularyResource().render_one(request, vocabulary)
        self.assertEquals(detail['display_name'], "Shapes")
        self.assertEquals(len(detail['term_set']), 2)
Beispiel #2
0
    def get_tags_and_terms(self, request, assets):
        notes = SherdNote.objects.get_related_notes(assets, self.record_owner
                                                    or None,
                                                    self.visible_authors,
                                                    self.all_items_are_visible)

        tags = TagResource().render_for_course(request, notes)
        vocab = VocabularyResource().render_for_course(request, notes)
        return {'active_tags': tags, 'active_vocabulary': vocab}
Beispiel #3
0
    def add_metadata(self, request, assets):
        # metadata for all notes associated with these assets
        # is displayed in the filtered list.
        notes = SherdNote.objects.get_related_notes(
            assets, self.record_owner or None, self.visible_authors,
            self.all_items_are_visible)

        tags = TagResource().render_for_course(request, notes)
        vocab = VocabularyResource().render_for_course(request, notes)
        return {'active_tags': tags, 'active_vocabulary': vocab}
Beispiel #4
0
    def get(self, request, asset_id=None, annot_id=None):

        if asset_id:
            try:
                asset = Asset.objects.get(pk=asset_id, course=request.course)
                asset.primary
            except Asset.DoesNotExist:
                return asset_switch_course(request, asset_id)
            except Source.DoesNotExist:
                ctx = RequestContext(request)
                return render_to_response('500.html', {}, context_instance=ctx)

        data = {'asset_id': asset_id, 'annotation_id': annot_id}

        if not request.is_ajax():
            return render_to_response('assetmgr/asset_workspace.html',
                                      data,
                                      context_instance=RequestContext(request))
        context = {'type': 'asset'}
        if asset_id:
            # @todo - refactor this context out of the mix
            # ideally, the client would simply request the json
            # the mixin is expecting a queryset, so this becomes awkward here
            self.record_owner = request.user
            assets = Asset.objects.filter(pk=asset_id)
            (assets, notes) = self.visible_assets_and_notes(request, assets)
            context['assets'] = {
                asset.pk: AssetResource().render_one(request, asset, notes)
            }

            help_setting = UserSetting.get_setting(request.user,
                                                   "help_item_detail_view",
                                                   True)
            context['user_settings'] = {'help_item_detail_view': help_setting}

        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

        user_resource = UserResource()
        owners = user_resource.render_list(request, request.course.members)

        data['panels'] = [{
            'panel_state': 'open',
            'panel_state_label': "Annotate Media",
            'context': context,
            'owners': owners,
            'vocabulary': vocabulary,
            'template': 'asset_workspace',
            'current_asset': asset_id,
            'current_annotation': annot_id,
            'update_history': True,
            'show_collection': True
        }]

        return self.render_to_json_response(data)
Beispiel #5
0
    def add_metadata(self, request, assets):
        # metadata for all notes associated with these assets
        # is displayed in the filtered list.
        # Not sure this is exactly right...will discuss with team
        notes = SherdNote.objects.get_related_notes(assets, self.record_owner
                                                    or None,
                                                    self.visible_authors)

        tags = TagResource().render_related(request, notes)
        vocab = VocabularyResource().render_related(request, notes)
        return {'active_tags': tags, 'active_vocabulary': vocab}
Beispiel #6
0
    def test_vocabulary_render_list(self):
        request = HttpRequest()
        request.course = self.sample_course
        qs = Vocabulary.objects.filter(course=request.course)

        lst = VocabularyResource().render_list(request, qs)

        self.assertEquals(len(lst), 2)
        self.assertEquals(lst[0]['display_name'], "Colors")
        self.assertEquals(len(lst[0]['term_set']), 3)
        self.assertEquals(lst[1]['display_name'], "Shapes")
        self.assertEquals(len(lst[1]['term_set']), 2)
Beispiel #7
0
def asset_workspace(request, asset_id=None, annot_id=None):
    if not request.user.is_staff:
        in_course_or_404(request.user.username, request.course)

    if asset_id:
        try:
            asset = Asset.objects.get(pk=asset_id, course=request.course)
            asset.primary
        except Asset.DoesNotExist:
            return asset_switch_course(request, asset_id)
        except Source.DoesNotExist:
            response = direct_to_template(request, "500.html", {})
            response.status_code = 500
            return response

    data = {
        'space_owner': request.user.username,
        'asset_id': asset_id,
        'annotation_id': annot_id
    }

    if not request.is_ajax():
        return render_to_response('assetmgr/asset_workspace.html',
                                  data,
                                  context_instance=RequestContext(request))
    elif asset_id:
        # @todo - refactor this context out of the mix
        # ideally, the client would simply request the json
        context = detail_asset_json(request, asset)
    else:
        context = {'type': 'asset'}

    vocabulary = VocabularyResource().render_list(
        request, Vocabulary.objects.get_for_object(request.course))

    user_resource = UserResource()
    owners = user_resource.render_list(request, request.course.members)

    data['panels'] = [{
        'panel_state': 'open',
        'panel_state_label': "Annotate Media",
        'context': context,
        'owners': owners,
        'vocabulary': vocabulary,
        'template': 'asset_workspace',
        'current_asset': asset_id,
        'current_annotation': annot_id,
        'update_history': True,
        'show_collection': True,
    }]

    return HttpResponse(simplejson.dumps(data, indent=2),
                        mimetype='application/json')
Beispiel #8
0
    def test_vocabulary_render_list(self):
        course = Course.objects.get(title="Sample Course")
        request = HttpRequest()
        request.course = course

        lst = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

        self.assertEquals(len(lst), 2)
        self.assertEquals(lst[0]['display_name'], "Colors")
        self.assertEquals(len(lst[0]['term_set']), 3)
        self.assertEquals(lst[1]['display_name'], "Shapes")
        self.assertEquals(len(lst[1]['term_set']), 2)
Beispiel #9
0
    def test_vocabulary_authorization(self):
        factory = RequestFactory()
        request = factory.get('')
        request.course = self.sample_course
        request.user = User.objects.get(username='******')

        vocabulary = Vocabulary.objects.all()
        authorization = VocabularyAuthorization()

        bundle = VocabularyResource().build_bundle(obj=vocabulary,
                                                   request=request)

        lst = authorization.read_list(vocabulary, bundle)
        self.assertEquals(len(lst), 2)
Beispiel #10
0
    def test_vocabulary_render_related_multiple(self):
        request = HttpRequest()
        request.course = self.sample_course

        notes = SherdNote.objects.filter(title__in=['Left Corner', 'Nice Tie'])
        ctx = VocabularyResource().render_related(request, notes)

        self.assertEquals(len(ctx), 2)
        self.assertEquals(ctx[0]['display_name'], 'Colors')
        self.assertEquals(len(ctx[0]['term_set']), 1)
        self.assertEquals(ctx[0]['term_set'][0]['display_name'], 'Red')
        self.assertEquals(ctx[0]['term_set'][0]['count'], 1)

        self.assertEquals(ctx[1]['display_name'], 'Shapes')
        self.assertEquals(len(ctx[1]['term_set']), 1)
        self.assertEquals(ctx[1]['term_set'][0]['display_name'], 'Square')
        self.assertEquals(ctx[1]['term_set'][0]['count'], 2)
Beispiel #11
0
    def test_vocabulary_render_related(self):
        course = Course.objects.get(title="Sample Course")
        request = HttpRequest()
        request.course = course

        notes = SherdNote.objects.filter(title='Left Corner')
        ctx = VocabularyResource().render_related(request, notes)

        self.assertEquals(len(ctx), 2)
        self.assertEquals(ctx[0]['display_name'], 'Colors')
        self.assertEquals(len(ctx[0]['term_set']), 1)
        self.assertEquals(ctx[0]['term_set'][0]['display_name'], 'Red')
        self.assertEquals(ctx[0]['term_set'][0]['count'], 1)

        self.assertEquals(ctx[1]['display_name'], 'Shapes')
        self.assertEquals(len(ctx[1]['term_set']), 1)
        self.assertEquals(ctx[1]['term_set'][0]['display_name'], 'Square')
        self.assertEquals(ctx[1]['term_set'][0]['count'], 1)
Beispiel #12
0
    def get(self, request, course_pk=None, asset_id=None, annot_id=None):
        if asset_id:
            try:
                asset = Asset.objects.get(pk=asset_id, course=request.course)
                asset.primary
            except Asset.DoesNotExist:
                return asset_switch_course(request, asset_id)
            except Source.DoesNotExist:
                return render(request, '500.html', {})

        if not request.is_ajax():
            return self.redirect_to_react_views(request.course.id, asset_id,
                                                annot_id)

        ctx = {'asset_id': asset_id, 'annotation_id': annot_id}

        qs = Vocabulary.objects.filter(course=request.course)
        vocabulary = VocabularyResource().render_list(request, qs)

        user_resource = UserResource()
        owners = user_resource.render_list(request, request.course.members)

        ctx['panels'] = [{
            'panel_state': 'open',
            'panel_state_label': "Annotate Media",
            'context': {
                'type':
                'asset',
                'is_faculty':
                self.is_viewer_faculty,
                'allow_item_download':
                self.is_viewer_faculty
                and course_details.allow_item_download(request.course)
            },
            'owners': owners,
            'vocabulary': vocabulary,
            'template': 'asset_workspace',
            'current_asset': asset_id,
            'current_annotation': annot_id,
            'update_history': True,
            'show_collection': True
        }]

        return self.render_to_json_response(ctx)
Beispiel #13
0
    def get_context_data(self, **kwargs):
        # passed project may identify the assignment or a response
        project = get_object_or_404(Project, pk=kwargs.get('project_id', None))
        parent = self.get_assignment(project)
        assignment_can_edit = \
            parent.can_edit(self.request.course, self.request.user)

        responses = parent.responses(self.request.course, self.request.user)

        peer_response = self.get_peer_response(project)
        my_response = self.get_my_response(responses)
        the_response = peer_response or my_response
        response_can_edit = self.response_can_edit(the_response)

        lst = Vocabulary.objects.filter(course=self.request.course)
        lst = lst.prefetch_related('term_set')
        vocabulary_json = VocabularyResource().render_list(self.request, lst)

        is_faculty = self.request.course.is_faculty(self.request.user)
        feedback, feedback_count = self.get_feedback(responses, is_faculty)

        students = self.request.course.students.order_by(
            'last_name', 'first_name', 'username')

        self.ctx = {
            'is_faculty': is_faculty,
            'assignment': parent,
            'assignment_can_edit': assignment_can_edit,
            'my_response': my_response,
            'the_response': the_response,
            'response_can_edit': response_can_edit,
            'response_view_policies': RESPONSE_VIEW_POLICY,
            'submit_policy': PUBLISH_WHOLE_CLASS[0],
            'vocabulary': json.dumps(vocabulary_json),
            'responses': responses,
            'feedback': json.dumps(feedback),
            'feedback_count': feedback_count,
            'students': students
        }
        self.ctx.update(self.get_extra_context())
        return self.ctx
Beispiel #14
0
    def get(self, request, asset_id):
        ctx = {}
        qs = Asset.objects.filter(pk=asset_id, course=request.course)

        if qs.count() > 0:
            notes = SherdNote.objects.get_related_notes(
                qs, self.record_owner, self.visible_authors,
                self.all_items_are_visible)

            # tags
            ctx['tags'] = TagResource().render_related(request, notes)

            # vocabulary
            ctx['vocabulary'] = VocabularyResource().render_related(
                request, notes)

            # DiscussionIndex is misleading. Objects returned are
            # projects & discussions title, object_pk, content_type, modified
            indicies = DiscussionIndex.objects.filter(
                asset=qs[0]).order_by('-modified')
            ctx.update(DiscussionIndexResource().render_list(
                request, indicies))
        return self.render_to_json_response(ctx)
Beispiel #15
0
    def test_vocabulary_render_for_course(self):
        request = HttpRequest()
        request.course = self.sample_course

        notes = SherdNote.objects.filter(title='Nice Tie')
        ctx = VocabularyResource().render_for_course(request, notes)

        self.assertEquals(len(ctx), 2)
        self.assertEquals(ctx[0]['display_name'], 'Colors')
        self.assertEquals(len(ctx[0]['term_set']), 3)
        self.assertEquals(ctx[0]['term_set'][0]['display_name'], 'Blue')
        self.assertEquals(ctx[0]['term_set'][0]['count'], 0)
        self.assertEquals(ctx[0]['term_set'][1]['display_name'], 'Green')
        self.assertEquals(ctx[0]['term_set'][1]['count'], 0)
        self.assertEquals(ctx[0]['term_set'][2]['display_name'], 'Red')
        self.assertEquals(ctx[0]['term_set'][2]['count'], 0)

        self.assertEquals(ctx[1]['display_name'], 'Shapes')
        self.assertEquals(len(ctx[1]['term_set']), 2)
        self.assertEquals(ctx[1]['term_set'][0]['display_name'], 'Square')
        self.assertEquals(ctx[1]['term_set'][0]['count'], 1)
        self.assertEquals(ctx[1]['term_set'][1]['display_name'], 'Triangle')
        self.assertEquals(ctx[1]['term_set'][1]['count'], 0)
Beispiel #16
0
    def get(self, request, asset_id):
        try:
            ctx = {}
            asset = Asset.objects.filter(pk=asset_id, course=request.course)
            notes = SherdNote.objects.get_related_notes(
                asset, self.record_owner, self.visible_authors)

            # tags
            ctx['tags'] = TagResource().render_related(request, notes)

            # vocabulary
            ctx['vocabulary'] = VocabularyResource().render_related(
                request, notes)

            # DiscussionIndex is misleading. Objects returned are
            # projects & discussions title, object_pk, content_type, modified
            indicies = DiscussionIndex.objects.filter(
                asset=asset).order_by('-modified')
            ctx.update(DiscussionIndexResource().render_list(
                request, indicies))

            return self.render_to_json_response(ctx)
        except Asset.DoesNotExist:
            return asset_switch_course(request, asset_id)
Beispiel #17
0
def discussion_view(request, discussion_id):
    """Show a threadedcomments discussion of an arbitrary object.
    discussion_id is the pk of the root comment."""

    root_comment = get_object_or_404(ThreadedComment, pk=discussion_id)
    if not root_comment.content_object.permission_to('read', request):
        return HttpResponseForbidden('You do not have permission \
                                     to view this discussion.')

    try:
        my_course = root_comment.content_object.context.content_object
    except:
        # legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = \
            Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()

    data = {'space_owner': request.user.username}

    if not request.is_ajax():
        data['discussion'] = root_comment
        return render_to_response('discussions/discussion.html',
                                  data,
                                  context_instance=RequestContext(request))
    else:
        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

        user_resource = UserResource()
        owners = user_resource.render_list(request, request.course.members)

        data['panels'] = [{
            'panel_state':
            'open',
            'subpanel_state':
            'open',
            'panel_state_label':
            "Discussion",
            'template':
            'discussion',
            'owners':
            owners,
            'vocabulary':
            vocabulary,
            'title':
            root_comment.title,
            'can_edit_title':
            my_course.is_faculty(request.user),
            'root_comment_id':
            root_comment.id,
            'context':
            threaded_comment_json(request, root_comment)
        }]

        # Create a place for asset editing
        panel = {
            'panel_state': 'closed',
            'panel_state_label': "Item Details",
            'template': 'asset_quick_edit',
            'update_history': False,
            'show_collection': False,
            'owners': owners,
            'vocabulary': vocabulary,
            'context': {
                'type': 'asset'
            }
        }

        data['panels'].append(panel)

        return HttpResponse(simplejson.dumps(data, indent=2),
                            mimetype='application/json')
Beispiel #18
0
def project_workspace(request, project_id, feedback=None):
    """
    A multi-panel editable view for the specified project
    Legacy note: Ideally, this function would be named project_view but
    StructuredCollaboration requires the view name
    to be  <class>-view to do a reverse lookup

    Panel 1: Parent Assignment (if applicable)
    Panel 2: Project
    Panel 3: Instructor Feedback (if applicable & exists)

    Keyword arguments:
    project_id -- the model id
    """
    project = get_object_or_404(Project, pk=project_id)

    if not project.can_read(request):
        return HttpResponseForbidden("forbidden")

    show_feedback = feedback == "feedback"
    data = {
        'space_owner': request.user.username,
        'show_feedback': show_feedback
    }

    if not request.is_ajax():
        data['project'] = project
        return render_to_response('projects/project.html',
                                  data,
                                  context_instance=RequestContext(request))
    else:
        panels = []

        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

        owners = UserResource().render_list(request, request.course.members)

        is_faculty = request.course.is_faculty(request.user)
        can_edit = project.can_edit(request)
        feedback_discussion = project.feedback_discussion() \
            if is_faculty or can_edit else None

        # Project Parent (assignment) if exists
        parent_assignment = project.assignment()
        if parent_assignment:
            resource = ProjectResource(
                record_viewer=request.user,
                is_viewer_faculty=is_faculty,
                editable=parent_assignment.can_edit(request))
            assignment_ctx = resource.render_one(request, parent_assignment)

            panel = {
                'is_faculty':
                is_faculty,
                'panel_state':
                "open" if (project.title == "Untitled"
                           and len(project.body) == 0) else "closed",
                'subpanel_state':
                'closed',
                'context':
                assignment_ctx,
                'owners':
                owners,
                'vocabulary':
                vocabulary,
                'template':
                'project'
            }
            panels.append(panel)

        # Requested project, can be either an assignment or composition
        resource = ProjectResource(record_viewer=request.user,
                                   is_viewer_faculty=is_faculty,
                                   editable=can_edit)
        project_context = resource.render_one(request, project)

        # only editing if it's new
        project_context['editing'] = \
            True if can_edit and len(project.body) < 1 else False

        project_context['create_instructor_feedback'] = \
            is_faculty and parent_assignment and not feedback_discussion

        panel = {
            'is_faculty': is_faculty,
            'panel_state': 'closed' if show_feedback else 'open',
            'context': project_context,
            'template': 'project',
            'owners': owners,
            'vocabulary': vocabulary
        }
        panels.append(panel)

        # Project Response -- if the requested project is an assignment
        # This is primarily a student view. The student's response should
        # pop up automatically when the parent assignment is viewed.
        if project.is_assignment(request):
            responses = project.responses_by(request, request.user)
            if len(responses) > 0:
                response = responses[0]
                response_can_edit = response.can_edit(request)
                resource = ProjectResource(record_viewer=request.user,
                                           is_viewer_faculty=is_faculty,
                                           editable=response_can_edit)
                response_context = resource.render_one(request, response)

                panel = {
                    'is_faculty': is_faculty,
                    'panel_state': 'closed',
                    'context': response_context,
                    'template': 'project',
                    'owners': owners,
                    'vocabulary': vocabulary
                }
                panels.append(panel)

                if not feedback_discussion and response_can_edit:
                    feedback_discussion = response.feedback_discussion()

        data['panels'] = panels

        # If feedback exists for the requested project
        if feedback_discussion:
            # 3rd pane is the instructor feedback, if it exists
            panel = {
                'panel_state': 'open' if show_feedback else 'closed',
                'panel_state_label': "Instructor Feedback",
                'template': 'discussion',
                'owners': owners,
                'vocabulary': vocabulary,
                'context': threaded_comment_json(request, feedback_discussion)
            }
            panels.append(panel)

        # Create a place for asset editing
        panel = {
            'panel_state': 'closed',
            'panel_state_label': "Item Details",
            'template': 'asset_quick_edit',
            'update_history': False,
            'owners': owners,
            'vocabulary': vocabulary,
            'context': {
                'type': 'asset'
            }
        }
        panels.append(panel)

        return HttpResponse(json.dumps(data, indent=2),
                            mimetype='application/json')
Beispiel #19
0
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.views.generic.base import TemplateView
from mediathread.assetmgr.views import AssetCollectionView, AssetDetailView, \
    TagCollectionView
from mediathread.main.views import MigrateCourseView, MigrateMaterialsView, \
    RequestCourseView
from mediathread.projects.views import ProjectCollectionView, ProjectDetailView
from mediathread.taxonomy.api import TermResource, VocabularyResource
from tastypie.api import Api
import os.path

tastypie_api = Api('')
tastypie_api.register(TermResource())
tastypie_api.register(VocabularyResource())

admin.autodiscover()

bookmarklet_root = os.path.join(os.path.dirname(__file__), "../media/",
                                "bookmarklets")

redirect_after_logout = getattr(settings, 'LOGOUT_REDIRECT_URL', None)

auth_urls = (r'^accounts/', include('django.contrib.auth.urls'))
logout_page = (r'^accounts/logout/$', 'django.contrib.auth.views.logout', {
    'next_page': redirect_after_logout
})

if hasattr(settings, 'WIND_BASE'):
    auth_urls = (r'^accounts/', include('djangowind.urls'))
Beispiel #20
0
    def post(self, request, *args, **kwargs):
        """Start a discussion of an arbitrary model instance."""
        title = request.POST['comment_html']
        comment = request.POST.get('comment', '')

        # Find the object we're discussing.
        model = request.POST['model']
        the_content_type = ContentType.objects.get(
            app_label=request.POST['app_label'], model=model)
        assert the_content_type is not None

        the_object = the_content_type.get_object_for_this_type(
            pk=request.POST['obj_pk'])
        assert the_object is not None

        try:
            obj_sc = Collaboration.objects.get_for_object(the_object)
        except Collaboration.DoesNotExist:
            obj_sc = Collaboration()
            # TODO: populate this collab with sensible auth defaults.
            obj_sc.content_object = the_object
            obj_sc.save()

        # sky: I think what I want to do is have the ThreadedComment
        # point to the_object
        # and the collaboration will point to the threaded root comment
        # that way, whereas, if we live in Collaboration-land,
        # we can get to ThreadedComments
        # threaded comments can also live in it's own world without 'knowing'
        # about SC OTOH, threaded comment shouldn't be able
        # to point to the regular object
        # until Collaboration says it's OK (i.e. has permissions)
        # ISSUE: how to migrate? (see models.py)

        # now create the CHILD collaboration object for the
        # discussion to point at.
        # This represents the auth for the discussion itself.
        collaboration_context = cached_course_collaboration(request.course)
        disc_sc = Collaboration(
            _parent=obj_sc,
            title=title,
            context=collaboration_context,
        )
        disc_sc.set_policy(request.POST.get('publish', None))
        disc_sc.save()

        # finally create the root discussion object, pointing it at the CHILD.
        new_threaded_comment = ThreadedComment(parent=None,
                                               title=title,
                                               comment=comment,
                                               user=request.user,
                                               content_object=disc_sc)

        # TODO: find the default site_id
        new_threaded_comment.site_id = 1
        new_threaded_comment.save()

        disc_sc.content_object = new_threaded_comment
        disc_sc.save()

        DiscussionIndex.update_class_references(
            new_threaded_comment.comment, new_threaded_comment.user,
            new_threaded_comment, new_threaded_comment.content_object,
            new_threaded_comment.user)

        if not request.is_ajax():
            if model == 'project':
                discussion_url = reverse('project-workspace',
                                         args=(request.course.pk,
                                               the_object.pk))
            else:
                discussion_url = reverse('discussion-view',
                                         args=(request.course.pk,
                                               new_threaded_comment.id))

            return HttpResponseRedirect(discussion_url)
        else:
            vocabulary = VocabularyResource().render_list(
                request, Vocabulary.objects.filter(course=request.course))

            user_resource = UserResource()
            owners = user_resource.render_list(request, request.course.members)

            data = {
                'panel_state': 'open',
                'panel_state_label': "Instructor Feedback",
                'template': 'discussion',
                'owners': owners,
                'vocabulary': vocabulary,
                'context': threaded_comment_json(request, new_threaded_comment)
            }

            return HttpResponse(json.dumps(data, indent=2),
                                content_type='application/json')
Beispiel #21
0
    def get(self, request, *args, **kwargs):
        project = get_object_or_404(Project, pk=kwargs.get('project_id', None))
        data = {'space_owner': request.user.username}

        if not request.is_ajax():
            self.template_name = 'projects/composition.html'
            data['project'] = project
            return self.render_to_response(data)
        else:
            panels = []

            lst = Vocabulary.objects.filter(course=request.course)
            lst = lst.prefetch_related('term_set')
            vocabulary = VocabularyResource().render_list(request, lst)

            owners = UserResource().render_list(request,
                                                request.course.members)

            is_faculty = request.course.is_faculty(request.user)
            can_edit = project.can_edit(request.course, request.user)

            # Requested project, can be either an assignment or composition
            resource = ProjectResource(record_viewer=request.user,
                                       is_viewer_faculty=is_faculty,
                                       editable=can_edit)
            project_context = resource.render_one(request, project)

            # only editing if it's new
            project_context['editing'] = \
                True if can_edit and len(project.body) < 1 else False

            project_context['create_instructor_feedback'] = False

            project_revisions_url = reverse(
                'project-revisions', args=[request.course.pk, project.id])

            panel = {
                'is_faculty': is_faculty,
                'context': project_context,
                'template': 'project',
                'owners': owners,
                'project_revisions_url': project_revisions_url,
                'vocabulary': vocabulary
            }
            panels.append(panel)

            data['panels'] = panels

            # Create a place for asset editing
            panel = {
                'template': 'asset_quick_edit',
                'update_history': False,
                'owners': owners,
                'vocabulary': vocabulary,
                'context': {
                    'type': 'asset'
                }
            }
            panels.append(panel)

            return self.render_to_json_response(data)
Beispiel #22
0
def discussion_create(request):
    """Start a discussion of an arbitrary model instance."""
    title = request.POST['comment_html']

    # Find the object we're discussing.
    the_content_type = ContentType.objects.get(
        app_label=request.POST['app_label'], model=request.POST['model'])
    assert the_content_type is not None

    the_object = the_content_type.get_object_for_this_type(
        pk=request.POST['obj_pk'])
    assert the_object is not None

    try:
        obj_sc = Collaboration.get_associated_collab(the_object)
    except Collaboration.DoesNotExist:
        obj_sc = Collaboration()
        # TODO: populate this collab with sensible auth defaults.
        obj_sc.content_object = the_object
        obj_sc.save()

    # sky: I think what I want to do is have the ThreadedComment
    # point to the_object
    # and the collaboration will point to the threaded root comment
    # that way, whereas, if we live in Collaboration-land,
    # we can get to ThreadedComments
    # threaded comments can also live in it's own world without 'knowing'
    # about SC OTOH, threaded comment shouldn't be able
    # to point to the regular object
    # until Collaboration says it's OK (i.e. has permissions)
    # ISSUE: how to migrate? (see models.py)

    # now create the CHILD collaboration object for the discussion to point at.
    # This represents the auth for the discussion itself.
    disc_sc = Collaboration(
        _parent=obj_sc,
        title=title,
        # or we could point it at the root
        # threadedcomments object.
        # content_object=None,
        context=request.collaboration_context,
    )
    disc_sc.policy = request.POST.get('publish', None)
    if request.POST.get('inherit', None) == 'true':
        disc_sc.group_id = obj_sc.group_id
        disc_sc.user_id = obj_sc.user_id
    disc_sc.save()

    # finally create the root discussion object, pointing it at the CHILD.
    new_threaded_comment = ThreadedComment(parent=None,
                                           title=title,
                                           comment='',
                                           user=request.user,
                                           content_object=disc_sc)

    # TODO: find the default site_id
    new_threaded_comment.site_id = 1
    new_threaded_comment.save()

    disc_sc.content_object = new_threaded_comment
    disc_sc.save()

    if not request.is_ajax():
        return HttpResponseRedirect("/discussion/%d/" %
                                    new_threaded_comment.id)
    else:
        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

        user_resource = UserResource()
        owners = user_resource.render_list(request, request.course.members)

        data = {
            'panel_state': 'open',
            'panel_state_label': "Instructor Feedback",
            'template': 'discussion',
            'owners': owners,
            'vocabulary': vocabulary,
            'context': threaded_comment_json(request, new_threaded_comment)
        }

        return HttpResponse(simplejson.dumps(data, indent=2),
                            mimetype='application/json')
Beispiel #23
0
from mediathread.api import TagResource
from mediathread.assetmgr.api import AssetResource
from mediathread.main.api import CourseResource, CourseSummaryResource
from mediathread.projects.api import ProjectResource
from mediathread.taxonomy.api import TermResource, VocabularyResource
from tastypie.api import Api
import os.path

v1_api = Api(api_name='v1')
v1_api.register(SherdNoteResource())
v1_api.register(AssetResource())
v1_api.register(ProjectResource())
v1_api.register(CourseResource())
v1_api.register(CourseSummaryResource())
v1_api.register(TermResource())
v1_api.register(VocabularyResource())
v1_api.register(TagResource())

admin.autodiscover()

site_media_root = os.path.join(os.path.dirname(__file__), "../media")
bookmarklet_root = os.path.join(os.path.dirname(__file__), "../media/",
                                "bookmarklets")

redirect_after_logout = getattr(settings, 'LOGOUT_REDIRECT_URL', None)

auth_urls = (r'^accounts/', include('django.contrib.auth.urls'))
logout_page = (r'^accounts/logout/$', 'django.contrib.auth.views.logout', {
    'next_page': redirect_after_logout
})
Beispiel #24
0
    def get(self, request, *args, **kwargs):
        project = get_object_or_404(Project, pk=kwargs.get('project_id', None))
        assignment = project.assignment()
        if not assignment or not assignment.is_essay_assignment():
            return HttpResponseForbidden('')

        panels = []

        lst = Vocabulary.objects.filter(course=request.course)
        lst = lst.prefetch_related('term_set')
        vocabulary = VocabularyResource().render_list(request, lst)

        owners = UserResource().render_list(request, request.course.members)

        is_faculty = request.course.is_faculty(request.user)
        can_edit = project.can_edit(request.course, request.user)
        feedback_discussion = project.feedback_discussion() \
            if is_faculty or can_edit else None

        parent = project.assignment()

        # Requested project, can be either an assignment or composition
        resource = ProjectResource(record_viewer=request.user,
                                   is_viewer_faculty=is_faculty,
                                   editable=can_edit)
        project_context = resource.render_one(request, project)

        # only editing if it's new
        project_context['editing'] = \
            True if can_edit and len(project.body) < 1 else False

        project_context['create_instructor_feedback'] = \
            is_faculty and parent and not feedback_discussion

        project_revisions_url = reverse('project-revisions',
                                        args=[request.course.pk, project.id])

        panel = {
            'is_faculty':
            is_faculty,
            'show_feedback':
            feedback_discussion is not None,
            'create_feedback_url':
            reverse('discussion-create', args=[request.course.pk]),
            'project_revisions_url':
            project_revisions_url,
            'context':
            project_context,
            'template':
            'project_response',
            'owners':
            owners,
            'vocabulary':
            vocabulary
        }
        panels.append(panel)

        # If feedback exists for the requested project
        if feedback_discussion:
            # 3rd pane is the instructor feedback, if it exists
            panel = {
                'template': 'project_feedback',
                'owners': owners,
                'vocabulary': vocabulary,
                'context': threaded_comment_json(request, feedback_discussion)
            }
            panels.append(panel)

        # Create a place for asset editing
        panel = {
            'template': 'asset_quick_edit',
            'update_history': False,
            'owners': owners,
            'vocabulary': vocabulary,
            'context': {
                'type': 'asset'
            }
        }
        panels.append(panel)

        data = {'space_owner': request.user.username, 'panels': panels}

        return self.render_to_json_response(data)