def get_group_msgs(groupid, page, username):
# Show 15 group messages per page.
paginator = Paginator(GroupMessage.objects.filter(group_id=groupid).order_by("-timestamp"), 15)
# If page request (9999) is out of range, return None
try:
group_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
return None
# Force evaluate queryset to fix some database error for mysql.
group_msgs.object_list = list(group_msgs.object_list)
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
reply_to_list = [r.reply_to_id for r in msg_replies]
for msg in group_msgs.object_list:
msg.reply_cnt = reply_to_list.count(msg.id)
msg.replies = []
for r in msg_replies:
if msg.id == r.reply_to_id:
msg.replies.append(r)
msg.replies = msg.replies[-3:]
for att in attachments:
if att.group_message_id != msg.id:
continue
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == "/":
repo = seafile_api.get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
else:
path = path.rstrip("/") # cut out last '/' if possible
att.name = os.path.basename(path)
# Load to discuss page if attachment is a image and from recommend.
if att.attach_type == "file" and att.src == "recommend":
att.filetype, att.fileext = get_file_type_and_ext(att.name)
if att.filetype == IMAGE:
att.obj_id = seafile_api.get_file_id_by_path(att.repo_id, path)
if not att.obj_id:
att.err = "File does not exist"
else:
att.token = seafile_api.get_fileserver_access_token(att.repo_id, att.obj_id, "view", username)
att.img_url = gen_file_get_url(att.token, att.name)
msg.attachment = att
return group_msgs
开发者ID:rominf,项目名称:seahub,代码行数:59,代码来源:utils.py
示例6: view_file_via_shared_dir
def view_file_via_shared_dir(request, token):
assert token is not None # Checked by URLconf
try:
fileshare = FileShare.objects.get(token=token)
except FileShare.DoesNotExist:
raise Http404
shared_by = fileshare.username
repo_id = fileshare.repo_id
repo = get_repo(repo_id)
if not repo:
raise Http404
path = request.GET.get('p', '').rstrip('/')
if not path:
raise Http404
if not path.startswith(fileshare.path): # Can not view upper dir of shared dir
raise Http404
zipped = gen_path_link(path, '')
obj_id = seafile_api.get_file_id_by_path(repo_id, path)
if not obj_id:
return render_error(request, _(u'File does not exist'))
file_size = seafile_api.get_file_size(obj_id)
filename = os.path.basename(path)
filetype, fileext = get_file_type_and_ext(filename)
access_token = seafserv_rpc.web_get_access_token(repo.id, obj_id,
'view', '')
raw_path = gen_file_get_url(access_token, filename)
inner_path = gen_inner_file_get_url(access_token, filename)
# get file content
ret_dict = {'err': '', 'file_content': '', 'encoding': '', 'file_enc': '',
'file_encoding_list': [], 'html_exists': False,
'filetype': filetype}
fsize = get_file_size(obj_id)
exceeds_limit, err_msg = file_size_exceeds_preview_limit(fsize, filetype)
if exceeds_limit:
err = err_msg
else:
"""Choose different approach when dealing with different type of file."""
if is_textual_file(file_type=filetype):
handle_textual_file(request, filetype, inner_path, ret_dict)
elif filetype == DOCUMENT:
handle_document(inner_path, obj_id, fileext, ret_dict)
elif filetype == PDF:
handle_pdf(inner_path, obj_id, fileext, ret_dict)
# send statistic messages
try:
obj_size = seafserv_threaded_rpc.get_file_size(obj_id)
send_message('seahub.stats', 'file-view\t%s\t%s\t%s\t%s' % \
(repo.id, shared_by, obj_id, obj_size))
except SearpcError, e:
logger.error('Error when sending file-view message: %s' % str(e))
开发者ID:swpd,项目名称:seahub,代码行数:58,代码来源:file.py
示例7: allow_generate_thumbnail
def allow_generate_thumbnail(username, repo, f):
# check if thumbnail is allowed
if seafile_api.check_repo_access_permission(repo.id, username) is None:
# user can not access repo
return False
file_type, file_ext = get_file_type_and_ext(f.obj_name)
if not repo.encrypted and file_type == IMAGE and ENABLE_THUMBNAIL \
and f.file_size < THUMBNAIL_IMAGE_SIZE_LIMIT * 1024**2:
return True
else:
return False
def post(self, request):
logo_file = request.FILES.get('logo', None)
if not logo_file:
error_msg = 'Logo can not be found.'
logger.error(error_msg)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
file_type, ext = get_file_type_and_ext(logo_file.name)
if file_type != IMAGE:
error_msg = file_type_error_msg(ext, PREVIEW_FILEEXT.get(IMAGE))
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if logo_file.size > 1024 * 1024 * 20: # 20mb
error_msg = file_size_error_msg(logo_file.size, 20*1024*1024)
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
if not os.path.exists(SEAHUB_DATA_ROOT):
os.makedirs(SEAHUB_DATA_ROOT)
custom_dir = os.path.join(SEAHUB_DATA_ROOT, os.path.dirname(CUSTOM_LOGO_PATH))
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
try:
# save logo file to custom dir
custom_logo_file = os.path.join(SEAHUB_DATA_ROOT, CUSTOM_LOGO_PATH)
image = Image.open(logo_file)
image.save(custom_logo_file)
# create symlink for custom dir
custom_symlink = os.path.join(MEDIA_ROOT, os.path.dirname(CUSTOM_LOGO_PATH))
if not os.path.exists(custom_symlink):
os.symlink(custom_dir, custom_symlink)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({'success': True})
开发者ID:haiwen,项目名称:seahub,代码行数:40,代码来源:logo.py
示例15: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
linkname = matchobj.group(1).strip()
filetype, fileext = get_file_type_and_ext(linkname)
filetype = filetype.lower()
if fileext == '':
# convert linkname that extension is missing to a markdown page
filename = linkname + ".md"
path = "/" + filename
if get_file_id_by_path(repo_id, path):
a_tag = "<a href='%s'>%s</a>"
return a_tag % (reverse('group_wiki', args=[group.id, linkname]), linkname)
else:
a_tag = '''<a class="wiki-page-missing" href='%s'>%s</a>'''
return a_tag % (reverse('group_wiki', args=[group.id, linkname.replace('/', '-')]), linkname)
elif filetype == 'image':
# load image to wiki page
path = "/" + linkname
filename = os.path.basename(path)
obj_id = get_file_id_by_path(repo_id, path)
if not obj_id:
# Replace '/' in linkname to '-', since wiki name can not
# contain '/'.
return '''<a class="wiki-page-missing" href='%s'>%s</a>''' % \
(reverse('group_wiki', args=[group.id, linkname.replace('/', '-')]), linkname)
token = web_get_access_token(repo_id, obj_id, 'view', username)
return '<img src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
else:
from base.templatetags.seahub_tags import file_icon_filter
# convert other types of filelinks to clickable links
path = "/" + linkname
icon = file_icon_filter(linkname)
s = reverse('repo_view_file', args=[repo_id]) + '?p=' + path
a_tag = '''<img src="%simg/file/%s" alt="%s" class="vam" /> <a href='%s' target='_blank' class="vam">%s</a>'''
return a_tag % (MEDIA_URL, icon, icon, s, linkname)
开发者ID:beride,项目名称:seahub,代码行数:39,代码来源:views.py
示例16: repl
def repl(matchobj):
if matchobj.group(2): # return origin string in backquotes
return matchobj.group(2)
page_name = matchobj.group(1).strip()
filetype, fileext = get_file_type_and_ext(page_name)
if fileext == '':
# convert page_name that extension is missing to a markdown page
dirent = get_wiki_dirent(repo_id, page_name)
if dirent is not None:
a_tag = "<a href='%s'>%s</a>"
return a_tag % (url_prefix + '/' + normalize_page_name(page_name), page_name)
else:
a_tag = '''<a class="wiki-page-missing" href='%s'>%s</a>'''
return a_tag % (url_prefix + '/' + page_name.replace('/', '-'), page_name)
elif filetype == IMAGE:
# load image to wiki page
path = "/" + page_name
filename = os.path.basename(path)
obj_id = get_file_id_by_path(repo_id, path)
if not obj_id:
# Replace '/' in page_name to '-', since wiki name can not
# contain '/'.
return '''<a class="wiki-page-missing" href='%s'>%s</a>''' % \
(url_prefix + '/' + page_name.replace('/', '-'), page_name)
token = seaserv.web_get_access_token(repo_id, obj_id, 'view', username)
return '<img src="%s" alt="%s" />' % (gen_file_get_url(token, filename), filename)
else:
from base.templatetags.seahub_tags import file_icon_filter
# convert other types of filelinks to clickable links
path = "/" + page_name
icon = file_icon_filter(page_name)
s = reverse('repo_view_file', args=[repo_id]) + \
'?p=' + urllib2.quote(smart_str(path))
a_tag = '''<img src="%simg/file/%s" alt="%s" class="vam" /> <a href='%s' target='_blank' class="vam">%s</a>'''
return a_tag % (MEDIA_URL, icon, icon, s, page_name)
开发者ID:sonicby,项目名称:seahub,代码行数:38,代码来源:utils.py
示例17: render_repo
def render_repo(request, repo):
"""Steps to show repo page:
If user has permission to view repo
If repo is encrypt and password is not set on server
return decrypt repo page
If repo is not encrypt or password is set on server
Show repo direntries based on requested path
If user does not have permission to view repo
return permission deny page
"""
username = request.user.username
path = get_path_from_request(request)
if not seafile_api.get_dir_id_by_path(repo.id, path):
raise Http404
user_perm = check_repo_access_permission(repo.id, request.user)
if user_perm is None:
return render_to_response('repo_access_deny.html', {
'repo': repo,
}, context_instance=RequestContext(request))
sub_lib_enabled = UserOptions.objects.is_sub_lib_enabled(username)
server_crypto = False
if repo.encrypted:
try:
server_crypto = UserOptions.objects.is_server_crypto(username)
except CryptoOptionNotSetError:
return render_to_response('options/set_user_options.html', {
}, context_instance=RequestContext(request))
if (repo.enc_version == 1 or (repo.enc_version == 2 and server_crypto)) \
and not is_password_set(repo.id, username):
return render_to_response('decrypt_repo_form.html', {
'repo': repo,
'next': get_next_url_from_request(request) or reverse('repo', args=[repo.id]),
'force_server_crypto': FORCE_SERVER_CRYPTO,
}, context_instance=RequestContext(request))
# query context args
fileserver_root = get_fileserver_root()
max_upload_file_size = get_max_upload_file_size()
protocol = request.is_secure() and 'https' or 'http'
domain = RequestSite(request).domain
for g in request.user.joined_groups:
g.avatar = grp_avatar(g.id, 20)
head_commit = get_commit(repo.id, repo.version, repo.head_cmmt_id)
if not head_commit:
raise Http404
if new_merge_with_no_conflict(head_commit):
info_commit = get_commit_before_new_merge(head_commit)
else:
info_commit = head_commit
repo_size = get_repo_size(repo.id)
no_quota = is_no_quota(repo.id)
if is_org_context(request):
repo_owner = seafile_api.get_org_repo_owner(repo.id)
else:
repo_owner = seafile_api.get_repo_owner(repo.id)
is_repo_owner = True if repo_owner == username else False
if is_repo_owner and not repo.is_virtual:
show_repo_settings = True
else:
show_repo_settings = False
more_start = None
file_list, dir_list, dirent_more = get_repo_dirents(request, repo,
head_commit, path,
offset=0, limit=100)
if dirent_more:
more_start = 100
zipped = get_nav_path(path, repo.name)
repo_groups = get_shared_groups_by_repo_and_user(repo.id, username)
if len(repo_groups) > 1:
repo_group_str = render_to_string("snippets/repo_group_list.html",
{'groups': repo_groups})
else:
repo_group_str = ''
upload_url = get_upload_url(request, repo.id)
fileshare = get_fileshare(repo.id, username, path)
dir_shared_link = get_dir_share_link(fileshare)
uploadlink = get_uploadlink(repo.id, username, path)
dir_shared_upload_link = get_dir_shared_upload_link(uploadlink)
if not repo.encrypted and ENABLE_THUMBNAIL:
size = THUMBNAIL_DEFAULT_SIZE
for f in file_list:
file_type, file_ext = get_file_type_and_ext(f.obj_name)
if file_type == IMAGE:
f.is_img = True
if os.path.exists(os.path.join(THUMBNAIL_ROOT, size, f.obj_id)):
f.thumbnail_src = get_thumbnail_src(repo.id, f.obj_id, size)
return render_to_response('repo.html', {
#.........这里部分代码省略.........
开发者ID:ggkitsas,项目名称:seahub,代码行数:101,代码来源:repo.py
示例18: group_discuss
def group_discuss(request, group):
if group.is_pub:
raise Http404
username = request.user.username
form = MessageForm()
# remove user notifications
UserNotification.objects.seen_group_msg_notices(username, group.id)
# Get all group members.
members = get_group_members(group.id)
"""group messages"""
# Show 15 group messages per page.
paginator = Paginator(GroupMessage.objects.filter(group_id=group.id).order_by("-timestamp"), 15)
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get("page", "1"))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
group_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
group_msgs = paginator.page(paginator.num_pages)
group_msgs.page_range = paginator.get_page_range(group_msgs.number)
# Force evaluate queryset to fix some database error for mysql.
group_msgs.object_list = list(group_msgs.object_list)
msg_attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
reply_to_list = [r.reply_to_id for r in msg_replies]
for msg in group_msgs.object_list:
msg.reply_cnt = reply_to_list.count(msg.id)
msg.replies = []
for r in msg_replies:
if msg.id == r.reply_to_id:
msg.replies.append(r)
msg.replies = msg.replies[-3:]
msg.attachments = []
for att in msg_attachments:
if att.group_message_id != msg.id:
continue
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == "/":
repo = get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
else:
path = path.rstrip("/") # cut out last '/' if possible
att.name = os.path.basename(path)
# Load to discuss page if attachment is a image and from recommend.
if att.attach_type == "file" and att.src == "recommend":
att.filetype, att.fileext = get_file_type_and_ext(att.name)
if att.filetype == IMAGE:
att.obj_id = get_file_id_by_path(att.repo_id, path)
if not att.obj_id:
att.err = _(u"File does not exist")
else:
att.token = seafile_api.get_fileserver_access_token(att.repo_id, att.obj_id, "view", username)
att.img_url = gen_file_get_url(att.token, att.name)
msg.attachments.append(att)
# get available modules(wiki, etc)
mods_available = get_available_mods_by_group(group.id)
mods_enabled = get_enabled_mods_by_group(group.id)
return render_to_response(
"group/group_discuss.html",
{
"group": group,
"is_staff": group.is_staff,
"group_msgs": group_msgs,
"form": form,
"mods_enabled": mods_enabled,
"mods_available": mods_available,
},
context_instance=RequestContext(request),
)
请发表评论