Beispiel #1
0
def merengue_logout_service(request):
    """Do the logout and then send a message to the user"""
    response = logout_service(request, config_loader=merengue_config_loader,
                              next_page='/')
    if 'SAMLResponse' in request.GET:  # we started the logout
        send_info(request, _('Thank you for your visit'))
    return response
Beispiel #2
0
def subscription_form(request, basecontent_id):
    content = BaseContent.objects.get(id=basecontent_id)
    subscribable = content.subscribable_set.actives()
    if not subscribable:
        return HttpResponseRedirect(content.get_absolute_url())
    subscribable = subscribable[0]
    app_label, module_name = subscribable.class_name.split('.')
    content_type = ContentType.objects.get(app_label=app_label, model=module_name)
    model_class = content_type.model_class()
    data = None
    if request.POST:
        data = request.POST
    form = model_class.class_form()(data)
    if form.is_valid():
        subscription = form.save(commit=False)
        subscription.subscribable = subscribable
        subscription.save()
        subscriber_listing_url = reverse('subscriber_listing', args=(basecontent_id, ))
        send_info(
            request,
            _('Request send successfully. See <a href="%(subscriber_listing)s">suscriber list</a>') % {
                'subscriber_listing': subscriber_listing_url,
            },
        )
        url_redirect = content.get_absolute_url()
        invalidate_cache_for_path(url_redirect)
        return HttpResponseRedirect(url_redirect)
    return render_to_response('subscription/subscription_form.html',
                              {'form': form,
                               'content': content,
                              },
                              context_instance=RequestContext(request))
Beispiel #3
0
def createdir(request, repository_name, path='',
              base_template=FILEBROWSER_BASE_TEMPLATE, url_prefix=None):
    repository = get_object_or_404(Repository, name=repository_name)
    if request.POST:
        dirname = request.POST.get('dirname', None)
        dirname = dirname.strip()
        errornote = None
        if not dirname:
            errornote = _('You must introduce the name of the new folder')
        elif repository.check_dir(join(path, dirname)):
            errornote = _(u'Folder %(dirname)s already exists') % {'dirname': dirname}
        if errornote:  # si hay algun tipo de error
            return render_to_response('filebrowser/createdir.html',
                                      {'repository': repository,
                                       'base_template': base_template,
                                       'path': path,
                                       'errornote': errornote,
                                       'url_prefix': url_prefix},
                                      context_instance=RequestContext(request))
        repository.create_dir(join(path, dirname))
        message = _('Folder created successfully')
        send_info(request, message)
        return HttpResponseRedirect(filebrowser_reverse(request, "filebrowser_dir_listing",
                        kwargs={'repository_name': repository.name,
                                'path': path},
                        url_prefix=url_prefix))
    else:
        dirs, files, parents, dirname = repository.list_directory(path)
        return render_to_response('filebrowser/createdir.html',
                                  {'repository': repository,
                                   'base_template': base_template,
                                   'path': path,
                                   'parents': parents,
                                   'url_prefix': url_prefix},
                                  context_instance=RequestContext(request))
Beispiel #4
0
def contact_form_submit(request, content_id, contact_form_id):
    content = get_object_or_404(BaseContent, pk=content_id).get_real_instance()
    contact_form = get_object_or_404(ContactForm, pk=contact_form_id,
                                     content__pk=content_id)

    if request.method == 'POST':
        form = contact_form.get_form(request)
        if form.is_valid():
            sentcontactform = form.save(request, content, contact_form)
            if contact_form.redirect_to:
                redirect = contact_form.redirect_to
                if contact_form.redirect_to_with_params:
                    redirect = "%s?content_id=%s&contact_form_id=%s&sentcontactform=%s" % (redirect,
                                                                                           content.pk,
                                                                                           contact_form_id,
                                                                                           sentcontactform.pk)
            else:
                redirect = request.META.get('HTTP_REFERER',
                                            content.public_link())
            if contact_form.sent_msg:
                send_info(request, contact_form.sent_msg)
        else:
            return errors_to_session(request, content, form, contact_form_id)

    return HttpResponseRedirect(redirect)
Beispiel #5
0
def can_create_new_thread(request, content):
    user = request.user
    if not user:
        login_url = '%s?next=%s' % (get_login_url(),
                                    request.get_full_path())
        return HttpResponseRedirect(login_url)
    elif not has_permission(content, user, 'edit'):
        send_info(request, ugettext('You don\'t have permission to create a new thread'))
        return HttpResponseRedirect(content.get_absolute_url())
    return None
