Skip to content

Commit

Permalink
添加管理的filter
Browse files Browse the repository at this point in the history
  • Loading branch information
rayer4u committed Jun 3, 2015
1 parent 6e1a25f commit 10dce88
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ios的应用自动签名、发布工具,基于django app
setting里需要配置MEDIA_URL, MEDIA_ROOT
1、签名相关的证书和描述文件位于/media/profiles/按照以下目录规则,某个证书下的某个项目的描述文件
证书1/
cert.cfg
Expand Down
35 changes: 29 additions & 6 deletions admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from django.contrib import admin
from .models import UpFile
from models import UpFile
import os

class PathFilter(admin.SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = 'id'

# Parameter for the filter that will be used in the URL query.
parameter_name = 'path'

def lookups(self, request, model_admin):
qs = model_admin.get_queryset(request)

ret = [(b, b) for b in set((os.path.dirname(a) if os.path.dirname(a) != '' else a) for a in qs.values_list('path', flat=True))]
print(ret)
return ret

def queryset(self, request, queryset):
# Compare the requested value (either '80s' or '90s')
# to decide how to filter the queryset.
if self.value() is not None:
print(self.value())
return queryset.filter(path__startswith=self.value(),)

class UpFileAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields':['path', 'status', 'user']}),
('Upload date infomation', {'fields':['up_date'], 'classes':['collapse']}),
]
admin.site.register(UpFile)
list_display = ('path', 'label')
list_editable = ('label',)
list_filter = ('user', PathFilter)

admin.site.register(UpFile, UpFileAdmin)
1 change: 1 addition & 0 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def upload(request):
out, err = p.communicate()

if len(err) > 0:
print(err, file=sys.stderr)
o.status = 'signfail'
o.save()
shutil.rmtree(tmpdir)
Expand Down

0 comments on commit 10dce88

Please sign in to comment.