mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 08:53:14 +00:00
Clean business group add
This commit is contained in:
@@ -6,7 +6,11 @@ and returns a dictionary to add to the context.
|
|||||||
These are referenced from the setting TEMPLATE_CONTEXT_PROCESSORS and used by
|
These are referenced from the setting TEMPLATE_CONTEXT_PROCESSORS and used by
|
||||||
RequestContext.
|
RequestContext.
|
||||||
"""
|
"""
|
||||||
from settings import SEAFILE_VERSION, SEAHUB_TITLE, BUSINESS_MODE
|
from settings import SEAFILE_VERSION, SEAHUB_TITLE
|
||||||
|
try:
|
||||||
|
from settings import BUSINESS_MODE
|
||||||
|
except ImportError:
|
||||||
|
BUSINESS_MODE = False
|
||||||
|
|
||||||
def base(request):
|
def base(request):
|
||||||
"""
|
"""
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
|
# encoding: utf-8
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
from seahub.utils import validate_group_name
|
||||||
|
|
||||||
class MessageForm(forms.Form):
|
class MessageForm(forms.Form):
|
||||||
message = forms.CharField(max_length=500)
|
message = forms.CharField(max_length=500)
|
||||||
|
|
||||||
@@ -16,3 +19,19 @@ class GroupRecommendForm(MessageForm):
|
|||||||
repo_id = forms.CharField(max_length=40)
|
repo_id = forms.CharField(max_length=40)
|
||||||
path = forms.CharField()
|
path = forms.CharField()
|
||||||
attach_type = forms.CharField(max_length=5)
|
attach_type = forms.CharField(max_length=5)
|
||||||
|
|
||||||
|
class GroupAddForm(forms.Form):
|
||||||
|
"""
|
||||||
|
A form used to add a new group.
|
||||||
|
"""
|
||||||
|
group_name = forms.CharField(max_length=255, error_messages={
|
||||||
|
'required': u'小组名称不能为空',
|
||||||
|
'max_length': u'小组名称太长,不超过255个字符',
|
||||||
|
})
|
||||||
|
def clean_group_name(self):
|
||||||
|
group_name = self.cleaned_data['group_name']
|
||||||
|
if not validate_group_name(group_name):
|
||||||
|
error_msg = u'小组名称只能包含中英文字符,数字及下划线。'
|
||||||
|
raise forms.ValidationError(error_msg)
|
||||||
|
else:
|
||||||
|
return group_name
|
||||||
|
@@ -8,7 +8,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
<!-- 我的小组 -->
|
<!-- 部门 -->
|
||||||
|
<h3>部门</h3>
|
||||||
{% include "group/groups_right_panel.html" %}
|
{% include "group/groups_right_panel.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
<!-- 我的小组 -->
|
<!-- 我的小组 -->
|
||||||
|
<h3>我的小组</h3>
|
||||||
{% include "group/groups_right_panel.html" %}
|
{% include "group/groups_right_panel.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
{% load seahub_tags group_avatar_tags %}
|
{% load seahub_tags group_avatar_tags %}
|
||||||
{% load url from future %}
|
{% load url from future %}
|
||||||
|
|
||||||
<h3>我的小组</h3>
|
|
||||||
{% if groups %}
|
{% if groups %}
|
||||||
<ul class="group-list w100 ovhd">
|
<ul class="group-list w100 ovhd">
|
||||||
{% for group in groups %}
|
{% for group in groups %}
|
||||||
|
@@ -8,7 +8,8 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block right_panel %}
|
{% block right_panel %}
|
||||||
<!-- 我的小组 -->
|
<!-- 项目组 -->
|
||||||
|
<h3>项目组</h3>
|
||||||
{% include "group/groups_right_panel.html" %}
|
{% include "group/groups_right_panel.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
from views import group_list, group_info, group_member_operations, \
|
from views import group_info, group_member_operations, \
|
||||||
group_members, msg_reply, msg_reply_new, group_recommend, \
|
group_members, msg_reply, msg_reply_new, group_recommend, \
|
||||||
create_group_repo
|
create_group_repo
|
||||||
|
|
||||||
|
164
group/views.py
164
group/views.py
@@ -10,6 +10,8 @@ from django.template import RequestContext
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.http import urlquote
|
from django.utils.http import urlquote
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.views.generic.base import TemplateResponseMixin
|
||||||
|
from django.views.generic.edit import BaseFormView, FormMixin
|
||||||
|
|
||||||
from auth.decorators import login_required
|
from auth.decorators import login_required
|
||||||
from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \
|
from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \
|
||||||
@@ -19,9 +21,11 @@ from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \
|
|||||||
from pysearpc import SearpcError
|
from pysearpc import SearpcError
|
||||||
|
|
||||||
from models import GroupMessage, MessageReply, MessageAttachment, BusinessGroup
|
from models import GroupMessage, MessageReply, MessageAttachment, BusinessGroup
|
||||||
from forms import MessageForm, MessageReplyForm, GroupRecommendForm
|
from forms import MessageForm, MessageReplyForm, GroupRecommendForm, \
|
||||||
|
GroupAddForm
|
||||||
from signals import grpmsg_added, grpmsg_reply_added
|
from signals import grpmsg_added, grpmsg_reply_added
|
||||||
from base.decorators import ctx_switch_required
|
from base.decorators import ctx_switch_required
|
||||||
|
from base.mixins import LoginRequiredMixin
|
||||||
from seahub.contacts.models import Contact
|
from seahub.contacts.models import Contact
|
||||||
from seahub.contacts.signals import mail_sended
|
from seahub.contacts.signals import mail_sended
|
||||||
from seahub.notifications.models import UserNotification
|
from seahub.notifications.models import UserNotification
|
||||||
@@ -34,36 +38,20 @@ 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
|
from seahub.forms import RepoCreateForm
|
||||||
|
|
||||||
@login_required
|
class GroupMixin(object):
|
||||||
def group_list(request):
|
def get_username(self):
|
||||||
if request.method == 'POST':
|
return self.request.user.username
|
||||||
"""
|
|
||||||
Add new group.
|
|
||||||
"""
|
|
||||||
result = {}
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
|
||||||
|
|
||||||
group_name = request.POST.get('group_name')
|
def ajax_form_valid(self):
|
||||||
if not validate_group_name(group_name):
|
|
||||||
result['error'] = u'小组名称只能包含中英文字符,数字及下划线。'
|
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
||||||
|
|
||||||
try:
|
|
||||||
group_id = ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
|
||||||
request.user.username)
|
|
||||||
except SearpcError, e:
|
|
||||||
result['error'] = _(e.msg)
|
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
||||||
return HttpResponse(json.dumps({'success': True}),
|
return HttpResponse(json.dumps({'success': True}),
|
||||||
content_type=content_type)
|
content_type='application/json; charset=utf-8')
|
||||||
|
|
||||||
groups = get_personal_groups(request.user.username);
|
def ajax_form_invalid(self, form):
|
||||||
|
return HttpResponseBadRequest(
|
||||||
|
json.dumps(form.errors),
|
||||||
|
content_type='application/json; charset=utf-8')
|
||||||
|
|
||||||
return render_to_response("group/groups.html", {
|
def is_dept_group(self, group_id):
|
||||||
"groups": groups,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
def is_dept_group(group_id):
|
|
||||||
try:
|
try:
|
||||||
BusinessGroup.objects.get(group_id=group_id, group_type='dept')
|
BusinessGroup.objects.get(group_id=group_id, group_type='dept')
|
||||||
ret = True
|
ret = True
|
||||||
@@ -71,7 +59,7 @@ def is_dept_group(group_id):
|
|||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def is_proj_group(group_id):
|
def is_proj_group(self, group_id):
|
||||||
try:
|
try:
|
||||||
BusinessGroup.objects.get(group_id=group_id, group_type='proj')
|
BusinessGroup.objects.get(group_id=group_id, group_type='proj')
|
||||||
ret = True
|
ret = True
|
||||||
@@ -79,73 +67,97 @@ def is_proj_group(group_id):
|
|||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@login_required
|
class GroupListView(LoginRequiredMixin, GroupMixin, TemplateResponseMixin,
|
||||||
def dept_group_list(request):
|
BaseFormView):
|
||||||
if request.method == 'POST':
|
template_name = 'group/groups.html'
|
||||||
"""
|
form_class = GroupAddForm
|
||||||
Add new department group.
|
|
||||||
"""
|
|
||||||
result = {}
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
|
||||||
|
|
||||||
group_name = request.POST.get('group_name')
|
|
||||||
if not validate_group_name(group_name):
|
|
||||||
result['error'] = u'小组名称只能包含中英文字符,数字及下划线。'
|
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
group_name = form.cleaned_data['group_name']
|
||||||
|
username = self.get_username()
|
||||||
try:
|
try:
|
||||||
group_id = ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
group_id = ccnet_threaded_rpc.create_group(
|
||||||
request.user.username)
|
group_name.encode('utf-8'), username)
|
||||||
|
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 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['groups'] = get_personal_groups(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 = BusinessGroup()
|
||||||
bg.group_id = group_id
|
bg.group_id = group_id
|
||||||
bg.group_type = 'dept'
|
bg.group_type = 'dept'
|
||||||
bg.save()
|
bg.save()
|
||||||
except SearpcError, e:
|
except SearpcError, e:
|
||||||
result['error'] = _(e.msg)
|
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
|
||||||
return HttpResponse(json.dumps({'success': True}),
|
|
||||||
content_type=content_type)
|
|
||||||
|
|
||||||
groups = [ g for g in get_personal_groups(request.user.username) \
|
|
||||||
if is_dept_group(g.id)]
|
|
||||||
|
|
||||||
return render_to_response("group/dept_groups.html", {
|
|
||||||
"groups": groups,
|
|
||||||
}, context_instance=RequestContext(request))
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def proj_group_list(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
"""
|
|
||||||
Add new department group.
|
|
||||||
"""
|
|
||||||
result = {}
|
result = {}
|
||||||
content_type = 'application/json; charset=utf-8'
|
result['error'] = _(e.msg)
|
||||||
|
return HttpResponse(json.dumps(result),
|
||||||
|
content_type='application/json; charset=utf-8')
|
||||||
|
|
||||||
group_name = request.POST.get('group_name')
|
if self.request.is_ajax():
|
||||||
if not validate_group_name(group_name):
|
return self.ajax_form_valid()
|
||||||
result['error'] = u'小组名称只能包含中英文字符,数字及下划线。'
|
else:
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
return FormMixin.form_valid(self, form)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
groups = [ g for g in get_personal_groups(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:
|
try:
|
||||||
group_id = ccnet_threaded_rpc.create_group(group_name.encode('utf-8'),
|
group_id = ccnet_threaded_rpc.create_group(
|
||||||
request.user.username)
|
group_name.encode('utf-8'), username)
|
||||||
bg = BusinessGroup()
|
bg = BusinessGroup()
|
||||||
bg.group_id = group_id
|
bg.group_id = group_id
|
||||||
bg.group_type = 'proj'
|
bg.group_type = 'proj'
|
||||||
bg.save()
|
bg.save()
|
||||||
except SearpcError, e:
|
except SearpcError, e:
|
||||||
|
result = {}
|
||||||
result['error'] = _(e.msg)
|
result['error'] = _(e.msg)
|
||||||
return HttpResponse(json.dumps(result), content_type=content_type)
|
return HttpResponse(json.dumps(result),
|
||||||
return HttpResponse(json.dumps({'success': True}),
|
content_type='application/json; charset=utf-8')
|
||||||
content_type=content_type)
|
|
||||||
|
|
||||||
groups = [ g for g in get_personal_groups(request.user.username) \
|
if self.request.is_ajax():
|
||||||
if is_proj_group(g.id)]
|
return self.ajax_form_valid()
|
||||||
|
else:
|
||||||
|
return FormMixin.form_valid(self, form)
|
||||||
|
|
||||||
return render_to_response("group/proj_groups.html", {
|
def get_context_data(self, **kwargs):
|
||||||
"groups": groups,
|
groups = [ g for g in get_personal_groups(self.get_username()) \
|
||||||
}, context_instance=RequestContext(request))
|
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):
|
||||||
|
@@ -202,8 +202,6 @@ SEAHUB_TITLE = 'SeaHub'
|
|||||||
|
|
||||||
USE_SUBDOMAIN = False
|
USE_SUBDOMAIN = False
|
||||||
|
|
||||||
BUSINESS_MODE = True
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import local_settings
|
import local_settings
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% if business_mode %}
|
{% if business_mode %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'dept_group_list' %}" {% block nav_deptgroup_class %}{% endblock %}>部门组</a>
|
<a href="{% url 'dept_group_list' %}" {% block nav_deptgroup_class %}{% endblock %}>部门</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'proj_group_list' %}" {% block nav_projgroup_class %}{% endblock %}>项目组</a>
|
<a href="{% url 'proj_group_list' %}" {% block nav_projgroup_class %}{% endblock %}>项目组</a>
|
||||||
|
8
urls.py
8
urls.py
@@ -5,7 +5,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 share.views import share_admin
|
from share.views import share_admin
|
||||||
from group.views import group_list, dept_group_list, proj_group_list
|
from group.views import GroupListView, DeptGroupListView, ProjGroupListView
|
||||||
|
|
||||||
# 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
|
||||||
@@ -88,9 +88,9 @@ 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/', group_list, name='group_list'),
|
url(r'^groups/', GroupListView.as_view(), name='group_list'),
|
||||||
url(r'^deptgroups/', dept_group_list, name='dept_group_list'),
|
url(r'^deptgroups/', DeptGroupListView.as_view(), name='dept_group_list'),
|
||||||
url(r'^projgroups/', proj_group_list, name='proj_group_list'),
|
url(r'^projgroups/', ProjGroupListView.as_view(), name='proj_group_list'),
|
||||||
(r'^organizations/', include('seahub.organizations.urls')),
|
(r'^organizations/', include('seahub.organizations.urls')),
|
||||||
(r'^profile/', include('seahub.profile.urls')),
|
(r'^profile/', include('seahub.profile.urls')),
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user