Beispiel #6
0
def rotate_language_and_redirect(request):
    """ Generic view that rotates user language and then redirect to an url passed by http parameter """
    from django.conf import settings
    languages = dict(settings.LANGUAGES)

    next_url = request.REQUEST.get('next', '')
    response = HttpResponseRedirect(next_url)
    new_lang_code = rotate_language(request, response)
    new_lang = smart_unicode(str(languages[new_lang_code]))

    log.send_info(request, u'%s %s' % (_('Now you are editing content in'), new_lang))

    return response
Beispiel #7
0
def upload(request, repository_name, path='',
           base_template=FILEBROWSER_BASE_TEMPLATE, url_prefix=None):
    repository = get_object_or_404(Repository, name=repository_name)
    if request.method == 'POST':
        for k, f in request.FILES.items():
            if k.startswith('file_'):
                fout = repository.create_file(join(path, f.name))
                for chunk in f.chunks():
                    fout.write(chunk)
                fout.close()
        send_info(request, _('Files uploaded successfully'))
        return HttpResponseRedirect(filebrowser_reverse(request, "filebrowser_dir_listing",
                        kwargs={'repository_name': repository.name,
                                'path': path},
                        url_prefix=url_prefix))
    else:
        dirs, files, parents, dirname = repository.list_directory(path)
        return render_to_response('filebrowser/upload.html',
                                  {'repository': repository,
                                   'base_template': base_template,
                                   'path': path,
                                   'parents': parents,
                                   'url_prefix': url_prefix},
                                  context_instance=RequestContext(request))
Beispiel #8
0
def action(request, repository_name, path,
           base_template=FILEBROWSER_BASE_TEMPLATE, url_prefix=None):
    """ process rename, delete, etc. actions in files and directories """
    repository = get_object_or_404(Repository, name=repository_name)
    if 'renameform' in request.POST:
        action = 'confirmrename'
    elif 'deleteform' in request.POST:
        action = 'confirmdelete'
    elif 'rename' in request.POST:
        action = 'rename'
        old_elems = []
    else:
        action = 'delete'
    elems = []
    for k, v in request.POST.items():
        if (k.startswith('dir_') or k.startswith('file_') or
            k.startswith('elem_') or k.startswith('doc_')):
            if k.startswith('doc_'):
                try:
                    title = Document.objects.get(slug=v).title
                except:
                    title = v
                elems.append({'id': v, 'title': title})
            else:
                elems.append({'id': v, 'title': v})
            if action == 'rename':
                if k.startswith('dir_'):
                    old_elems.append(request.POST['olddir_%s' % k[len('dir_'):]])
                elif k.startswith('file_'):
                    old_elems.append(request.POST['oldfile_%s' % k[len('file_'):]])
                else:
                    old_elems.append(request.POST['olddoc_%s' % k[len('doc_'):]])
    if not elems:
        send_error(request, _("You didn't selected any element"))
        return HttpResponseRedirect(filebrowser_reverse(request, "filebrowser_dir_listing",
                        kwargs={'repository_name': repository.name,
                                'path': path},
                        url_prefix=url_prefix))
    if action in ['confirmrename', 'confirmdelete']:
        if action == 'confirmrename':
            template = 'filebrowser/rename.html'
        else:
            template = 'filebrowser/delete.html'
        basepath = repository.get_absolute_path(path)
        basepath = basepath.encode('utf-8').decode('utf-8')
        files = []
        dirs = []
        docs = []
        for e in elems:
            file = join(basepath, e['id'])
            if isdir(file):
                dirs.append(e)
            elif isfile(file):
                files.append(e)
            else:
                docs.append(e)
        pathdirs, pathfiles, parents, dirname = repository.list_directory(path)
        return render_to_response(template,
                                  {'repository': repository,
                                   'base_template': base_template,
                                   'path': path,
                                   'files': files,
                                   'parents': parents,
                                   'dirs': dirs,
                                   'docs': docs,
                                   'url_prefix': url_prefix,
                                  },
                                  context_instance=RequestContext(request))
    elif action == 'rename':
        repository.rename_elems(path, elems, old_elems)
        send_info(request, _('Elements renamed successfully'))
        return HttpResponseRedirect(filebrowser_reverse(request, "filebrowser_dir_listing",
                        kwargs={'repository_name': repository.name,
                                'path': path},
                        url_prefix=url_prefix))
    elif action == 'delete':
        repository.delete_elems(path, elems)
        send_info(request, _('Elements deleted successfully'))
        return HttpResponseRedirect(filebrowser_reverse(request, "filebrowser_dir_listing",
                        kwargs={'repository_name': repository.name,
                                'path': path},
                        url_prefix=url_prefix))
    else:
        return Http404