Exemplo n.º 1
0
def show_group_list(request, object_type='projects', identity=None, return_message=None):
    """
    The landing page in the "profile" section of Local Ground, where the user
    gets to view the projects/views to which s/he is authorized.
    """
    from localground.account.models import Project, View
    context = RequestContext(request)
    r = request.GET or request.POST
    object_list, object_name = None, None
    ModelClass = Form_LU.get(object_type).get('model_class')
    if request.POST:
        return_message = _batch_update(request, ModelClass, identity)
    object_list = ModelClass.objects.get_objects_with_counts(identity, ordering='id')
    group_object = ModelClass()
    context.update({
        'username': identity.username if identity is not None else 'all',
        'object_list': object_list,
        'group_object': group_object,
        'raw_url': '/profile/%s/' % object_type, #todo: deprecate
        'url': '/profile/%s/' % object_type,
        'url_raw': '/profile/%s/' % object_type, #todo: deprecate
        'object_type': object_type
    })
    if return_message is not None:
        context.update({ 'return_message': return_message })
    if request.user.is_superuser or context.get('is_impersonation'):
        context.update({'users': Project.get_users()})
    context.update(prep_paginator(request, object_list))
    return render_to_response('groups.html', context)
Exemplo n.º 2
0
def get_objects(request, object_type, identity=None, project=None, return_message=None):
    context = RequestContext(request)
    r = request.GET or request.POST
    is_barcoded = (object_type == 'map-image' or object_type == 'attachment')
    objects = None
    class_name, template_name = _get_object_variables(object_type)
    if class_name is None:
        return HttpResponse('object_type "%s" is invalid' % (object_type))
     
    #update form values, if form post:   
    if request.POST:
        return_message = _batch_update(request, object_type, class_name, identity)
     
    ordering_field = None #'-id'   
    if project is not None:
        objects = class_name.objects.by_project(project, ordering_field=ordering_field)
    else:
        objects = class_name.objects.get_all(ordering_field=ordering_field, user=identity)
        #if identity is not None:
        #    objects = objects.filter(owner=identity)
    username = identity.username if identity is not None else 'all'
    projects = Project.objects.get_objects(identity)
    if request.user.is_superuser and username == 'all':
        projects = Project.objects.all().order_by('name')
    project_id = 'all'
    if project is not None: project_id = str(project.id)
    
    context.update({
        'username': username,
        'url': '/profile/%s/?a=a' % object_type,
        #'project_url': '/profile/%s/?alias=%s' % (object_type, username),
        #'user_url': '/profile/%s/?project_id=%s' % (object_type, project_id),
        'raw_url': '/profile/%s/' % (object_type),
        'projects': projects,
        'selected_project': project,
        'selected_project_id': project_id,
        'object_type': object_type.replace('-', ' ')
    })
    if is_barcoded:
        context.update({ 'statuses': StatusCode.objects.all().order_by('id') })    
    if return_message is not None:
        context.update({ 'return_message': return_message })
    if request.user.is_superuser or context.get('is_impersonation'):
        context.update({'users': Project.get_users()})
    context.update(prep_paginator(request, objects))
    return render_to_response(template_name, context)
