def projects_json(request): projects = get_user_projects(request, request.user.username) data = { 'projects': projects, 'user': get_user_data(request.user) } return JsonResponse(data, safe=False)
def user_projects(request, username): data = {} if not request.user.is_authenticated() or request.user.is_guest: data['status'] = 401 else: if not username: redirect_url = reverse( 'userpage:user_projects', kwargs={'username': request.user.username} ) return HttpResponseRedirect(redirect_url) if username == request.user.username or request.user.is_superuser: # projects = [{ # 'title': _('Empty Project'), # 'url': request.build_absolute_uri('/'), # }] # projects.extend(get_user_projects(request, username)) projects = get_user_projects(request, username) data.update({ 'username': username, 'projects': projects, 'gislab_version': webgis.VERSION, 'gislab_homepage': settings.GISQUICK_HOMEPAGE, 'gislab_documentation': settings.GISQUICK_DOCUMENTATION_PAGE, 'user': get_user_data(request.user), 'status': 200 }) else: try: request.user = models.GisquickUser.objects.get(username=username) except models.GisquickUser.DoesNotExist: return HttpResponse( "User does not exist.", content_type='text/plain', status=403 ) data['status'] = 403 templateData = { 'data': data, 'jsonData': json.dumps(data) } return render( request, "userpage/index.html", templateData, content_type="text/html" )
def user_projects(request, username): if not request.user.is_authenticated() or request.user.is_guest: data = { 'status': 401 } else: if not username: redirect_url = app_url(request, user_page_url(request.user.username)) return HttpResponseRedirect(redirect_url) if username == request.user.username or request.user.is_superuser: # projects = [{ # 'title': _('Empty Project'), # 'url': request.build_absolute_uri('/'), # }] # projects.extend(get_user_projects(request, username)) projects = get_user_projects(request, username) data = { 'username': username, 'projects': projects, 'gislab_version': webgis.VERSION, 'gislab_homepage': settings.GISLAB_HOMEPAGE, 'gislab_documentation': settings.GISLAB_DOCUMENTATION_PAGE, 'user': get_user_data(request.user), 'status': 200 } else: try: request.user = models.GislabUser.objects.get(username=username) except models.GislabUser.DoesNotExist: return HttpResponse( "User does not exist.", content_type='text/plain', status=403 ) data = { 'status': 403 } templateData = { 'data': data, 'jsonData': json.dumps(data) } return render( request, "viewer/user_home.html", templateData, content_type="text/html" )
def user_projects(request, username): if not request.user.is_authenticated() or request.user.is_guest: # redirect to login page login_url = secure_url(request, reverse('login')) return HttpResponseRedirect( set_query_parameters(login_url, {'next': secure_url(request)})) if not username: redirect_url = user_projects_url(request.user.username) return HttpResponseRedirect(redirect_url) if username != request.user.username: if not request.user.is_superuser: return HttpResponse( "Access Denied", content_type='text/plain', status=403 ) else: try: request.user = models.GislabUser.objects.get(username=username) except models.GislabUser.DoesNotExist: return HttpResponse( "User does not exist.", content_type='text/plain', status=403 ) projects = [{ 'title': _('Empty Project'), 'url': request.build_absolute_uri('/'), }] projects.extend(get_user_projects(request, username)) context = { 'username': username, 'projects': projects, 'debug': settings.DEBUG } return render( request, "viewer/user_projects.html", context, content_type="text/html" )