Пример #1
0
    def render(self, context):
        user = context['request'].user

        if not user.is_authenticated() or get_setting( user, 'show_tips'):
            return '<div class="tip">%s</div>' % random.choice(TIPS)
        else:
            return ''
Пример #2
0
    def render(self, context):
        try:
            obj, content_type, user = self.resolve_vars(context)
            edit = True

            # Try to get the note for this object:
            try:
                note = Note.objects.get( user = user,
                                          content_type = content_type,
                                          object_id = obj.id )
                public = 'on' if note.public else 'off'
                checked = 'checked' if note.public else ''
                note = note.txt
            except ObjectDoesNotExist:
                note = ''
                edit = False
                public = 'on' if get_setting(user, 'profile_public') else 'off'
                checked = 'checked' if get_setting(user, 'profile_public') else ''

            form_view = reverse( 'manage_note', kwargs={
                                 'ctype_id': content_type.id,
                                 'object_id': obj.id })

            form = '''
            <div class="add_note noprint">
            <form method="POST" action="%(form_view)s">
              <input type='hidden' name='csrfmiddlewaretoken' value='%(csrf)s' />
              <textarea class="note_name_input" type="text" name="txt" maxlength="20480">%(note)s</textarea>
              <input type="checkbox" name="public" id="id_public" value="%(public)s" %(checked)s /> Nota p&uacute;blica |
              <button type="submit" value="Submit">Aplicar</button>
            </form></div>
            ''' % { 'form_view': form_view,
                    'csrf': csrf.get_token(context['request']),
                    'note': note,
                    'public': public,
                    'checked': checked, }

            return form
        except template.VariableDoesNotExist:
            return ''
Пример #3
0
def document_display( request, docid ):
    context = {}

    document = get_object_or_404(Document, pk=docid )

    if document.no_index() and not request.user.is_authenticated():
        return forgetme(request)

    context['document'] = document
    context['url'] = urllib.quote_plus( SITE_URL + reverse( 'document_display',
            kwargs = { 'docid': docid }) )
    context['text'] =  urllib.quote_plus( document.title().encode('utf-8')  )

    if request.user.is_authenticated():
        context['show_user_notes'] = get_setting(request.user, 'show_user_notes')

    return render_to_response('document_display.html', context,
                context_instance=RequestContext(request))
Пример #4
0
def document_display( request, docid ):
    context = {}

    document = get_object_or_404(Document, pk=docid )

    if document.no_index() and not request.user.is_authenticated():
        return forgetme(request)

    context['document'] = document
    context['url'] = urllib.quote_plus(SITE_URL + document.get_absolute_url())
    context['text'] =  urllib.quote_plus(document.title().encode('utf-8'))

    if request.user.is_authenticated():
        context['show_user_notes'] = get_setting(request.user, 'show_user_notes')

    # TODO: retrieve the html text between these dates and remove the
    # warning altogether
    context['pdf_warning'] = (document.date >= datetime.date(2016,3,24) and
                              document.date < datetime.date(2016, 12, 19))

    return render_to_response('document_display.html', context,
                context_instance=RequestContext(request))
Пример #5
0
def get_tag_from_request(request):
    if request.method != 'POST':
        raise PermissionDenied

    user = request.user
    form = TagForm(request.POST)

    if form.is_valid():
        name = form.cleaned_data['name']
        if not name.strip():
            # Do not create empty tags
            return None
        try:
            tag = Tag.objects.get( user=user, name=name )
        except ObjectDoesNotExist:
            tag = Tag( user=user,
                       name=name,
                       public = get_setting(user, 'profile_public'))
            tag.save()
            logger.info('User %s created tag "%s"' % (tag.user.username, tag.name))
    else:
        tag = None

    return tag
Пример #6
0
def add_bookmark( user, obj ):
    bookmark = Bookmark( user=user,
            content_object=obj,
            public = get_setting(user, 'profile_public'))
    bookmark.save()
    return bookmark