コード例 #1
0
def sync_async(request):        
    if request.method == "POST":
        if not request.POST.__contains__('n'):
            message = "Malformed request. Try again or contact a tech associate."
            data = {"success": False,
                    "message": message}
            json = j.dumps(data)
            return HttpResponse(json, mimetype='application/json')
        n = request.POST["n"]
        if not n.isdigit():
            message = "Malformed request. Try again or contact a tech associate."
            data = {"success": False,
                    "message": message}
            json = j.dumps(data)
            return HttpResponse(json, mimetype='application/json')
        try:
            smug_lib.sync_all(True)
            smugmug = smug_lib.login(False)
            remote_albums = len(smugmug.albums_get(NickName="thecrimson")["Albums"])
            local_albums = len(Event.objects.all())
            message = "Database successfully synced with SmugMug"
            data = {"success" : True,
                    "message" : message,
                    "n_remote": remote_albums,
                    "n_local" : local_albums}
            json = j.dumps(data)
            return HttpResponse(json, mimetype='application/json')
        except Exception, arg:
            message = arg.__class__.__name__ + ": " + str(arg)
            print message
            data = {"success": False,
                    "message": message}
            print data
            json = j.dumps(data)
            return HttpResponse(json, mimetype='application/json')
コード例 #2
0
def sync_setup(request):
    smugmug = smug_lib.login(False)
    remote_albums = len(smugmug.albums_get(NickName="thecrimson")["Albums"])
    local_albums = len(Event.objects.all())
    message_style = "warning" if remote_albums > local_albums else "success"
    context = {'n_remote'      : remote_albums,
               'n_local'       : local_albums, 
               'diff'          : remote_albums - local_albums,
               'message_class' : message_style}
    return render_to_response('admin/syncdb.html', context, context_instance=RequestContext(request))