Exemplo n.º 3
0
def get_objects(request,
                identity=None,
                project=None,
                return_message=None,
                format_type='table'):
    context = RequestContext(request)
    r = request.GET or request.POST
    objects = None
    object_type = 'tables'
    template_name = 'profile/tables.html'
    is_blank = r.get('is_blank', False) in ['1', 'True', 'true']

    #query for user, forms, and projects:
    username = identity.username if identity is not None else 'all'

    forms, projects = None, None
    if request.user.is_superuser and username == 'all':
        projects = Project.objects.all().order_by('name')
        forms = Form.objects.all_forms()
    else:
        projects = Project.objects.get_objects(identity)
        forms = Form.objects.my_forms(user=identity)
    project_id = 'all'
    if project is not None: project_id = str(project.id)

    form_id = int(
        r.get('form_id',
              request.COOKIES.get('form_id_' + request.user.username, -1)))
    form = None
    try:
        if form_id != -1:
            form = Form.objects.get(id=form_id)
    except Form.DoesNotExist:
        form = None
        #context.update(dict(message='Form ID #%s not found' % form_id))
    if form is None and len(forms) > 0:
        form = forms[0]
    records = []
    if form is not None:
        attachment = None
        if r.get('attachment_id') is not None:
            try:
                attachment = Attachment.objects.get(
                    id=int(r.get('attachment_id')))
            except:
                attachment = None
        records = form.get_data(project=project,
                                identity=identity,
                                is_blank=is_blank,
                                has_geometry=False,
                                attachment=attachment)

    #build urls (for restful interface):
    url = '/profile/%s/?is_blank=%s&format_type=%s' % (object_type, is_blank,
                                                       format_type)
    context.update({
        'username':
        username,
        'url':
        url,
        'raw_url':
        '/profile/%s/' % (object_type),
        'projects':
        list(projects),
        'form':
        form,
        'forms':
        list(forms),
        'selected_project':
        project,
        'selected_project_id':
        project_id,
        'object_type':
        'table',
        'format_type':
        format_type,
        'is_blank':
        is_blank,
        'style':
        r.get('style',
              request.COOKIES.get('style_' + request.user.username, 'default'))
    })
    if return_message is not None:
        context.update({'return_message': return_message})
    if request.user.is_superuser:
        context.update({'users': Project.get_users()})
    context.update(prep_paginator(request, records))
    return render_to_response(template_name, context)
Exemplo n.º 4
0
def get_objects(request, identity=None, project=None, return_message=None,
                    format_type='table'):
    context = RequestContext(request)
    r = request.GET or request.POST
    objects = None
    object_type = 'tables'
    template_name = 'profile/tables.html'
    is_blank = r.get('is_blank', False) in ['1', 'True', 'true']
    
    #query for user, forms, and projects:
    username = identity.username if identity is not None else 'all'
     
    forms, projects = None, None
    if request.user.is_superuser and username == 'all':
        projects = Project.objects.all().order_by('name')
        forms = Form.objects.all_forms()
    else:
        projects = Project.objects.get_objects(identity)
        forms = Form.objects.my_forms(user=identity)
    project_id = 'all'
    if project is not None: project_id = str(project.id)
    
    form_id = int(r.get('form_id', request.COOKIES.get('form_id_' + request.user.username, -1)))
    form = None
    try:
        if form_id != -1:
            form = Form.objects.get(id=form_id)
    except Form.DoesNotExist:
        form = None
        #context.update(dict(message='Form ID #%s not found' % form_id))
    if form is None and len(forms) > 0:
        form = forms[0] 
    records = []
    if form is not None:
        attachment = None
        if r.get('attachment_id') is not None:
            try:
                attachment = Attachment.objects.get(id=int(r.get('attachment_id')))
            except:
                attachment = None
        records = form.get_data(project=project, identity=identity,
                                    is_blank=is_blank, has_geometry=False,
                                    attachment=attachment)
    
    #build urls (for restful interface):
    url = '/profile/%s/?is_blank=%s&format_type=%s' % (object_type, is_blank, format_type)
    context.update({
        'username': username,
        'url': url,
        'raw_url': '/profile/%s/' % (object_type),
        'projects': list(projects),
        'form': form,
        'forms': list(forms),
        'selected_project': project,
        'selected_project_id': project_id,
        'object_type': 'table',
        'format_type': format_type,
        'is_blank': is_blank,
        'style': r.get('style',
                    request.COOKIES.get('style_' + request.user.username, 'default'))
    })
    if return_message is not None:
        context.update({ 'return_message': return_message })
    if request.user.is_superuser:
        context.update({'users': Project.get_users()})
    context.update(prep_paginator(request, records))
    return render_to_response(template_name, context)