diff --git a/organizations/context_processors.py b/organizations/context_processors.py index a74f5b7c7a..4f30518c5a 100644 --- a/organizations/context_processors.py +++ b/organizations/context_processors.py @@ -1,16 +1,12 @@ +from seahub.utils import get_cur_ctx + def org(request): """ Add org info and base template that html page will extends to context. """ - if hasattr(request.user, 'org') and request.user.org is not None: - if request.user.org['is_staff']: - base_template = 'org_admin_base.html' - else: - base_template = 'org_base.html' - return {'cur_ctx': 'org', - 'org': request.user.org, - 'base_template': base_template} - else: - return {'cur_ctx': '', - 'base_template': 'myhome_base.html'} - + ctx_dict = get_cur_ctx(request) + base_template = ctx_dict['base_template'] + org_dict = ctx_dict['org_dict'] + return {'base_template': base_template, + 'org': org_dict} + diff --git a/organizations/middleware.py b/organizations/middleware.py index 2e7c52591d..567339d74f 100644 --- a/organizations/middleware.py +++ b/organizations/middleware.py @@ -3,11 +3,11 @@ from django.http import HttpResponseRedirect from seaserv import get_org_by_url_prefix, get_orgs_by_user -from settings import ORG_CACHE_PREFIX try: from seahub.settings import CLOUD_MODE except ImportError: CLOUD_MODE = False +from seahub.utils import get_cur_ctx class OrganizationMiddleware(object): """ @@ -20,8 +20,8 @@ class OrganizationMiddleware(object): request.cloud_mode = True # Get current org context - org = cache.get(ORG_CACHE_PREFIX + request.user.username) - request.user.org = org + ctx_dict = get_cur_ctx(request) + request.user.org = ctx_dict.get('org_dict', None) # Get all orgs user created. orgs = get_orgs_by_user(request.user.username) diff --git a/organizations/settings.py b/organizations/settings.py index f18fa87b54..00719086af 100644 --- a/organizations/settings.py +++ b/organizations/settings.py @@ -1,3 +1 @@ from django.conf import settings - -ORG_CACHE_PREFIX = getattr(settings, 'ORG_CACHE_PREFIX', 'ORGANIZATION_') diff --git a/organizations/templates/organizations/org_info.html b/organizations/templates/organizations/org_info.html index 8fc553aefc..575a8338bd 100644 --- a/organizations/templates/organizations/org_info.html +++ b/organizations/templates/organizations/org_info.html @@ -46,7 +46,7 @@ {% if repo.latest_modify %} {{ repo.latest_modify|translate_commit_time }} {% else %} - —— —— + -- {% endif %} 同步 diff --git a/organizations/templates/organizations/org_useradmin.html b/organizations/templates/organizations/org_useradmin.html index b570978f31..bc4b5ad17f 100644 --- a/organizations/templates/organizations/org_useradmin.html +++ b/organizations/templates/organizations/org_useradmin.html @@ -35,7 +35,7 @@ {{ user.props.email }} {% if not user.is_self %} - + {% endif %} diff --git a/organizations/utils.py b/organizations/utils.py index 7175f67dd1..76f4d8cce4 100644 --- a/organizations/utils.py +++ b/organizations/utils.py @@ -1,23 +1,7 @@ import sys -from django.core.cache import cache -from settings import ORG_CACHE_PREFIX from seaserv import get_org_id_by_repo_id - -def clear_org_ctx(request): - """ - Clear current context. - """ - cache.delete(ORG_CACHE_PREFIX + request.user.username) - request.user.org = None - -def set_org_ctx(request, org_dict): - """ - Set current context to org. - """ - cache.set(ORG_CACHE_PREFIX + request.user.username, org_dict, sys.maxint) - request.user.org = org_dict - + def access_org_repo(request, repo_id): """ Check whether user can view org repo. @@ -28,6 +12,3 @@ def access_org_repo(request, repo_id): cur_org_id = request.user.org['org_id'] org_id = get_org_id_by_repo_id(repo_id) return True if cur_org_id == org_id else False - - - diff --git a/organizations/views.py b/organizations/views.py index 8c8c27c6c9..5eb0941815 100644 --- a/organizations/views.py +++ b/organizations/views.py @@ -19,14 +19,12 @@ from seaserv import ccnet_threaded_rpc, get_orgs_by_user, get_org_repos, \ from forms import OrgCreateForm from signals import org_user_added -from settings import ORG_CACHE_PREFIX -from utils import set_org_ctx from notifications.models import UserNotification from registration.models import RegistrationProfile from seahub.forms import RepoCreateForm import seahub.settings as seahub_settings -from seahub.utils import render_error, render_permission_error, validate_group_name, \ - emails2list, gen_token +from seahub.utils import render_error, render_permission_error, gen_token, \ + validate_group_name, emails2list, set_cur_ctx, calculate_repo_last_modify from seahub.views import myhome @login_required @@ -65,11 +63,15 @@ def org_info(request, url_prefix): if not org: return HttpResponseRedirect(reverse(myhome)) - set_org_ctx(request, org._dict) + ctx_dict = {'base_template': 'org_base.html', + 'org_dict': org._dict} + set_cur_ctx(request, ctx_dict) org_members = ccnet_threaded_rpc.get_org_emailusers(url_prefix, 0, sys.maxint) repos = get_org_repos(org.org_id, 0, sys.maxint) + calculate_repo_last_modify(repos) + repos.sort(lambda x, y: cmp(y.latest_modify, x.latest_modify)) url = 'organizations/%s/repo/create/' % org.url_prefix return render_to_response('organizations/org_info.html', { @@ -139,6 +141,10 @@ def org_useradmin(request, url_prefix): if not request.user.org['is_staff']: raise Http404 + ctx_dict = {'base_template': 'org_admin_base.html', + 'org_dict': request.user.org} + set_cur_ctx(request, ctx_dict) + if request.method == 'POST': emails = request.POST.get('added-member-name') diff --git a/templates/admin_base.html b/templates/admin_base.html index 07534b7474..f4c36981e5 100644 --- a/templates/admin_base.html +++ b/templates/admin_base.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block top_bar_manager_class %} class="cur"{% endblock %} +{% block top_bar_sys_manager_class %} class="cur"{% endblock %} {% block nav %} {% endif %} {% endif %} + + {% if request.user.is_staff %} + 系统管理 + 个人工作台 + {% endif %} - {% if request.user.is_staff or request.user.org.is_staff %} - {% if request.user.is_staff %} - 管理员工作台 - {% if request.user.is_staff %} - 个人工作台 + {% if request.user.org.is_staff %} + 管理员工作台 + 个人工作台 {% endif %} diff --git a/templates/myhome.html b/templates/myhome.html index 5fb715fc01..ce72ce43eb 100644 --- a/templates/myhome.html +++ b/templates/myhome.html @@ -116,7 +116,7 @@ {% if repo.latest_modify %} {{ repo.latest_modify|translate_commit_time }} {% else %} - —— —— + -- {% endif %} 同步 @@ -147,7 +147,7 @@ {% if repo.latest_modify %} {{ repo.latest_modify|translate_commit_time }} {% else %} - —— —— + -- {% endif %} 同步 diff --git a/templates/org_admin_base.html b/templates/org_admin_base.html index f49bdbd8d1..87aae0acec 100644 --- a/templates/org_admin_base.html +++ b/templates/org_admin_base.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block top_bar_manager_class %} class="cur"{% endblock %} +{% block top_bar_org_manager_class %} class="cur"{% endblock %} {% block nav %}