コード例 #1
0
 def get_context(self):
     resource = self.get_resource()
     request = self.context.get('request')
     return {
         'text': self.text,
         'textid': self.text.id,
         'title': 'Annotate Text',
         'content': self.get_content(resource),
         'baselocation': basepath(request),
         'userid': request.user.id,
         'title': self.text.title,
         'repository_id': self.text.repository.id,
         'project': self.project
     }
コード例 #2
0
 def get_context(self):
     resource = self.get_resource()
     request = self.context.get('request')
     content = self.get_content(resource)
     detect  = chardet.detect(content)
     return {
         'text': self.text,
         'textid': self.text.id,
         'title': 'Annotate Text',
         'content': content.decode(detect['encoding']).encode('utf-8'), # We are using chardet to guess the encoding becuase giles is returning everyting with a utf-8 header even if it is not utf-8
         'baselocation' : basepath(request),
         'userid': request.user.id,
         'title': self.text.title,
         'repository_id': self.text.repository.id,
         'project': self.project
     }
コード例 #3
0
def network(request):
    """
    Provides a network browser view.

    Parameters
    ----------
    request : `django.http.requests.HttpRequest`

    Returns
    ----------
    :class:`django.http.response.HttpResponse`
    """
    template = "annotations/network.html"
    form = None
    context = {
        'baselocation': basepath(request),
        'user': request.user,
        'form': form,
    }
    return render(request, template, context)
コード例 #4
0
ファイル: text_views.py プロジェクト: sumukha1994/vogon-web
def text(request, textid):
    """
    Provides the main text annotation/info view.

    Parameters
    ----------
    request : `django.http.requests.HttpRequest`

    Returns
    ----------
    :class:`django.http.response.HttpResponse`
    """

    text = get_object_or_404(Text, pk=textid)
    from annotations.annotators import annotator_factory

    annotator = annotator_factory(request, text)

    context_data = {
        'text': text,
        'textid': textid,
        'title': 'Annotate Text',
        'content': annotator.get_content(),
        'baselocation': basepath(request)
    }

    # If a text is restricted, then the user needs explicit permission to
    #  access it.
    access_conditions = [
        request.user in text.annotators.all(),
        getattr(request.user, 'is_admin', False),
        text.public,
    ]
    # if not any(access_conditions):
    #     # TODO: return a pretty templated response.
    #     raise PermissionDenied
    mode = request.GET.get('mode', 'view')

    if all([
            request.user.is_authenticated(),
            any(access_conditions), mode == 'annotate'
    ]):
        template = "annotations/text.html"
        context_data.update({
            'userid': request.user.id,
            'title': text.title,
        })
        context = context_data
        return render(request, template, context)
    elif all([
            request.user.is_authenticated(),
            any(access_conditions), mode == 'user_annotations'
    ]):
        appellations = Appellation.objects.filter(occursIn_id=textid,
                                                  asPredicate=False,
                                                  createdBy=request.user.id)
        appellations_data, appellation_creators = get_appellation_summaries(
            appellations)
        relationset_qs = RelationSet.objects.filter(occursIn=textid,
                                                    createdBy=request.user.id)
        relationsets = _get_relations_data(relationset_qs)

        context_data.update({
            'view': 'user',
        })
    elif mode == 'annotate':
        return HttpResponseRedirect(reverse('login'))

    template = "annotations/text_view.html"

    appellations = Appellation.objects.filter(occursIn_id=textid,
                                              asPredicate=False)
    appellations_data, appellation_creators = get_appellation_summaries(
        appellations)
    relationset_qs = RelationSet.objects.filter(occursIn=textid)
    relationsets = _get_relations_data(relationset_qs)

    context_data.update({
        'userid': request.user.id,
        'appellations_data': appellations_data,
        'annotators': appellation_creators,
        'relations': relationsets,
        'title': text.title,
    })
    context = context_data
    return render(request, template, context)