mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-19 18:29:23 +00:00
Removed class-based view in group creation
This commit is contained in:
168
group/views.py
168
group/views.py
@@ -43,140 +43,52 @@ from seahub.utils import render_error, render_permission_error, \
|
|||||||
from seahub.views import is_registered_user
|
from seahub.views import is_registered_user
|
||||||
from seahub.forms import RepoCreateForm, SharedRepoCreateForm
|
from seahub.forms import RepoCreateForm, SharedRepoCreateForm
|
||||||
|
|
||||||
class GroupMixin(object):
|
@login_required
|
||||||
def get_username(self):
|
def group_list(request):
|
||||||
return self.request.user.username
|
username = request.user.username
|
||||||
|
|
||||||
def ajax_form_valid(self):
|
if request.method == 'POST':
|
||||||
return HttpResponse(json.dumps({'success': True}),
|
"""
|
||||||
content_type='application/json; charset=utf-8')
|
Add a new group.
|
||||||
|
"""
|
||||||
def ajax_form_invalid(self, form):
|
|
||||||
return HttpResponseBadRequest(
|
|
||||||
json.dumps(form.errors),
|
|
||||||
content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
def is_dept_group(self, group_id):
|
|
||||||
try:
|
|
||||||
BusinessGroup.objects.get(group_id=group_id, group_type='dept')
|
|
||||||
ret = True
|
|
||||||
except BusinessGroup.DoesNotExist:
|
|
||||||
ret = False
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def is_proj_group(self, group_id):
|
|
||||||
try:
|
|
||||||
BusinessGroup.objects.get(group_id=group_id, group_type='proj')
|
|
||||||
ret = True
|
|
||||||
except BusinessGroup.DoesNotExist:
|
|
||||||
ret = False
|
|
||||||
return ret
|
|
||||||
|
|
||||||
class GroupListView(LoginRequiredMixin, GroupMixin, TemplateResponseMixin,
|
|
||||||
BaseFormView):
|
|
||||||
template_name = 'group/groups.html'
|
|
||||||
form_class = GroupAddForm
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
group_name = form.cleaned_data['group_name']
|
|
||||||
username = self.get_username()
|
|
||||||
result = {}
|
result = {}
|
||||||
|
content_type = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
if self.request.cloud_mode:
|
form = GroupAddForm(request.POST)
|
||||||
# Check whether group name is duplicated in groups he joined and
|
if form.is_valid():
|
||||||
# created.
|
group_name = form.cleaned_data['group_name']
|
||||||
checked_groups = get_personal_groups_by_user(username)
|
|
||||||
|
# Check whether group name is duplicated.
|
||||||
|
if request.cloud_mode:
|
||||||
|
checked_groups = get_personal_groups_by_user(username)
|
||||||
|
else:
|
||||||
|
checked_groups = get_personal_groups(-1, -1)
|
||||||
|
for g in checked_groups:
|
||||||
|
if g.group_name == group_name:
|
||||||
|
result['error'] = _(u'There is already a group with that name.')
|
||||||
|
return HttpResponse(json.dumps(result), status=400,
|
||||||
|
content_type=content_type)
|
||||||
|
|
||||||
|
# Group name is valid, create that group.
|
||||||
|
try:
|
||||||
|
ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
||||||
|
username)
|
||||||
|
return HttpResponse(json.dumps({'success': True}),
|
||||||
|
content_type=content_type)
|
||||||
|
except SearpcError, e:
|
||||||
|
result['error'] = _(e.msg)
|
||||||
|
return HttpResponse(json.dumps(result), status=500,
|
||||||
|
content_type=content_type)
|
||||||
else:
|
else:
|
||||||
# Check whether group name is duplicated in all groups.
|
return HttpResponseBadRequest(json.dumps(form.errors),
|
||||||
checked_groups = get_personal_groups(-1, -1)
|
content_type=content_type)
|
||||||
for g in checked_groups:
|
|
||||||
if g.group_name == group_name:
|
|
||||||
result['error'] = _(u'There is already a group with that name.')
|
|
||||||
return HttpResponse(json.dumps(result), status=400,
|
|
||||||
content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
try:
|
### GET ###
|
||||||
group_id = ccnet_threaded_rpc.create_group(
|
joined_groups = get_personal_groups_by_user(username)
|
||||||
group_name.encode('utf-8'), username)
|
|
||||||
except SearpcError, e:
|
|
||||||
result['error'] = _(e.msg)
|
|
||||||
return HttpResponse(json.dumps(result), status=500,
|
|
||||||
content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
if self.request.is_ajax():
|
return render_to_response('group/groups.html', {
|
||||||
return self.ajax_form_valid()
|
'joined_groups': joined_groups,
|
||||||
else:
|
}, context_instance=RequestContext(request))
|
||||||
return FormMixin.form_valid(self, form)
|
|
||||||
|
|
||||||
def form_invalid(self, form):
|
|
||||||
if self.request.is_ajax():
|
|
||||||
return self.ajax_form_invalid(form)
|
|
||||||
else:
|
|
||||||
return FormMixin.form_invalid(self, form)
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
kwargs['joined_groups'] = get_personal_groups_by_user(self.get_username())
|
|
||||||
return kwargs
|
|
||||||
|
|
||||||
# class DeptGroupListView(GroupListView):
|
|
||||||
# template_name = 'group/dept_groups.html'
|
|
||||||
|
|
||||||
# def form_valid(self, form):
|
|
||||||
# group_name = form.cleaned_data['group_name']
|
|
||||||
# username = self.get_username()
|
|
||||||
# try:
|
|
||||||
# group_id = ccnet_threaded_rpc.create_group(
|
|
||||||
# group_name.encode('utf-8'), username)
|
|
||||||
# bg = BusinessGroup()
|
|
||||||
# bg.group_id = group_id
|
|
||||||
# bg.group_type = 'dept'
|
|
||||||
# bg.save()
|
|
||||||
# except SearpcError, e:
|
|
||||||
# result = {}
|
|
||||||
# result['error'] = _(e.msg)
|
|
||||||
# return HttpResponse(json.dumps(result),
|
|
||||||
# content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
# if self.request.is_ajax():
|
|
||||||
# return self.ajax_form_valid()
|
|
||||||
# else:
|
|
||||||
# return FormMixin.form_valid(self, form)
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# groups = [ g for g in get_personal_groups_by_user(self.get_username()) \
|
|
||||||
# if self.is_dept_group(g.id)]
|
|
||||||
# kwargs['groups'] = groups
|
|
||||||
# return kwargs
|
|
||||||
|
|
||||||
# class ProjGroupListView(GroupListView):
|
|
||||||
# template_name = 'group/proj_groups.html'
|
|
||||||
|
|
||||||
# def form_valid(self, form):
|
|
||||||
# group_name = form.cleaned_data['group_name']
|
|
||||||
# username = self.get_username()
|
|
||||||
# try:
|
|
||||||
# group_id = ccnet_threaded_rpc.create_group(
|
|
||||||
# group_name.encode('utf-8'), username)
|
|
||||||
# bg = BusinessGroup()
|
|
||||||
# bg.group_id = group_id
|
|
||||||
# bg.group_type = 'proj'
|
|
||||||
# bg.save()
|
|
||||||
# except SearpcError, e:
|
|
||||||
# result = {}
|
|
||||||
# result['error'] = _(e.msg)
|
|
||||||
# return HttpResponse(json.dumps(result),
|
|
||||||
# content_type='application/json; charset=utf-8')
|
|
||||||
|
|
||||||
# if self.request.is_ajax():
|
|
||||||
# return self.ajax_form_valid()
|
|
||||||
# else:
|
|
||||||
# return FormMixin.form_valid(self, form)
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# groups = [ g for g in get_personal_groups_by_user(self.get_username()) \
|
|
||||||
# if self.is_proj_group(g.id)]
|
|
||||||
# kwargs['groups'] = groups
|
|
||||||
# return kwargs
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def group_remove(request, group_id):
|
def group_remove(request, group_id):
|
||||||
|
@@ -25,7 +25,6 @@ from decorators import org_staff_required
|
|||||||
from forms import OrgCreateForm
|
from forms import OrgCreateForm
|
||||||
from signals import org_user_added
|
from signals import org_user_added
|
||||||
from utils import validate_org_repo_owner
|
from utils import validate_org_repo_owner
|
||||||
from group.views import GroupListView
|
|
||||||
from notifications.models import UserNotification
|
from notifications.models import UserNotification
|
||||||
from profile.models import Profile
|
from profile.models import Profile
|
||||||
from share.models import FileShare
|
from share.models import FileShare
|
||||||
|
4
urls.py
4
urls.py
@@ -4,7 +4,7 @@ from django.views.generic.simple import direct_to_template
|
|||||||
|
|
||||||
from seahub.views import *
|
from seahub.views import *
|
||||||
from notifications.views import notification_list
|
from notifications.views import notification_list
|
||||||
from group.views import GroupListView
|
from group.views import group_list
|
||||||
|
|
||||||
# Uncomment the next two lines to enable the admin:
|
# Uncomment the next two lines to enable the admin:
|
||||||
#from django.contrib import admin
|
#from django.contrib import admin
|
||||||
@@ -82,7 +82,7 @@ urlpatterns = patterns('',
|
|||||||
url(r'^sys/notificationadmin/', notification_list, name='notification_list'),
|
url(r'^sys/notificationadmin/', notification_list, name='notification_list'),
|
||||||
(r'^contacts/', include('contacts.urls')),
|
(r'^contacts/', include('contacts.urls')),
|
||||||
(r'^group/', include('seahub.group.urls')),
|
(r'^group/', include('seahub.group.urls')),
|
||||||
url(r'^groups/', GroupListView.as_view(), name='group_list'),
|
url(r'^groups/', group_list, name='group_list'),
|
||||||
(r'^profile/', include('seahub.profile.urls')),
|
(r'^profile/', include('seahub.profile.urls')),
|
||||||
(r'^share/', include('share.urls')),
|
(r'^share/', include('share.urls')),
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user